mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-01 16:44:41 +02:00
Fix:Syncing when media is open in audio player and playing on another device #984
- Local playback session IDs have been updated to UUIDs instead of prefixing local_play_
This commit is contained in:
parent
dd66042766
commit
7412d0899f
5 changed files with 13 additions and 15 deletions
|
@ -81,7 +81,7 @@ class LocalLibraryItem(
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession {
|
fun getPlaybackSession(episode:PodcastEpisode?, deviceInfo:DeviceInfo):PlaybackSession {
|
||||||
val localEpisodeId = episode?.id
|
val localEpisodeId = episode?.id
|
||||||
val sessionId = "play_local_${UUID.randomUUID()}"
|
val sessionId = "${UUID.randomUUID()}"
|
||||||
|
|
||||||
// Get current progress for local media
|
// Get current progress for local media
|
||||||
val mediaProgressId = if (localEpisodeId.isNullOrEmpty()) id else "$id-$localEpisodeId"
|
val mediaProgressId = if (localEpisodeId.isNullOrEmpty()) id else "$id-$localEpisodeId"
|
||||||
|
|
|
@ -164,7 +164,7 @@ extension LocalLibraryItem {
|
||||||
|
|
||||||
func getPlaybackSession(episode: PodcastEpisode?) -> PlaybackSession {
|
func getPlaybackSession(episode: PodcastEpisode?) -> PlaybackSession {
|
||||||
let localEpisodeId = episode?.id
|
let localEpisodeId = episode?.id
|
||||||
let sessionId = "play_local_\(UUID().uuidString)"
|
let sessionId = UUID().uuidString
|
||||||
|
|
||||||
// Get current progress from local media
|
// Get current progress from local media
|
||||||
let mediaProgressId = (localEpisodeId != nil) ? "\(self.id)-\(localEpisodeId!)" : self.id
|
let mediaProgressId = (localEpisodeId != nil) ? "\(self.id)-\(localEpisodeId!)" : self.id
|
||||||
|
|
|
@ -21,7 +21,7 @@ class PlayerHandler {
|
||||||
cleanupOldSessions(currentSessionId: sessionId)
|
cleanupOldSessions(currentSessionId: sessionId)
|
||||||
|
|
||||||
// Set now playing info
|
// Set now playing info
|
||||||
NowPlayingInfo.shared.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil))
|
NowPlayingInfo.shared.setSessionMetadata(metadata: NowPlayingMetadata(id: session.id, itemId: session.libraryItemId!, title: session.displayTitle ?? "Unknown title", author: session.displayAuthor, series: nil, isLocal: session.isLocal))
|
||||||
|
|
||||||
// Create the audio player
|
// Create the audio player
|
||||||
player = AudioPlayer(sessionId: sessionId, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
player = AudioPlayer(sessionId: sessionId, playWhenReady: playWhenReady, playbackRate: playbackRate)
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct NowPlayingMetadata {
|
||||||
var title: String
|
var title: String
|
||||||
var author: String?
|
var author: String?
|
||||||
var series: String?
|
var series: String?
|
||||||
|
var isLocal: Bool
|
||||||
|
|
||||||
var coverUrl: URL? {
|
var coverUrl: URL? {
|
||||||
if self.isLocal {
|
if self.isLocal {
|
||||||
|
@ -25,8 +26,6 @@ struct NowPlayingMetadata {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var isLocal: Bool { id.starts(with: "play_local_") }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NowPlayingInfo {
|
class NowPlayingInfo {
|
||||||
|
|
|
@ -221,18 +221,6 @@ export default {
|
||||||
const prog = payload.data // MediaProgress
|
const prog = payload.data // MediaProgress
|
||||||
console.log(`[default] userMediaProgressUpdate checking for local media progress ${payload.id}`)
|
console.log(`[default] userMediaProgressUpdate checking for local media progress ${payload.id}`)
|
||||||
|
|
||||||
// Update local media progress if exists
|
|
||||||
const localProg = await this.$db.getLocalMediaProgressForServerItem({ libraryItemId: prog.libraryItemId, episodeId: prog.episodeId })
|
|
||||||
|
|
||||||
let newLocalMediaProgress = null
|
|
||||||
if (localProg && localProg.lastUpdate < prog.lastUpdate) {
|
|
||||||
if (localProg.currentTime == prog.currentTime && localProg.isFinished == prog.isFinished) {
|
|
||||||
console.log('[default] syncing progress server lastUpdate > local lastUpdate but currentTime and isFinished is equal')
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
console.log(`[default] syncing progress server lastUpdate > local lastUpdate. server currentTime=${prog.currentTime} local currentTime=${localProg.currentTime} | server/local isFinished=${prog.isFinished}/${localProg.isFinished}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this media item is currently open in the player, paused, and this progress update is coming from a different session
|
// Check if this media item is currently open in the player, paused, and this progress update is coming from a different session
|
||||||
const isMediaOpenInPlayer = this.$store.getters['getIsMediaStreaming'](prog.libraryItemId, prog.episodeId)
|
const isMediaOpenInPlayer = this.$store.getters['getIsMediaStreaming'](prog.libraryItemId, prog.episodeId)
|
||||||
if (isMediaOpenInPlayer && this.$store.getters['getCurrentPlaybackSessionId'] !== payload.sessionId && !this.$store.state.playerIsPlaying) {
|
if (isMediaOpenInPlayer && this.$store.getters['getCurrentPlaybackSessionId'] !== payload.sessionId && !this.$store.state.playerIsPlaying) {
|
||||||
|
@ -240,6 +228,17 @@ export default {
|
||||||
this.$eventBus.$emit('playback-time-update', payload.data.currentTime)
|
this.$eventBus.$emit('playback-time-update', payload.data.currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get local media progress if exists
|
||||||
|
const localProg = await this.$db.getLocalMediaProgressForServerItem({ libraryItemId: prog.libraryItemId, episodeId: prog.episodeId })
|
||||||
|
|
||||||
|
let newLocalMediaProgress = null
|
||||||
|
// Progress update is more recent then local progress
|
||||||
|
if (localProg && localProg.lastUpdate < prog.lastUpdate) {
|
||||||
|
if (localProg.currentTime == prog.currentTime && localProg.isFinished == prog.isFinished) {
|
||||||
|
console.log('[default] syncing progress server lastUpdate > local lastUpdate but currentTime and isFinished is equal')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Server progress is more up-to-date
|
// Server progress is more up-to-date
|
||||||
console.log(`[default] syncing progress from server with local item for "${prog.libraryItemId}" ${prog.episodeId ? `episode ${prog.episodeId}` : ''} | server lastUpdate=${prog.lastUpdate} > local lastUpdate=${localProg.lastUpdate}`)
|
console.log(`[default] syncing progress from server with local item for "${prog.libraryItemId}" ${prog.episodeId ? `episode ${prog.episodeId}` : ''} | server lastUpdate=${prog.lastUpdate} > local lastUpdate=${localProg.lastUpdate}`)
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue