Update LocalAudioPlayer and chapters view for improved functionality

This commit is contained in:
lykos 2025-10-05 18:54:32 +13:00
parent 123351e08a
commit 98a01b8b10
2 changed files with 15 additions and 9 deletions

View File

@ -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')
// 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)
}
}
</script>

View File

@ -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()
}