diff --git a/client/pages/audiobook/_id/chapters.vue b/client/pages/audiobook/_id/chapters.vue
index cf254165b..4d6c0e41d 100644
--- a/client/pages/audiobook/_id/chapters.vue
+++ b/client/pages/audiobook/_id/chapters.vue
@@ -117,10 +117,10 @@
-
@@ -594,6 +594,14 @@ export default {
this.hasChanges = hasChanges
},
+ getAudioTrackForTime(time) {
+ if (typeof time !== 'number') {
+ return null
+ }
+ return this.tracks.find((at) => {
+ return time >= at.startOffset && time < at.startOffset + at.duration
+ })
+ },
playChapter(chapter) {
console.log('Play Chapter', chapter.id)
if (this.selectedChapterId === chapter.id) {
@@ -608,9 +616,12 @@ export default {
this.destroyAudioEl()
}
- const audioTrack = this.tracks.find((at) => {
- return chapter.start >= at.startOffset && chapter.start < at.startOffset + at.duration
- })
+ const audioTrack = this.getAudioTrackForTime(chapter.start)
+ if (!audioTrack) {
+ console.error('No audio track found for chapter', chapter)
+ return
+ }
+
this.selectedChapter = chapter
this.isLoadingChapter = true