mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-10 11:21:36 +00:00
Add support for "Open Current Chapter" button
This commit is contained in:
parent
5308fd8b46
commit
79df705da7
30 changed files with 88 additions and 6 deletions
|
|
@ -36,6 +36,7 @@
|
|||
ref="audioPlayer"
|
||||
:chapters="chapters"
|
||||
:current-chapter="currentChapter"
|
||||
:libraryItem="streamLibraryItem"
|
||||
:paused="!isPlaying"
|
||||
:loading="playerLoading"
|
||||
:bookmarks="bookmarks"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@
|
|||
<ui-tooltip direction="top" :text="$strings.LabelVolume">
|
||||
<controls-volume-control ref="volumeControl" v-model="volume" @input="setVolume" class="mx-2 hidden sm:block" />
|
||||
</ui-tooltip>
|
||||
|
||||
<ui-tooltip v-if="hasEbookFile" direction="top" :text="$strings.ButtonOpenCurrentChapter">
|
||||
<button :aria-label="$strings.ButtonOpenCurrentChapter" class="text-gray-300 hover:text-white mx-1 lg:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="openEbook">
|
||||
<span class="material-symbols text-2xl">auto_stories</span>
|
||||
</button>
|
||||
</ui-tooltip>
|
||||
<ui-tooltip v-if="!hideSleepTimer" direction="top" :text="$strings.LabelSleepTimer">
|
||||
<button :aria-label="$strings.LabelSleepTimer" class="text-gray-300 hover:text-white mx-1 lg:mx-2" @mousedown.prevent @mouseup.prevent @click.stop="$emit('showSleepTimer')">
|
||||
<span v-if="!sleepTimerSet" class="material-symbols text-2xl">snooze</span>
|
||||
|
|
@ -77,6 +81,7 @@ export default {
|
|||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
libraryItem: Object,
|
||||
sleepTimerSet: Boolean,
|
||||
sleepTimerRemaining: Number,
|
||||
sleepTimerType: String,
|
||||
|
|
@ -173,6 +178,9 @@ export default {
|
|||
useChapterTrack() {
|
||||
const _useChapterTrack = this.$store.getters['user/getUserSetting']('useChapterTrack') || false
|
||||
return this.chapters.length ? _useChapterTrack : false
|
||||
},
|
||||
hasEbookFile() {
|
||||
return this.libraryItem.media && this.libraryItem.media.ebookFile
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -352,6 +360,9 @@ export default {
|
|||
else if (action === this.$hotkeys.AudioPlayer.INCREASE_PLAYBACK_RATE) this.increasePlaybackRate()
|
||||
else if (action === this.$hotkeys.AudioPlayer.DECREASE_PLAYBACK_RATE) this.decreasePlaybackRate()
|
||||
else if (action === this.$hotkeys.AudioPlayer.CLOSE) this.closePlayer()
|
||||
},
|
||||
openEbook() {
|
||||
this.$store.commit('showEReader', { libraryItem: this.libraryItem, keepProgress: true })
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ export default {
|
|||
})
|
||||
}
|
||||
},
|
||||
initEpub() {
|
||||
async initEpub() {
|
||||
/** @type {EpubReader} */
|
||||
const reader = this
|
||||
|
||||
|
|
@ -330,8 +330,26 @@ export default {
|
|||
flow: 'paginated'
|
||||
})
|
||||
|
||||
// load saved progress
|
||||
reader.rendition.display(this.savedEbookLocation || reader.book.locations.start)
|
||||
await reader.book.ready
|
||||
// load saved progress or initial chapter
|
||||
var initialLocation = this.savedEbookLocation || this.initialChapterHref || reader.book.locations.start
|
||||
try {
|
||||
const initialChapterTitle = this.getCurrentAudioChapter()
|
||||
if (initialChapterTitle) {
|
||||
const href = this.findChapterHref(initialChapterTitle)
|
||||
if (href) {
|
||||
try {
|
||||
initialLocation = 'text/' + href
|
||||
} catch (error) {
|
||||
console.error('Failed to navigate to chapter:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
|
||||
reader.rendition.display(initialLocation)
|
||||
|
||||
reader.rendition.on('rendered', () => {
|
||||
this.applyTheme()
|
||||
|
|
@ -439,13 +457,38 @@ export default {
|
|||
this.rendition.getContents().forEach((c) => {
|
||||
c.addStylesheetRules(this.themeRules)
|
||||
})
|
||||
},
|
||||
getCurrentAudioChapter() {
|
||||
try {
|
||||
var currentTime = this.$store.getters['user/getUserMediaProgress'](this.libraryItemId).currentTime
|
||||
var audioBookChapters = this.$store.state.streamLibraryItem.media.chapters
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
if (!audioBookChapters) return null
|
||||
const chapter = audioBookChapters.find((chapter) => chapter.start <= currentTime && currentTime < chapter.end)
|
||||
return chapter.title || audioBookChapters[audioBookChapters.length - 1].title
|
||||
},
|
||||
findChapterHref(title) {
|
||||
const findInToc = (items) => {
|
||||
for (let item of items) {
|
||||
if (item.label.trim() === title) return item.href
|
||||
if (item.subitems) {
|
||||
const result = findInToc(item.subitems)
|
||||
if (result) return result
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
return findInToc(this.rendition.book.navigation.toc)
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
async mounted() {
|
||||
this.windowWidth = window.innerWidth
|
||||
this.windowHeight = window.innerHeight
|
||||
window.addEventListener('resize', this.resize)
|
||||
this.initEpub()
|
||||
|
||||
await this.initEpub()
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('resize', this.resize)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue