Skip to content

Commit

Permalink
Update collection/playlist play button to show pause when playing #1394
Browse files Browse the repository at this point in the history
…, update collections to play local item if available
  • Loading branch information
advplyr committed Jan 26, 2025
1 parent c79ecbb commit 0520cbd
Show file tree
Hide file tree
Showing 33 changed files with 84 additions and 50 deletions.
25 changes: 22 additions & 3 deletions components/tables/collection/BookTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="book-table-content h-full px-2 flex items-center">
<div class="max-w-full">
<p class="truncate block text-sm">{{ bookTitle }}</p>
<p class="truncate block text-sm">{{ bookTitle }} <span v-if="localLibraryItem" class="material-icons text-success text-base align-text-bottom">download_done</span></p>
<p class="truncate block text-fg-muted text-xs">{{ bookAuthor }}</p>
<p v-if="media.duration" class="text-xxs text-fg-muted">{{ bookDuration }}</p>
</div>
Expand Down Expand Up @@ -39,6 +39,9 @@ export default {
libraryItemId() {
return this.book.id
},
localLibraryItem() {
return this.book.localLibraryItem
},
media() {
return this.book.media || {}
},
Expand Down Expand Up @@ -73,18 +76,34 @@ export default {
showPlayBtn() {
return !this.isMissing && !this.isInvalid && this.tracks.length
},
isStreaming() {
playerIsStartingPlayback() {
// Play has been pressed and waiting for native play response
return this.$store.state.playerIsStartingPlayback
},
isOpenInPlayer() {
if (this.localLibraryItem && this.$store.getters['getIsMediaStreaming'](this.localLibraryItem.id)) return true
return this.$store.getters['getIsMediaStreaming'](this.libraryItemId)
},
streamIsPlaying() {
return this.$store.state.playerIsPlaying && this.isStreaming
return this.$store.state.playerIsPlaying && this.isOpenInPlayer
}
},
methods: {
async playClick() {
if (this.playerIsStartingPlayback) return
await this.$hapticsImpact()
if (this.streamIsPlaying) {
this.$eventBus.$emit('pause-item')
return
}
this.$store.commit('setPlayerIsStartingPlayback', this.libraryItemId)
if (this.localLibraryItem) {
this.$eventBus.$emit('play-item', {
libraryItemId: this.localLibraryItem.id,
serverLibraryItemId: this.libraryItemId
})
} else {
this.$eventBus.$emit('play-item', {
libraryItemId: this.libraryItemId
Expand Down
4 changes: 2 additions & 2 deletions components/tables/playlist/ItemTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ export default {
showPlayBtn() {
return !this.isMissing && !this.isInvalid && (this.tracks.length || this.episode)
},
isStreaming() {
isOpenInPlayer() {
if (this.localLibraryItem && this.localEpisode && this.$store.getters['getIsMediaStreaming'](this.localLibraryItem.id, this.localEpisode.id)) return true
return this.$store.getters['getIsMediaStreaming'](this.libraryItem.id, this.episodeId)
},
streamIsPlaying() {
return this.$store.state.playerIsPlaying && this.isStreaming
return this.$store.state.playerIsPlaying && this.isOpenInPlayer
},
playerIsStartingPlayback() {
// Play has been pressed and waiting for native play response
Expand Down
53 changes: 42 additions & 11 deletions pages/collection/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
{{ collectionName }}
</h1>
<div class="flex-grow" />
<ui-btn v-if="showPlayButton" :disabled="streaming" color="success" :padding-x="4" small :loading="playerIsStartingForThisMedia" class="flex items-center justify-center h-9 mr-2 w-24" @click="clickPlay">
<span v-show="!streaming" class="material-icons -ml-2 pr-1 text-white">play_arrow</span>
{{ streaming ? $strings.ButtonPlaying : $strings.ButtonPlay }}
<ui-btn v-if="showPlayButton" color="success" :padding-x="4" :loading="playerIsStartingForThisMedia" small class="flex items-center justify-center mx-1 w-24" @click="playClick">
<span class="material-icons">{{ playerIsPlaying ? 'pause' : 'play_arrow' }}</span>
<span class="px-1 text-sm">{{ playerIsPlaying ? $strings.ButtonPause : $strings.ButtonPlay }}</span>
</ui-btn>
</div>

Expand Down Expand Up @@ -47,6 +47,18 @@ export default {
return redirect('/bookshelf')
}
// Lookup matching local items and attach to collection items
if (collection.books.length) {
const localLibraryItems = (await app.$db.getLocalLibraryItems('book')) || []
if (localLibraryItems.length) {
collection.books.forEach((collectionItem) => {
const matchingLocalLibraryItem = localLibraryItems.find((lli) => lli.libraryItemId === collectionItem.id)
if (!matchingLocalLibraryItem) return
collectionItem.localLibraryItem = matchingLocalLibraryItem
})
}
}
return {
collection
}
Expand All @@ -70,13 +82,19 @@ export default {
description() {
return this.collection.description || ''
},
playableBooks() {
playableItems() {
return this.bookItems.filter((book) => {
return !book.isMissing && !book.isInvalid && book.media.tracks.length
})
},
streaming() {
return !!this.playableBooks.find((b) => this.$store.getters['getIsMediaStreaming'](b.id))
playerIsPlaying() {
return this.$store.state.playerIsPlaying && this.isOpenInPlayer
},
isOpenInPlayer() {
return !!this.playableItems.find((i) => {
if (i.localLibraryItem && this.$store.getters['getIsMediaStreaming'](i.localLibraryItem.id)) return true
return this.$store.getters['getIsMediaStreaming'](i.id)
})
},
playerIsStartingPlayback() {
// Play has been pressed and waiting for native play response
Expand All @@ -88,21 +106,34 @@ export default {
return mediaId === this.mediaIdStartingPlayback
},
showPlayButton() {
return this.playableBooks.length
return this.playableItems.length
}
},
methods: {
clickPlay() {
async playClick() {
if (this.playerIsStartingPlayback) return
await this.$hapticsImpact()
var nextBookNotRead = this.playableBooks.find((pb) => {
var prog = this.$store.getters['user/getUserMediaProgress'](pb.id)
if (this.playerIsPlaying) {
this.$eventBus.$emit('pause-item')
} else {
this.playNextItem()
}
},
playNextItem() {
const nextBookNotRead = this.playableItems.find((pb) => {
const prog = this.$store.getters['user/getUserMediaProgress'](pb.id)
return !prog?.isFinished
})
if (nextBookNotRead) {
this.mediaIdStartingPlayback = nextBookNotRead.id
this.$store.commit('setPlayerIsStartingPlayback', nextBookNotRead.id)
this.$eventBus.$emit('play-item', { libraryItemId: nextBookNotRead.id })
if (nextBookNotRead.localLibraryItem) {
this.$eventBus.$emit('play-item', { libraryItemId: nextBookNotRead.localLibraryItem.id, serverLibraryItemId: nextBookNotRead.id })
} else {
this.$eventBus.$emit('play-item', { libraryItemId: nextBookNotRead.id })
}
}
}
},
Expand Down
23 changes: 18 additions & 5 deletions pages/playlist/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
{{ playlistName }}
</h1>
<div class="flex-grow" />
<ui-btn v-if="showPlayButton" :disabled="streaming" color="success" :padding-x="4" :loading="playerIsStartingForThisMedia" small class="flex items-center justify-center text-center h-9 mr-2 w-24" @click="clickPlay">
<span v-show="!streaming" class="material-icons -ml-2 pr-1 text-white">play_arrow</span>
{{ streaming ? $strings.ButtonPlaying : $strings.ButtonPlay }}
<ui-btn v-if="showPlayButton" color="success" :padding-x="4" :loading="playerIsStartingForThisMedia" small class="flex items-center justify-center mx-1 w-24" @click="playClick">
<span class="material-icons">{{ playerIsPlaying ? 'pause' : 'play_arrow' }}</span>
<span class="px-1 text-sm">{{ playerIsPlaying ? $strings.ButtonPause : $strings.ButtonPlay }}</span>
</ui-btn>
</div>

Expand Down Expand Up @@ -101,7 +101,10 @@ export default {
return libraryItem.media.tracks.length
})
},
streaming() {
playerIsPlaying() {
return this.$store.state.playerIsPlaying && this.isOpenInPlayer
},
isOpenInPlayer() {
return !!this.playableItems.find((i) => {
if (i.localLibraryItem && this.$store.getters['getIsMediaStreaming'](i.localLibraryItem.id, i.localEpisode?.id)) return true
return this.$store.getters['getIsMediaStreaming'](i.libraryItemId, i.episodeId)
Expand All @@ -126,7 +129,17 @@ export default {
this.selectedEpisode = playlistItem.episode
this.showMoreMenu = true
},
clickPlay() {
async playClick() {
if (this.playerIsStartingPlayback) return
await this.$hapticsImpact()
if (this.playerIsPlaying) {
this.$eventBus.$emit('pause-item')
} else {
this.playNextItem()
}
},
playNextItem() {
const nextItem = this.playableItems.find((i) => {
const prog = this.$store.getters['user/getUserMediaProgress'](i.libraryItemId, i.episodeId)
return !prog?.isFinished
Expand Down
1 change: 0 additions & 1 deletion strings/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "تَوَقَّف",
"ButtonPlay": "تشغيل",
"ButtonPlayEpisode": "شغل الحلقة",
"ButtonPlaying": "مشغل الآن",
"ButtonPlaylists": "قوائم التشغيل",
"ButtonRead": "اقرأ",
"ButtonReadLess": "قلص",
Expand Down
1 change: 0 additions & 1 deletion strings/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"ButtonNextEpisode": "Наступны эпізод",
"ButtonOpenFeed": "Адкрыць стужку",
"ButtonPause": "Паўза",
"ButtonPlaying": "Прайграваецца",
"ButtonPlaylists": "Плэйлісты",
"ButtonRemoveFromServer": "Выдаліць з сервера",
"ButtonSave": "Захаваць",
Expand Down
1 change: 0 additions & 1 deletion strings/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "বিরতি",
"ButtonPlay": "বাজান",
"ButtonPlayEpisode": "পর্বটি চালান",
"ButtonPlaying": "বাজছে",
"ButtonPlaylists": "প্লেলিস্ট",
"ButtonRead": "পড়ুন",
"ButtonReadLess": "কম পড়ুন",
Expand Down
1 change: 0 additions & 1 deletion strings/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "Pausa",
"ButtonPlay": "Reproduir",
"ButtonPlayEpisode": "Reproduir episodi",
"ButtonPlaying": "Reproduint",
"ButtonPlaylists": "Llistes de reproducció",
"ButtonRead": "Llegir",
"ButtonReadLess": "Llig menys",
Expand Down
1 change: 0 additions & 1 deletion strings/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pozastavit",
"ButtonPlay": "Přehrát",
"ButtonPlayEpisode": "Přehrát epizodu",
"ButtonPlaying": "Hraje",
"ButtonPlaylists": "Seznamy skladeb",
"ButtonRead": "Číst",
"ButtonReadLess": "Číst méně",
Expand Down
1 change: 0 additions & 1 deletion strings/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pause",
"ButtonPlay": "Afspil",
"ButtonPlayEpisode": "Afspil Afsnit",
"ButtonPlaying": "Afspiller",
"ButtonPlaylists": "Afspilningslister",
"ButtonRead": "Læs",
"ButtonReadLess": "Se mindre",
Expand Down
1 change: 0 additions & 1 deletion strings/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pausieren",
"ButtonPlay": "Abspielen",
"ButtonPlayEpisode": "Episode abspielen",
"ButtonPlaying": "Spielt",
"ButtonPlaylists": "Wiedergabelisten",
"ButtonRead": "Lesen",
"ButtonReadLess": "weniger Anzeigen",
Expand Down
1 change: 0 additions & 1 deletion strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pause",
"ButtonPlay": "Play",
"ButtonPlayEpisode": "Play Episode",
"ButtonPlaying": "Playing",
"ButtonPlaylists": "Playlists",
"ButtonRead": "Read",
"ButtonReadLess": "Read less",
Expand Down
1 change: 0 additions & 1 deletion strings/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pausar",
"ButtonPlay": "Reproducir",
"ButtonPlayEpisode": "Reproducir episodio",
"ButtonPlaying": "Reproduciendo",
"ButtonPlaylists": "Listas de reproducción",
"ButtonRead": "Leer",
"ButtonReadLess": "Leer menos",
Expand Down
1 change: 0 additions & 1 deletion strings/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "Pysäytä",
"ButtonPlay": "Toista",
"ButtonPlayEpisode": "Toista jakso",
"ButtonPlaying": "Toistetaan",
"ButtonPlaylists": "Soittolistat",
"ButtonRead": "Lue",
"ButtonReadLess": "Lue vähemmän",
Expand Down
1 change: 0 additions & 1 deletion strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pause",
"ButtonPlay": "Lire",
"ButtonPlayEpisode": "Lire l’épisode",
"ButtonPlaying": "En lecture",
"ButtonPlaylists": "Listes de lecture",
"ButtonRead": "Lire",
"ButtonReadLess": "Lire moins",
Expand Down
1 change: 0 additions & 1 deletion strings/gu.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ButtonLibrary": "પુસ્તકાલય",
"ButtonOpenFeed": "ફીડ ખોલો",
"ButtonPlay": "ચલાવો",
"ButtonPlaying": "ચલાવી રહ્યું છે",
"ButtonPlaylists": "પ્લેલિસ્ટ",
"ButtonRead": "વાંચો",
"ButtonRemove": "કાઢી નાખો",
Expand Down
1 change: 0 additions & 1 deletion strings/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"ButtonLibrary": "ספרייה",
"ButtonPlay": "נגן",
"ButtonPlayEpisode": "נגן פרק",
"ButtonPlaying": "מנגן",
"ButtonPlaylists": "רשימת השמעה",
"HeaderOpenRSSFeed": "פתח ערוץ RSS",
"LabelAddedDate": "נוסף ב-{0}"
Expand Down
1 change: 0 additions & 1 deletion strings/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ButtonLibrary": "पुस्तकालय",
"ButtonOpenFeed": "फ़ीड खोलें",
"ButtonPlay": "चलाएँ",
"ButtonPlaying": "चल रही है",
"ButtonPlaylists": "प्लेलिस्ट्स",
"ButtonRead": "पढ़ लिया",
"ButtonRemove": "हटाएं",
Expand Down
1 change: 0 additions & 1 deletion strings/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pauziraj",
"ButtonPlay": "Reproduciraj",
"ButtonPlayEpisode": "Reproduciraj nastavak",
"ButtonPlaying": "Izvodi se",
"ButtonPlaylists": "Popisi za izvođenje",
"ButtonRead": "Pročitaj",
"ButtonReadLess": "Pročitaj manje",
Expand Down
1 change: 0 additions & 1 deletion strings/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Szünet",
"ButtonPlay": "Lejátszás",
"ButtonPlayEpisode": "Epizód lejátszása",
"ButtonPlaying": "Lejátszás folyamatban",
"ButtonPlaylists": "Lejátszási listák",
"ButtonRead": "Olvasás",
"ButtonReadLess": "Mutass kevesebbet",
Expand Down
1 change: 0 additions & 1 deletion strings/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Pausa",
"ButtonPlay": "Riproduci",
"ButtonPlayEpisode": "Riproduci episodio",
"ButtonPlaying": "In riproduzione",
"ButtonPlaylists": "Playlist",
"ButtonRead": "Leggi",
"ButtonReadLess": "Riduci",
Expand Down
1 change: 0 additions & 1 deletion strings/lt.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"ButtonPause": "Pauzė",
"ButtonPlay": "Groti",
"ButtonPlayEpisode": "Groti episodą",
"ButtonPlaying": "Grojama",
"ButtonPlaylists": "Grojaraščiai",
"ButtonRead": "Skaityti",
"ButtonReadLess": "Skaityti mažiau",
Expand Down
1 change: 0 additions & 1 deletion strings/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "Pauze",
"ButtonPlay": "Afspelen",
"ButtonPlayEpisode": "Aflevering afspelen",
"ButtonPlaying": "Speelt",
"ButtonPlaylists": "Afspeellijsten",
"ButtonRead": "Lees",
"ButtonReadLess": "Minder lezen",
Expand Down
1 change: 0 additions & 1 deletion strings/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"ButtonPause": "Pause",
"ButtonPlay": "Spill av",
"ButtonPlayEpisode": "Spill episode",
"ButtonPlaying": "Spiller av",
"ButtonPlaylists": "Spillelister",
"ButtonRead": "Les",
"ButtonRemove": "Fjern",
Expand Down
1 change: 0 additions & 1 deletion strings/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "Wstrzymaj",
"ButtonPlay": "Odtwarzaj",
"ButtonPlayEpisode": "Odtwórz odcinek",
"ButtonPlaying": "Odtwarzane",
"ButtonPlaylists": "Listy odtwarzania",
"ButtonRead": "Czytaj",
"ButtonReadLess": "Czytaj mniej",
Expand Down
1 change: 0 additions & 1 deletion strings/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"ButtonPause": "Pausar",
"ButtonPlay": "Reproduzir",
"ButtonPlayEpisode": "Reproduzir Episódio",
"ButtonPlaying": "Reproduzindo",
"ButtonPlaylists": "Lista de Reprodução",
"ButtonRead": "Ler",
"ButtonReadLess": "Ler menos",
Expand Down
1 change: 0 additions & 1 deletion strings/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ButtonPause": "Пауза",
"ButtonPlay": "Слушать",
"ButtonPlayEpisode": "Воспроизвести эпизод",
"ButtonPlaying": "Проигрывается",
"ButtonPlaylists": "Плейлисты",
"ButtonRead": "Читать",
"ButtonReadLess": "Читать меньше",
Expand Down
Loading

0 comments on commit 0520cbd

Please sign in to comment.