diff --git a/client/pages/audiobook/_id/chapters.vue b/client/pages/audiobook/_id/chapters.vue index cf254165b..d2a55141b 100644 --- a/client/pages/audiobook/_id/chapters.vue +++ b/client/pages/audiobook/_id/chapters.vue @@ -595,6 +595,12 @@ export default { this.hasChanges = hasChanges }, playChapter(chapter) { + // Pause any existing audiobook playback to prevent multiple streams + if (this.$store.state.streamLibraryItem) { + this.$eventBus.$emit('pause-item') + } + + console.log('$store.state.streamLibraryItem', this.$store.state) console.log('Play Chapter', chapter.id) if (this.selectedChapterId === chapter.id) { console.log('Chapter already playing', this.isLoadingChapter, this.isPlayingChapter) @@ -641,15 +647,8 @@ export default { }) audioEl.addEventListener('ended', () => { console.log('Audio ended') - const nextTrack = this.tracks.find((t) => t.index === this.currentTrackIndex + 1) - if (nextTrack) { - console.log('Playing next track', nextTrack.index) - this.currentTrackIndex = nextTrack.index - this.playTrackAtTime(nextTrack, 0) - } else { - console.log('No next track') - this.destroyAudioEl() - } + // stop at end of chapter + this.destroyAudioEl() }) this.audioEl = audioEl }, @@ -995,11 +994,13 @@ export default { this.initChapters() this.$eventBus.$on(`${this.libraryItem.id}_updated`, this.libraryItemUpdated) + this.$eventBus.$on('pause-chapter', this.destroyAudioEl) }, beforeDestroy() { this.destroyAudioEl() this.$eventBus.$off(`${this.libraryItem.id}_updated`, this.libraryItemUpdated) + this.$eventBus.$off('pause-chapter', this.destroyAudioEl) } } diff --git a/client/players/LocalAudioPlayer.js b/client/players/LocalAudioPlayer.js index 7fc17e7aa..ad53e1a76 100644 --- a/client/players/LocalAudioPlayer.js +++ b/client/players/LocalAudioPlayer.js @@ -231,6 +231,11 @@ export default class LocalAudioPlayer extends EventEmitter { } play() { + // Emit pause-chapter event to stop any other chapter playing + if (this.ctx.$eventBus) { + this.ctx.$eventBus.$emit('pause-chapter') + } + this.playWhenReady = true if (this.player) this.player.play() }