mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 15:19:34 +02:00
Fix:iOS sending multiple sync requests at the same time, Update:iOS sync every 5s
This commit is contained in:
parent
16f6f3b7e9
commit
073110376a
1 changed files with 11 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue