mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-11-24 20:05:41 +01:00
Update LocalAudioPlayer and chapters view for improved functionality
This commit is contained in:
parent
123351e08a
commit
98a01b8b10
@ -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)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user