Don't sync progress for finished content

-> Still has the potential issue of starting a listening session
This commit is contained in:
Howard Wilson 2023-05-13 22:13:18 +02:00
parent 3c406c12b4
commit 1522783034
6 changed files with 21 additions and 9 deletions

View file

@ -41,6 +41,7 @@
:sleep-timer-set="sleepTimerSet" :sleep-timer-set="sleepTimerSet"
:sleep-timer-remaining="sleepTimerRemaining" :sleep-timer-remaining="sleepTimerRemaining"
:is-podcast="isPodcast" :is-podcast="isPodcast"
:is-finished="isFinished"
@playPause="playPause" @playPause="playPause"
@jumpForward="jumpForward" @jumpForward="jumpForward"
@jumpBackward="jumpBackward" @jumpBackward="jumpBackward"
@ -82,7 +83,8 @@ export default {
sleepTimer: null, sleepTimer: null,
displayTitle: null, displayTitle: null,
currentPlaybackRate: 1, currentPlaybackRate: 1,
syncFailedToast: null syncFailedToast: null,
isFinished: false
} }
}, },
computed: { computed: {
@ -203,6 +205,7 @@ export default {
}, },
setPlaying(isPlaying) { setPlaying(isPlaying) {
this.isPlaying = isPlaying this.isPlaying = isPlaying
this.isFinished = !this.playerHandler.syncProgress
this.$store.commit('setIsPlaying', isPlaying) this.$store.commit('setIsPlaying', isPlaying)
this.updateMediaSessionPlaybackState() this.updateMediaSessionPlaybackState()
}, },

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="relative"> <div class="relative">
<!-- Track --> <!-- Track -->
<div ref="track" class="w-full h-2 bg-gray-700 relative cursor-pointer transform duration-100 hover:scale-y-125 overflow-hidden" @mousemove="mousemoveTrack" @mouseleave="mouseleaveTrack" @click.stop="clickTrack"> <div ref="track" :class="isFinished ? 'bg-yellow-400' : 'bg-gray-700'" class="w-full h-2 relative cursor-pointer transform duration-100 hover:scale-y-125 overflow-hidden" @mousemove="mousemoveTrack" @mouseleave="mouseleaveTrack" @click.stop="clickTrack">
<div ref="readyTrack" class="h-full bg-gray-600 absolute top-0 left-0 pointer-events-none" /> <div ref="readyTrack" class="h-full bg-gray-600 absolute top-0 left-0 pointer-events-none" />
<div ref="bufferTrack" class="h-full bg-gray-500 absolute top-0 left-0 pointer-events-none" /> <div ref="bufferTrack" class="h-full bg-gray-500 absolute top-0 left-0 pointer-events-none" />
<div ref="playedTrack" class="h-full bg-gray-200 absolute top-0 left-0 pointer-events-none" /> <div ref="playedTrack" class="h-full bg-gray-200 absolute top-0 left-0 pointer-events-none" />
@ -39,7 +39,8 @@ export default {
type: Object, type: Object,
default: () => {} default: () => {}
}, },
playbackRate: Number playbackRate: Number,
isFinished: Boolean
}, },
data() { data() {
return { return {

View file

@ -46,7 +46,7 @@
<player-playback-controls :loading="loading" :seek-loading="seekLoading" :playback-rate.sync="playbackRate" :paused="paused" :has-next-chapter="hasNextChapter" @prevChapter="prevChapter" @nextChapter="nextChapter" @jumpForward="jumpForward" @jumpBackward="jumpBackward" @setPlaybackRate="setPlaybackRate" @playPause="playPause" /> <player-playback-controls :loading="loading" :seek-loading="seekLoading" :playback-rate.sync="playbackRate" :paused="paused" :has-next-chapter="hasNextChapter" @prevChapter="prevChapter" @nextChapter="nextChapter" @jumpForward="jumpForward" @jumpBackward="jumpBackward" @setPlaybackRate="setPlaybackRate" @playPause="playPause" />
</div> </div>
<player-track-bar ref="trackbar" :loading="loading" :chapters="chapters" :duration="duration" :current-chapter="currentChapter" :playback-rate="playbackRate" @seek="seek" /> <player-track-bar ref="trackbar" :loading="loading" :chapters="chapters" :duration="duration" :current-chapter="currentChapter" :playback-rate="playbackRate" :is-finished="isFinished" @seek="seek" />
<div class="flex"> <div class="flex">
<p ref="currentTimestamp" class="font-mono text-xxs sm:text-sm text-gray-100 pointer-events-auto">00:00:00</p> <p ref="currentTimestamp" class="font-mono text-xxs sm:text-sm text-gray-100 pointer-events-auto">00:00:00</p>
@ -78,7 +78,8 @@ export default {
}, },
sleepTimerSet: Boolean, sleepTimerSet: Boolean,
sleepTimerRemaining: Number, sleepTimerRemaining: Number,
isPodcast: Boolean isPodcast: Boolean,
isFinished: Boolean
}, },
data() { data() {
return { return {

View file

@ -27,6 +27,7 @@ export default class PlayerHandler {
this.listeningTimeSinceSync = 0 this.listeningTimeSinceSync = 0
this.playInterval = null this.playInterval = null
this.syncProgress = true
} }
get isCasting() { get isCasting() {
@ -218,6 +219,7 @@ export default class PlayerHandler {
prepareSession(session) { prepareSession(session) {
this.failedProgressSyncs = 0 this.failedProgressSyncs = 0
this.startTime = this.startTimeOverride !== undefined ? this.startTimeOverride : session.currentTime this.startTime = this.startTimeOverride !== undefined ? this.startTimeOverride : session.currentTime
this.syncProgress = !session.isFinished
this.currentSessionId = session.id this.currentSessionId = session.id
this.displayTitle = session.displayTitle this.displayTitle = session.displayTitle
this.displayAuthor = session.displayAuthor this.displayAuthor = session.displayAuthor
@ -300,7 +302,7 @@ export default class PlayerHandler {
if (this.player) { if (this.player) {
const listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync)) const listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
// When opening player and quickly closing dont save progress // When opening player and quickly closing dont save progress
if (listeningTimeToAdd > 20 || this.lastSyncTime > 0) { if (this.syncProgress && (listeningTimeToAdd > 20 || this.lastSyncTime > 0)) {
syncData = { syncData = {
timeListened: listeningTimeToAdd, timeListened: listeningTimeToAdd,
duration: this.getDuration(), duration: this.getDuration(),
@ -316,7 +318,7 @@ export default class PlayerHandler {
} }
sendProgressSync(currentTime) { sendProgressSync(currentTime) {
if (this.isMusic) return if (this.isMusic || !this.syncProgress) return
const diffSinceLastSync = Math.abs(this.lastSyncTime - currentTime) const diffSinceLastSync = Math.abs(this.lastSyncTime - currentTime)
if (diffSinceLastSync < 1) return if (diffSinceLastSync < 1) return

View file

@ -173,7 +173,7 @@ class PlaybackSessionManager {
} }
} }
const newPlaybackSession = new PlaybackSession() const newPlaybackSession = new PlaybackSession()
newPlaybackSession.setData(libraryItem, user, mediaPlayer, deviceInfo, userStartTime, episodeId) newPlaybackSession.setData(libraryItem, user, mediaPlayer, deviceInfo, userStartTime, userProgress.isFinished, episodeId)
if (libraryItem.mediaType === 'video') { if (libraryItem.mediaType === 'video') {
if (shouldDirectPlay) { if (shouldDirectPlay) {

View file

@ -32,6 +32,7 @@ class PlaybackSession {
this.timeListening = null this.timeListening = null
this.startTime = null // media current time at start of playback this.startTime = null // media current time at start of playback
this.currentTime = 0 // Last current time set this.currentTime = 0 // Last current time set
this.isFinished = null
this.startedAt = null this.startedAt = null
this.updatedAt = null this.updatedAt = null
@ -69,6 +70,7 @@ class PlaybackSession {
timeListening: this.timeListening, timeListening: this.timeListening,
startTime: this.startTime, startTime: this.startTime,
currentTime: this.currentTime, currentTime: this.currentTime,
isFinished: this.isFinished,
startedAt: this.startedAt, startedAt: this.startedAt,
updatedAt: this.updatedAt updatedAt: this.updatedAt
} }
@ -96,6 +98,7 @@ class PlaybackSession {
timeListening: this.timeListening, timeListening: this.timeListening,
startTime: this.startTime, startTime: this.startTime,
currentTime: this.currentTime, currentTime: this.currentTime,
isFinished: this.isFinished,
startedAt: this.startedAt, startedAt: this.startedAt,
updatedAt: this.updatedAt, updatedAt: this.updatedAt,
audioTracks: this.audioTracks.map(at => at.toJSON()), audioTracks: this.audioTracks.map(at => at.toJSON()),
@ -136,6 +139,7 @@ class PlaybackSession {
this.timeListening = session.timeListening || null this.timeListening = session.timeListening || null
this.startTime = session.startTime || 0 this.startTime = session.startTime || 0
this.currentTime = session.currentTime || 0 this.currentTime = session.currentTime || 0
this.currentTime = session.isFinished || null
this.startedAt = session.startedAt this.startedAt = session.startedAt
this.updatedAt = session.updatedAt || null this.updatedAt = session.updatedAt || null
@ -169,7 +173,7 @@ class PlaybackSession {
} }
} }
setData(libraryItem, user, mediaPlayer, deviceInfo, startTime, episodeId = null) { setData(libraryItem, user, mediaPlayer, deviceInfo, startTime, isFinished, episodeId = null) {
this.id = getId('play') this.id = getId('play')
this.userId = user.id this.userId = user.id
this.libraryId = libraryItem.libraryId this.libraryId = libraryItem.libraryId
@ -194,6 +198,7 @@ class PlaybackSession {
this.timeListening = 0 this.timeListening = 0
this.startTime = startTime this.startTime = startTime
this.currentTime = startTime this.currentTime = startTime
this.isFinished = isFinished
this.date = date.format(new Date(), 'YYYY-MM-DD') this.date = date.format(new Date(), 'YYYY-MM-DD')
this.dayOfWeek = date.format(new Date(), 'dddd') this.dayOfWeek = date.format(new Date(), 'dddd')