Fix:iOS sending multiple sync requests at the same time, Update:iOS sync every 5s

This commit is contained in:
advplyr 2022-07-28 19:30:18 -05:00
parent 16f6f3b7e9
commit 073110376a

View file

@ -11,6 +11,7 @@ class PlayerHandler {
private static var player: AudioPlayer?
private static var session: PlaybackSession?
private static var timer: Timer?
private static var lastSyncTime:Double = 0.0
private static var _remainingSleepTime: Int? = nil
public static var remainingSleepTime: Int? {
@ -128,7 +129,7 @@ class PlayerHandler {
listeningTimePassedSinceLastSync += 1
}
if listeningTimePassedSinceLastSync > 3 {
if listeningTimePassedSinceLastSync >= 5 {
syncProgress()
}
@ -149,6 +150,15 @@ class PlayerHandler {
return
}
// Prevent multiple sync requests
let timeSinceLastSync = Date().timeIntervalSince1970 - lastSyncTime
if (lastSyncTime > 0 && timeSinceLastSync < 1) {
NSLog("syncProgress last sync time was < 1 second so not syncing")
return
}
lastSyncTime = Date().timeIntervalSince1970 // seconds
let report = PlaybackReport(currentTime: playerCurrentTime, duration: player.getDuration(), timeListened: listeningTimePassedSinceLastSync)
session!.currentTime = playerCurrentTime