Fix all kinds of syncing errors

This commit is contained in:
ronaldheft
2022-08-13 12:41:20 -04:00
parent c029e519e9
commit e0e2f02e0b
6 changed files with 83 additions and 43 deletions
+9 -2
View File
@@ -71,12 +71,16 @@ class PlayerHandler {
}
public static func stopPlayback() {
player?.destroy()
player = nil
// Pause playback first, so we can sync our current progress
player?.pause()
// Stop updating progress before we destory the player, so we don't receive bad data
timer?.invalidate()
timer = nil
player?.destroy()
player = nil
NowPlayingInfo.shared.reset()
}
@@ -164,6 +168,9 @@ class PlayerHandler {
return
}
// Prevent a sync if we got junk data from the player (occurs when exiting out of memory
guard !playerCurrentTime.isNaN else { return }
lastSyncTime = Date().timeIntervalSince1970 // seconds
let report = PlaybackReport(currentTime: playerCurrentTime, duration: player.getDuration(), timeListened: listeningTimePassedSinceLastSync)