2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2022-03-13 02:59:35 +01:00
|
|
|
<div v-if="streamLibraryItem" id="streamContainer" class="w-full fixed bottom-0 left-0 right-0 h-48 sm:h-44 md:h-40 z-40 bg-primary px-4 pb-1 md:pb-4 pt-2">
|
2022-05-31 02:26:53 +02:00
|
|
|
<div id="videoDock" />
|
2022-06-19 17:04:15 +02:00
|
|
|
<nuxt-link v-if="!playerHandler.isVideo" :to="`/item/${streamLibraryItem.id}`" class="absolute left-1 sm:left-4 cursor-pointer" :style="{ top: bookCoverPosTop + 'px' }">
|
2022-08-13 20:56:37 +02:00
|
|
|
<covers-book-cover :library-item="streamLibraryItem" :width="bookCoverWidth" :book-cover-aspect-ratio="coverAspectRatio" />
|
2021-09-21 23:42:01 +02:00
|
|
|
</nuxt-link>
|
2022-06-19 17:04:15 +02:00
|
|
|
<div class="flex items-start mb-6 md:mb-0" :class="playerHandler.isVideo ? 'ml-4 pl-96' : 'pl-20 sm:pl-24'">
|
2021-08-18 00:01:11 +02:00
|
|
|
<div>
|
2022-06-19 17:04:15 +02:00
|
|
|
<nuxt-link :to="`/item/${streamLibraryItem.id}`" class="hover:underline cursor-pointer text-sm sm:text-lg">
|
2022-02-13 00:19:14 +01:00
|
|
|
{{ title }}
|
2021-09-21 23:42:01 +02:00
|
|
|
</nuxt-link>
|
2022-05-31 02:26:53 +02:00
|
|
|
<div v-if="!playerHandler.isVideo" class="text-gray-400 flex items-center">
|
2021-10-27 01:12:19 +02:00
|
|
|
<span class="material-icons text-sm">person</span>
|
2022-06-19 17:04:15 +02:00
|
|
|
<p v-if="podcastAuthor" class="pl-1 sm:pl-1.5 text-xs sm:text-base">{{ podcastAuthor }}</p>
|
|
|
|
<p v-else-if="authors.length" class="pl-1 sm:pl-1.5 text-xs sm:text-base">
|
2022-05-09 01:43:24 +02:00
|
|
|
<nuxt-link v-for="(author, index) in authors" :key="index" :to="`/author/${author.id}`" class="hover:underline">{{ author.name }}<span v-if="index < authors.length - 1">, </span></nuxt-link>
|
2021-10-31 22:40:27 +01:00
|
|
|
</p>
|
2022-11-09 00:10:08 +01:00
|
|
|
<p v-else class="text-xs sm:text-base cursor-pointer pl-1 sm:pl-1.5">{{ $strings.LabelUnknown }}</p>
|
2021-10-27 01:12:19 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="text-gray-400 flex items-center">
|
|
|
|
<span class="material-icons text-xs">schedule</span>
|
2022-06-19 17:04:15 +02:00
|
|
|
<p class="font-mono text-xs sm:text-sm pl-1 sm:pl-1.5 pb-px">{{ totalDurationPretty }}</p>
|
2021-10-27 01:12:19 +02:00
|
|
|
</div>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow" />
|
2022-06-19 17:04:15 +02:00
|
|
|
<span class="material-icons sm:px-2 py-1 md:p-4 cursor-pointer text-xl sm:text-2xl" @click="closePlayer">close</span>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
2022-06-01 03:13:46 +02:00
|
|
|
<player-ui
|
2022-03-05 19:30:46 +01:00
|
|
|
ref="audioPlayer"
|
|
|
|
:chapters="chapters"
|
|
|
|
:paused="!isPlaying"
|
|
|
|
:loading="playerLoading"
|
|
|
|
:bookmarks="bookmarks"
|
|
|
|
:sleep-timer-set="sleepTimerSet"
|
|
|
|
:sleep-timer-remaining="sleepTimerRemaining"
|
2022-04-12 02:42:09 +02:00
|
|
|
:is-podcast="isPodcast"
|
2022-03-05 19:30:46 +01:00
|
|
|
@playPause="playPause"
|
|
|
|
@jumpForward="jumpForward"
|
|
|
|
@jumpBackward="jumpBackward"
|
|
|
|
@setVolume="setVolume"
|
|
|
|
@setPlaybackRate="setPlaybackRate"
|
|
|
|
@seek="seek"
|
|
|
|
@close="closePlayer"
|
|
|
|
@showBookmarks="showBookmarks"
|
|
|
|
@showSleepTimer="showSleepTimerModal = true"
|
2022-08-28 20:12:38 +02:00
|
|
|
@showPlayerQueueItems="showPlayerQueueItemsModal = true"
|
2022-03-05 19:30:46 +01:00
|
|
|
/>
|
2021-10-25 01:25:44 +02:00
|
|
|
|
2022-03-18 02:28:04 +01:00
|
|
|
<modals-bookmarks-modal v-model="showBookmarksModal" :bookmarks="bookmarks" :current-time="bookmarkCurrentTime" :library-item-id="libraryItemId" @select="selectBookmark" />
|
2022-03-05 19:30:46 +01:00
|
|
|
|
|
|
|
<modals-sleep-timer-modal v-model="showSleepTimerModal" :timer-set="sleepTimerSet" :timer-time="sleepTimerTime" :remaining="sleepTimerRemaining" @set="setSleepTimer" @cancel="cancelSleepTimer" @increment="incrementSleepTimer" @decrement="decrementSleepTimer" />
|
2022-08-28 20:12:38 +02:00
|
|
|
|
|
|
|
<modals-player-queue-items-modal v-model="showPlayerQueueItemsModal" :library-item-id="libraryItemId" />
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-02-23 00:33:55 +01:00
|
|
|
import PlayerHandler from '@/players/PlayerHandler'
|
|
|
|
|
2021-08-18 00:01:11 +02:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2022-02-23 00:33:55 +01:00
|
|
|
playerHandler: new PlayerHandler(this),
|
2021-10-25 01:25:44 +02:00
|
|
|
totalDuration: 0,
|
|
|
|
showBookmarksModal: false,
|
|
|
|
bookmarkCurrentTime: 0,
|
2022-02-23 00:33:55 +01:00
|
|
|
playerLoading: false,
|
|
|
|
isPlaying: false,
|
2022-03-05 19:30:46 +01:00
|
|
|
currentTime: 0,
|
|
|
|
showSleepTimerModal: false,
|
2022-08-28 20:12:38 +02:00
|
|
|
showPlayerQueueItemsModal: false,
|
2022-03-05 19:30:46 +01:00
|
|
|
sleepTimerSet: false,
|
|
|
|
sleepTimerTime: 0,
|
|
|
|
sleepTimerRemaining: 0,
|
2022-04-02 17:26:42 +02:00
|
|
|
sleepTimer: null,
|
2022-04-23 23:51:13 +02:00
|
|
|
displayTitle: null,
|
2022-06-04 02:11:13 +02:00
|
|
|
initialPlaybackRate: 1,
|
|
|
|
syncFailedToast: null
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-12-03 02:02:38 +01:00
|
|
|
coverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
2021-11-04 23:35:59 +01:00
|
|
|
bookCoverWidth() {
|
|
|
|
return 88
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverPosTop() {
|
2022-08-13 20:56:37 +02:00
|
|
|
if (this.coverAspectRatio == 1) return -10
|
2021-12-03 02:02:38 +01:00
|
|
|
return -64
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
cover() {
|
2022-03-13 02:59:35 +01:00
|
|
|
if (this.media.coverPath) return this.media.coverPath
|
2021-08-18 00:01:11 +02:00
|
|
|
return 'Logo.png'
|
|
|
|
},
|
|
|
|
user() {
|
2021-08-24 01:31:04 +02:00
|
|
|
return this.$store.state.user.user
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-03-26 17:59:34 +01:00
|
|
|
userMediaProgress() {
|
2022-03-13 02:59:35 +01:00
|
|
|
if (!this.libraryItemId) return
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId)
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2022-03-18 01:10:47 +01:00
|
|
|
userItemCurrentTime() {
|
2022-03-26 17:59:34 +01:00
|
|
|
return this.userMediaProgress ? this.userMediaProgress.currentTime || 0 : 0
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
2021-10-25 01:25:44 +02:00
|
|
|
bookmarks() {
|
2022-03-18 02:28:04 +01:00
|
|
|
if (!this.libraryItemId) return []
|
|
|
|
return this.$store.getters['user/getUserBookmarksForItem'](this.libraryItemId)
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2022-03-13 02:59:35 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-03-13 02:59:35 +01:00
|
|
|
libraryItemId() {
|
|
|
|
return this.streamLibraryItem ? this.streamLibraryItem.id : null
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2022-03-13 02:59:35 +01:00
|
|
|
media() {
|
|
|
|
return this.streamLibraryItem ? this.streamLibraryItem.media || {} : {}
|
|
|
|
},
|
2022-03-27 00:30:58 +01:00
|
|
|
isPodcast() {
|
|
|
|
return this.streamLibraryItem ? this.streamLibraryItem.mediaType === 'podcast' : false
|
|
|
|
},
|
2022-03-13 02:59:35 +01:00
|
|
|
mediaMetadata() {
|
|
|
|
return this.media.metadata || {}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
chapters() {
|
2022-03-13 02:59:35 +01:00
|
|
|
return this.media.chapters || []
|
2021-09-08 16:15:54 +02:00
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
title() {
|
2022-04-02 17:26:42 +02:00
|
|
|
if (this.playerHandler.displayTitle) return this.playerHandler.displayTitle
|
2022-03-13 02:59:35 +01:00
|
|
|
return this.mediaMetadata.title || 'No Title'
|
2021-10-31 22:40:27 +01:00
|
|
|
},
|
2022-03-13 02:59:35 +01:00
|
|
|
authors() {
|
|
|
|
return this.mediaMetadata.authors || []
|
2021-10-31 22:40:27 +01:00
|
|
|
},
|
2021-10-06 04:10:49 +02:00
|
|
|
libraryId() {
|
2022-03-13 02:59:35 +01:00
|
|
|
return this.streamLibraryItem ? this.streamLibraryItem.libraryId : null
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
|
|
|
totalDurationPretty() {
|
|
|
|
return this.$secondsToTimestamp(this.totalDuration)
|
2022-03-27 00:30:58 +01:00
|
|
|
},
|
|
|
|
podcastAuthor() {
|
|
|
|
if (!this.isPodcast) return null
|
|
|
|
return this.mediaMetadata.author || 'Unknown'
|
2022-08-28 20:12:38 +02:00
|
|
|
},
|
|
|
|
playerQueueItems() {
|
|
|
|
return this.$store.state.playerQueueItems || []
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-28 21:21:28 +02:00
|
|
|
mediaFinished(libraryItemId, episodeId) {
|
|
|
|
// Play next item in queue
|
|
|
|
if (!this.playerQueueItems.length || !this.$store.state.playerQueueAutoPlay) {
|
|
|
|
// TODO: Set media finished flag so play button will play next queue item
|
|
|
|
return
|
|
|
|
}
|
2022-08-28 20:12:38 +02:00
|
|
|
var currentQueueIndex = this.playerQueueItems.findIndex((i) => {
|
|
|
|
if (episodeId) return i.libraryItemId === libraryItemId && i.episodeId === episodeId
|
|
|
|
return i.libraryItemId === libraryItemId
|
|
|
|
})
|
|
|
|
if (currentQueueIndex < 0) {
|
|
|
|
console.error('Media finished not found in queue', this.playerQueueItems)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (currentQueueIndex === this.playerQueueItems.length - 1) {
|
|
|
|
console.log('Finished last item in queue')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const nextItemInQueue = this.playerQueueItems[currentQueueIndex + 1]
|
|
|
|
if (nextItemInQueue) {
|
|
|
|
this.playLibraryItem({
|
|
|
|
libraryItemId: nextItemInQueue.libraryItemId,
|
|
|
|
episodeId: nextItemInQueue.episodeId || null,
|
|
|
|
queueItems: this.playerQueueItems
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
setPlaying(isPlaying) {
|
|
|
|
this.isPlaying = isPlaying
|
|
|
|
this.$store.commit('setIsPlaying', isPlaying)
|
2022-05-15 22:48:41 +02:00
|
|
|
this.updateMediaSessionPlaybackState()
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
2022-03-05 19:30:46 +01:00
|
|
|
setSleepTimer(seconds) {
|
|
|
|
this.sleepTimerSet = true
|
|
|
|
this.sleepTimerTime = seconds
|
|
|
|
this.sleepTimerRemaining = seconds
|
|
|
|
this.runSleepTimer()
|
|
|
|
this.showSleepTimerModal = false
|
|
|
|
},
|
|
|
|
runSleepTimer() {
|
|
|
|
var lastTick = Date.now()
|
|
|
|
clearInterval(this.sleepTimer)
|
|
|
|
this.sleepTimer = setInterval(() => {
|
|
|
|
var elapsed = Date.now() - lastTick
|
|
|
|
lastTick = Date.now()
|
|
|
|
this.sleepTimerRemaining -= elapsed / 1000
|
|
|
|
|
|
|
|
if (this.sleepTimerRemaining <= 0) {
|
|
|
|
this.clearSleepTimer()
|
|
|
|
this.playerHandler.pause()
|
|
|
|
this.$toast.info('Sleep Timer Done.. zZzzZz')
|
|
|
|
}
|
|
|
|
}, 1000)
|
|
|
|
},
|
|
|
|
cancelSleepTimer() {
|
|
|
|
this.showSleepTimerModal = false
|
|
|
|
this.clearSleepTimer()
|
|
|
|
},
|
|
|
|
clearSleepTimer() {
|
|
|
|
clearInterval(this.sleepTimer)
|
|
|
|
this.sleepTimerRemaining = 0
|
|
|
|
this.sleepTimer = null
|
|
|
|
this.sleepTimerSet = false
|
|
|
|
},
|
|
|
|
incrementSleepTimer(amount) {
|
|
|
|
if (!this.sleepTimerSet) return
|
|
|
|
this.sleepTimerRemaining += amount
|
|
|
|
},
|
|
|
|
decrementSleepTimer(amount) {
|
|
|
|
if (this.sleepTimerRemaining < amount) {
|
|
|
|
this.sleepTimerRemaining = 3
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.sleepTimerRemaining = Math.max(0, this.sleepTimerRemaining - amount)
|
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
playPause() {
|
|
|
|
this.playerHandler.playPause()
|
2021-11-13 02:43:16 +01:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
jumpForward() {
|
|
|
|
this.playerHandler.jumpForward()
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
jumpBackward() {
|
|
|
|
this.playerHandler.jumpBackward()
|
2021-10-25 01:25:44 +02:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setVolume(volume) {
|
|
|
|
this.playerHandler.setVolume(volume)
|
2021-09-21 23:42:01 +02:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setPlaybackRate(playbackRate) {
|
2022-04-23 23:51:13 +02:00
|
|
|
this.initialPlaybackRate = playbackRate
|
2022-02-23 00:33:55 +01:00
|
|
|
this.playerHandler.setPlaybackRate(playbackRate)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
seek(time) {
|
|
|
|
this.playerHandler.seek(time)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setCurrentTime(time) {
|
|
|
|
this.currentTime = time
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
2022-02-23 00:33:55 +01:00
|
|
|
this.$refs.audioPlayer.setCurrentTime(time)
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setDuration(duration) {
|
|
|
|
this.totalDuration = duration
|
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setDuration(duration)
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
|
|
|
setBufferTime(buffertime) {
|
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setBufferTime(buffertime)
|
2021-08-19 01:31:19 +02:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-03-05 19:30:46 +01:00
|
|
|
showBookmarks() {
|
|
|
|
this.bookmarkCurrentTime = this.currentTime
|
2022-02-23 00:33:55 +01:00
|
|
|
this.showBookmarksModal = true
|
|
|
|
},
|
|
|
|
selectBookmark(bookmark) {
|
|
|
|
this.seek(bookmark.time)
|
|
|
|
this.showBookmarksModal = false
|
|
|
|
},
|
|
|
|
closePlayer() {
|
|
|
|
this.playerHandler.closePlayer()
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$store.commit('setMediaPlaying', null)
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
2022-05-15 22:48:41 +02:00
|
|
|
mediaSessionPlay() {
|
|
|
|
console.log('Media session play')
|
|
|
|
this.playerHandler.play()
|
|
|
|
},
|
|
|
|
mediaSessionPause() {
|
|
|
|
console.log('Media session pause')
|
|
|
|
this.playerHandler.pause()
|
|
|
|
},
|
|
|
|
mediaSessionStop() {
|
|
|
|
console.log('Media session stop')
|
|
|
|
this.playerHandler.pause()
|
|
|
|
},
|
|
|
|
mediaSessionSeekBackward() {
|
|
|
|
console.log('Media session seek backward')
|
|
|
|
this.playerHandler.jumpBackward()
|
|
|
|
},
|
|
|
|
mediaSessionSeekForward() {
|
|
|
|
console.log('Media session seek forward')
|
|
|
|
this.playerHandler.jumpForward()
|
|
|
|
},
|
|
|
|
mediaSessionSeekTo(e) {
|
|
|
|
console.log('Media session seek to', e)
|
|
|
|
if (e.seekTime !== null && !isNaN(e.seekTime)) {
|
|
|
|
this.playerHandler.seek(e.seekTime)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateMediaSessionPlaybackState() {
|
|
|
|
if ('mediaSession' in navigator) {
|
|
|
|
navigator.mediaSession.playbackState = this.isPlaying ? 'playing' : 'paused'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setMediaSession() {
|
|
|
|
if (!this.streamLibraryItem) {
|
|
|
|
console.error('setMediaSession: No library item set')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('mediaSession' in navigator) {
|
|
|
|
var coverImageSrc = this.$store.getters['globals/getLibraryItemCoverSrc'](this.streamLibraryItem, '/Logo.png')
|
|
|
|
const artwork = [
|
|
|
|
{
|
|
|
|
src: coverImageSrc
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
navigator.mediaSession.metadata = new MediaMetadata({
|
|
|
|
title: this.title,
|
|
|
|
artist: this.playerHandler.displayAuthor || this.mediaMetadata.authorName || 'Unknown',
|
|
|
|
album: this.mediaMetadata.seriesName || '',
|
|
|
|
artwork
|
|
|
|
})
|
|
|
|
console.log('Set media session metadata', navigator.mediaSession.metadata)
|
|
|
|
|
|
|
|
navigator.mediaSession.setActionHandler('play', this.mediaSessionPlay)
|
|
|
|
navigator.mediaSession.setActionHandler('pause', this.mediaSessionPause)
|
|
|
|
navigator.mediaSession.setActionHandler('stop', this.mediaSessionStop)
|
|
|
|
navigator.mediaSession.setActionHandler('seekbackward', this.mediaSessionSeekBackward)
|
|
|
|
navigator.mediaSession.setActionHandler('seekforward', this.mediaSessionSeekForward)
|
|
|
|
navigator.mediaSession.setActionHandler('seekto', this.mediaSessionSeekTo)
|
|
|
|
// navigator.mediaSession.setActionHandler('previoustrack')
|
|
|
|
// navigator.mediaSession.setActionHandler('nexttrack')
|
|
|
|
} else {
|
|
|
|
console.warn('Media session not available')
|
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
streamProgress(data) {
|
|
|
|
if (!data.numSegments) return
|
|
|
|
var chunks = data.chunks
|
2021-09-08 16:15:54 +02:00
|
|
|
console.log(`[StreamContainer] Stream Progress ${data.percent}`)
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setChunksReady(chunks, data.numSegments)
|
2021-08-21 01:29:10 +02:00
|
|
|
} else {
|
|
|
|
console.error('No Audio Ref')
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
2022-08-28 20:12:38 +02:00
|
|
|
sessionOpen(session) {
|
|
|
|
// For opening session on init (temporarily unused)
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$store.commit('setMediaPlaying', {
|
|
|
|
libraryItem: session.libraryItem,
|
|
|
|
episodeId: session.episodeId
|
|
|
|
})
|
2022-04-23 23:51:13 +02:00
|
|
|
this.playerHandler.prepareOpenSession(session, this.initialPlaybackRate)
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-04-16 19:37:10 +02:00
|
|
|
streamOpen(session) {
|
|
|
|
console.log(`[StreamContainer] Stream session open`, session)
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
streamClosed(streamId) {
|
2022-02-23 00:33:55 +01:00
|
|
|
// Stream was closed from the server
|
2022-03-13 02:59:35 +01:00
|
|
|
if (this.playerHandler.isPlayingLocalItem && this.playerHandler.currentStreamId === streamId) {
|
2022-02-23 00:33:55 +01:00
|
|
|
console.warn('[StreamContainer] Closing stream due to request from server')
|
|
|
|
this.playerHandler.closePlayer()
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
streamReady() {
|
2021-08-21 01:29:10 +02:00
|
|
|
console.log(`[STREAM-CONTAINER] Stream Ready`)
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setStreamReady()
|
2021-08-21 01:29:10 +02:00
|
|
|
} else {
|
|
|
|
console.error('No Audio Ref')
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
2021-11-13 22:24:56 +01:00
|
|
|
streamError(streamId) {
|
2022-02-23 00:33:55 +01:00
|
|
|
// Stream had critical error from the server
|
2022-03-13 02:59:35 +01:00
|
|
|
if (this.playerHandler.isPlayingLocalItem && this.playerHandler.currentStreamId === streamId) {
|
2022-02-23 00:33:55 +01:00
|
|
|
console.warn('[StreamContainer] Closing stream due to stream error from server')
|
|
|
|
this.playerHandler.closePlayer()
|
2021-11-13 22:24:56 +01:00
|
|
|
}
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
streamReset({ startTime, streamId }) {
|
2022-02-23 00:33:55 +01:00
|
|
|
this.playerHandler.resetStream(startTime, streamId)
|
|
|
|
},
|
|
|
|
castSessionActive(isActive) {
|
2022-03-13 02:59:35 +01:00
|
|
|
if (isActive && this.playerHandler.isPlayingLocalItem) {
|
2022-02-23 00:33:55 +01:00
|
|
|
// Cast session started switch to cast player
|
|
|
|
this.playerHandler.switchPlayer()
|
2022-03-13 02:59:35 +01:00
|
|
|
} else if (!isActive && this.playerHandler.isPlayingCastedItem) {
|
2022-02-23 00:33:55 +01:00
|
|
|
// Cast session ended switch to local player
|
|
|
|
this.playerHandler.switchPlayer()
|
|
|
|
}
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
async playLibraryItem(payload) {
|
|
|
|
var libraryItemId = payload.libraryItemId
|
|
|
|
var episodeId = payload.episodeId || null
|
|
|
|
|
|
|
|
if (this.playerHandler.libraryItemId == libraryItemId && this.playerHandler.episodeId == episodeId) {
|
2022-07-30 19:25:15 +02:00
|
|
|
if (payload.startTime !== null && !isNaN(payload.startTime)) {
|
|
|
|
this.seek(payload.startTime)
|
|
|
|
} else {
|
2022-08-13 20:56:37 +02:00
|
|
|
this.playerHandler.play()
|
2022-07-30 19:25:15 +02:00
|
|
|
}
|
2022-03-26 23:41:26 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-13 02:59:35 +01:00
|
|
|
var libraryItem = await this.$axios.$get(`/api/items/${libraryItemId}?expanded=1`).catch((error) => {
|
|
|
|
console.error('Failed to fetch full item', error)
|
2022-02-23 00:33:55 +01:00
|
|
|
return null
|
|
|
|
})
|
2022-03-13 02:59:35 +01:00
|
|
|
if (!libraryItem) return
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$store.commit('setMediaPlaying', {
|
|
|
|
libraryItem,
|
2022-08-28 20:12:38 +02:00
|
|
|
episodeId,
|
|
|
|
queueItems: payload.queueItems || []
|
2022-03-26 23:41:26 +01:00
|
|
|
})
|
2022-07-14 02:38:34 +02:00
|
|
|
this.$nextTick(() => {
|
|
|
|
if (this.$refs.audioPlayer) this.$refs.audioPlayer.checkUpdateChapterTrack()
|
|
|
|
})
|
|
|
|
|
2022-07-30 02:06:52 +02:00
|
|
|
this.playerHandler.load(libraryItem, episodeId, true, this.initialPlaybackRate, payload.startTime)
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
|
|
|
pauseItem() {
|
|
|
|
this.playerHandler.pause()
|
2022-06-04 02:11:13 +02:00
|
|
|
},
|
|
|
|
showFailedProgressSyncs() {
|
|
|
|
if (!isNaN(this.syncFailedToast)) this.$toast.dismiss(this.syncFailedToast)
|
|
|
|
this.syncFailedToast = this.$toast('Progress is not being synced. Restart playback', { timeout: false, type: 'error' })
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$eventBus.$on('cast-session-active', this.castSessionActive)
|
2022-07-30 02:06:52 +02:00
|
|
|
this.$eventBus.$on('playback-seek', this.seek)
|
2022-03-13 02:59:35 +01:00
|
|
|
this.$eventBus.$on('play-item', this.playLibraryItem)
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$eventBus.$on('pause-item', this.pauseItem)
|
2022-02-23 00:33:55 +01:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$eventBus.$off('cast-session-active', this.castSessionActive)
|
2022-07-30 02:06:52 +02:00
|
|
|
this.$eventBus.$off('playback-seek', this.seek)
|
2022-03-13 02:59:35 +01:00
|
|
|
this.$eventBus.$off('play-item', this.playLibraryItem)
|
2022-03-26 23:41:26 +01:00
|
|
|
this.$eventBus.$off('pause-item', this.pauseItem)
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#streamContainer {
|
|
|
|
box-shadow: 0px -6px 8px #1111113f;
|
|
|
|
}
|
|
|
|
</style>
|