diff --git a/components/AudioPlayerMini.vue b/components/AudioPlayerMini.vue index 55a49541..aaf505f4 100644 --- a/components/AudioPlayerMini.vue +++ b/components/AudioPlayerMini.vue @@ -198,11 +198,33 @@ export default { this.pause() } }, - set(audiobookStreamData) { + async set(audiobookStreamData, stream, fromAppDestroy) { this.isResetting = false this.initObject = { ...audiobookStreamData } + var init = true + if (!!stream) { + console.log(JSON.stringify(stream)) + var data = await MyNativeAudio.getStreamSyncData() + console.log('getStreamSyncData', JSON.stringify(data)) + console.log('lastUpdate', !!stream.lastUpdate ? stream.lastUpdate : 0) + //Same audiobook + if (data.id == stream.id && (data.isPlaying || (data.lastPauseTime >= (!!stream.lastUpdate ? stream.lastUpdate : 0)))) { + console.log('Same audiobook') + this.isPaused = !data.isPlaying + this.currentTime = Number((data.currentTime / 1000).toFixed(2)) + this.timeupdate() + if (data.isPlaying) { + console.log('playing - continue') + if (fromAppDestroy) this.startPlayInterval() + } + else console.log('paused and newer') + if (!fromAppDestroy) return + init = false + this.initObject.startTime = String(Math.floor(this.currentTime * 1000)) + } + } this.currentPlaybackRate = this.initObject.playbackSpeed - MyNativeAudio.initPlayer(this.initObject).then((res) => { + if (init) MyNativeAudio.initPlayer(this.initObject).then((res) => { if (res && res.success) { console.log('Success init audio player') } else { diff --git a/components/app/StreamContainer.vue b/components/app/StreamContainer.vue index 9413e78a..1883ea68 100644 --- a/components/app/StreamContainer.vue +++ b/components/app/StreamContainer.vue @@ -269,7 +269,7 @@ export default { isLocal: true } - this.$refs.audioPlayerMini.set(audiobookStreamData) + this.$refs.audioPlayerMini.set(audiobookStreamData, null, false) }, streamOpen(stream) { if (this.download) { @@ -286,8 +286,6 @@ export default { return } - this.stream = stream - // Update local remove current this.$localStore.setCurrent(null) @@ -298,6 +296,7 @@ export default { if (playOnLoad) this.$store.commit('setPlayOnLoad', false) var audiobookStreamData = { + id: stream.id, title: this.title, author: this.author, playWhenReady: !!playOnLoad, @@ -309,7 +308,9 @@ export default { playlistUrl: this.$server.url + playlistUrl, token: this.$store.getters['user/getToken'] } - this.$refs.audioPlayerMini.set(audiobookStreamData) + this.$refs.audioPlayerMini.set(audiobookStreamData, stream, !this.stream) + + this.stream = stream }, audioPlayerMounted() { console.log('Audio Player Mounted', this.$server.stream)