mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 07:07:22 +02:00
Fix:iOS sending multiple sync requests at the same time, Update:iOS sync every 5s
This commit is contained in:
@@ -11,6 +11,7 @@ class PlayerHandler {
|
|||||||
private static var player: AudioPlayer?
|
private static var player: AudioPlayer?
|
||||||
private static var session: PlaybackSession?
|
private static var session: PlaybackSession?
|
||||||
private static var timer: Timer?
|
private static var timer: Timer?
|
||||||
|
private static var lastSyncTime:Double = 0.0
|
||||||
|
|
||||||
private static var _remainingSleepTime: Int? = nil
|
private static var _remainingSleepTime: Int? = nil
|
||||||
public static var remainingSleepTime: Int? {
|
public static var remainingSleepTime: Int? {
|
||||||
@@ -128,7 +129,7 @@ class PlayerHandler {
|
|||||||
listeningTimePassedSinceLastSync += 1
|
listeningTimePassedSinceLastSync += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if listeningTimePassedSinceLastSync > 3 {
|
if listeningTimePassedSinceLastSync >= 5 {
|
||||||
syncProgress()
|
syncProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +150,15 @@ class PlayerHandler {
|
|||||||
return
|
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)
|
let report = PlaybackReport(currentTime: playerCurrentTime, duration: player.getDuration(), timeListened: listeningTimePassedSinceLastSync)
|
||||||
|
|
||||||
session!.currentTime = playerCurrentTime
|
session!.currentTime = playerCurrentTime
|
||||||
|
|||||||
Reference in New Issue
Block a user