From ec704bf501b39307d8907223644009b337771bf2 Mon Sep 17 00:00:00 2001 From: Lars Kiesow Date: Sat, 11 Feb 2023 22:57:06 +0100 Subject: [PATCH 1/2] Easy way to play current audiobook This patch implements a generic way of re-opening the player for the book you last listened to. This is especially handy when first opening the app and you can restart playback with a single click. The player is opened only if no other book is already open in the player. It will not overwrite or replace playbacks or player already in progress. The player is opened paused. No automatic playback since that could be really annoying. This closes #494 --- components/app/AudioPlayerContainer.vue | 3 ++- pages/bookshelf/index.vue | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/app/AudioPlayerContainer.vue b/components/app/AudioPlayerContainer.vue index 060a2878..2cd17531 100644 --- a/components/app/AudioPlayerContainer.vue +++ b/components/app/AudioPlayerContainer.vue @@ -188,6 +188,7 @@ export default { const libraryItemId = payload.libraryItemId const episodeId = payload.episodeId const startTime = payload.startTime + const startWhenReady = !payload.paused // When playing local library item and can also play this item from the server // then store the server library item id so it can be used if a cast is made @@ -223,7 +224,7 @@ export default { } console.log('Called playLibraryItem', libraryItemId) - const preparePayload = { libraryItemId, episodeId, playWhenReady: true, playbackRate } + const preparePayload = { libraryItemId, episodeId, playWhenReady: startWhenReady, playbackRate } if (startTime !== undefined && startTime !== null) preparePayload.startTime = startTime AbsAudioPlayer.prepareLibraryItem(preparePayload) .then((data) => { diff --git a/pages/bookshelf/index.vue b/pages/bookshelf/index.vue index 2eaffa05..8eb417e6 100644 --- a/pages/bookshelf/index.vue +++ b/pages/bookshelf/index.vue @@ -247,6 +247,15 @@ export default { return cat }) + // If we don't already have a player open + // Try opening the first book from continue-listening without playing it + if (!this.$store.state.playerLibraryItemId) { + const lastListening = categories.filter((cat) => cat.id === 'continue-listening')[0]?.entities?.[0]?.id + if (lastListening) { + this.$eventBus.$emit('play-item', { libraryItemId: lastListening, paused: true }) + } + } + // Only add the local shelf with the same media type const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType && !cat.localOnly) this.shelves.push(...localShelves) From 40bda3d48b1c2d25b96d576038576523aae4c708 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 12 Feb 2023 08:47:38 -0600 Subject: [PATCH 2/2] Auto play podcast episode & check for local copy --- pages/bookshelf/index.vue | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/pages/bookshelf/index.vue b/pages/bookshelf/index.vue index 8eb417e6..14770ec6 100644 --- a/pages/bookshelf/index.vue +++ b/pages/bookshelf/index.vue @@ -39,6 +39,7 @@ export default { shelves: [], loading: false, isFirstNetworkConnection: true, + isFirstAutoOpenPlayer: true, lastServerFetch: 0, lastServerFetchLibraryId: null, lastLocalFetch: 0, @@ -247,14 +248,7 @@ export default { return cat }) - // If we don't already have a player open - // Try opening the first book from continue-listening without playing it - if (!this.$store.state.playerLibraryItemId) { - const lastListening = categories.filter((cat) => cat.id === 'continue-listening')[0]?.entities?.[0]?.id - if (lastListening) { - this.$eventBus.$emit('play-item', { libraryItemId: lastListening, paused: true }) - } - } + this.openMediaPlayerWithMostRecentListening() // Only add the local shelf with the same media type const localShelves = localCategories.filter((cat) => cat.type === this.currentLibraryMediaType && !cat.localOnly) @@ -270,6 +264,40 @@ export default { this.loading = false }, + openMediaPlayerWithMostRecentListening() { + // If we don't already have a player open + // Try opening the first book from continue-listening without playing it + if (this.$store.state.playerLibraryItemId || !this.isFirstAutoOpenPlayer) return + this.isFirstAutoOpenPlayer = false // Only run this once, not on every library change + + const continueListeningShelf = this.shelves.find((cat) => cat.id === 'continue-listening') + const mostRecentEntity = continueListeningShelf?.entities?.[0] + if (mostRecentEntity) { + const playObject = { + libraryItemId: mostRecentEntity.id, + episodeId: mostRecentEntity.recentEpisode?.id || null, + paused: true + } + + // Check if there is a local copy + if (mostRecentEntity.localLibraryItem) { + if (mostRecentEntity.recentEpisode) { + // Check if the podcast episode has a local copy + const localEpisode = mostRecentEntity.localLibraryItem.media.episodes.find((ep) => ep.serverEpisodeId === mostRecentEntity.recentEpisode.id) + if (localEpisode) { + playObject.libraryItemId = mostRecentEntity.localLibraryItem.id + playObject.episodeId = localEpisode.id + playObject.serverLibraryItemId = mostRecentEntity.id + playObject.serverEpisodeId = mostRecentEntity.recentEpisode.id + } + } else { + playObject.libraryItemId = mostRecentEntity.localLibraryItem.id + playObject.serverLibraryItemId = mostRecentEntity.id + } + } + this.$eventBus.$emit('play-item', playObject) + } + }, libraryChanged() { if (this.currentLibraryId) { console.log(`[categories] libraryChanged so fetching categories`)