mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-30 22:59:35 +02:00
refactor: Use refactored seek back time class
This commit is contained in:
parent
890852bef5
commit
cdfbbcbf8a
1 changed files with 1 additions and 27 deletions
|
@ -289,8 +289,7 @@ class AudioPlayer: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine where we are starting playback
|
// Determine where we are starting playback
|
||||||
let lastPlayed = (session.updatedAt ?? 0)/1000
|
let currentTime = allowSeekBack ? PlayerTimeUtils.calcSeekBackTime(currentTime: session.currentTime, lastPlayedMs: session.updatedAt) : session.currentTime
|
||||||
let currentTime = allowSeekBack ? calculateSeekBackTimeAtCurrentTime(session.currentTime, lastPlayed: lastPlayed) : session.currentTime
|
|
||||||
|
|
||||||
// Sync our new playback position
|
// Sync our new playback position
|
||||||
Task { await PlayerProgress.shared.syncFromPlayer(currentTime: currentTime, includesPlayProgress: self.isPlaying(), isStopping: false) }
|
Task { await PlayerProgress.shared.syncFromPlayer(currentTime: currentTime, includesPlayProgress: self.isPlaying(), isStopping: false) }
|
||||||
|
@ -307,31 +306,6 @@ class AudioPlayer: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func calculateSeekBackTimeAtCurrentTime(_ currentTime: Double, lastPlayed: Double) -> Double {
|
|
||||||
let difference = Date().timeIntervalSince1970 - lastPlayed
|
|
||||||
var time: Double = 0
|
|
||||||
|
|
||||||
// Scale seek back time based on how long since last play
|
|
||||||
if lastPlayed == 0 {
|
|
||||||
time = 5
|
|
||||||
} else if difference < 6 {
|
|
||||||
time = 2
|
|
||||||
} else if difference < 12 {
|
|
||||||
time = 10
|
|
||||||
} else if difference < 30 {
|
|
||||||
time = 15
|
|
||||||
} else if difference < 180 {
|
|
||||||
time = 20
|
|
||||||
} else if difference < 3600 {
|
|
||||||
time = 25
|
|
||||||
} else {
|
|
||||||
time = 29
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wind the clock back
|
|
||||||
return currentTime - time
|
|
||||||
}
|
|
||||||
|
|
||||||
private func resumePlayback() {
|
private func resumePlayback() {
|
||||||
logger.log("PLAY: Resuming playback")
|
logger.log("PLAY: Resuming playback")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue