mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 15:19:34 +02:00
fix: Negative currentTime after seek back
This commit is contained in:
parent
cdfbbcbf8a
commit
2dbce1e3bb
2 changed files with 9 additions and 1 deletions
|
@ -17,6 +17,13 @@ final class PlayerTimeUtilsTests: XCTestCase {
|
||||||
XCTAssertEqual(PlayerTimeUtils.calcSeekBackTime(currentTime: currentTime, lastPlayedMs: lastPlayedMs), 998)
|
XCTAssertEqual(PlayerTimeUtils.calcSeekBackTime(currentTime: currentTime, lastPlayedMs: lastPlayedMs), 998)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCalcSeekBackTimeWithZeroCurrentTime() {
|
||||||
|
let currentTime: Double = 0
|
||||||
|
let threeHundredSecondsAgo = Date(timeIntervalSinceNow: -300)
|
||||||
|
let lastPlayedMs = threeHundredSecondsAgo.timeIntervalSince1970 * 1000
|
||||||
|
XCTAssertEqual(PlayerTimeUtils.calcSeekBackTime(currentTime: currentTime, lastPlayedMs: lastPlayedMs), 0)
|
||||||
|
}
|
||||||
|
|
||||||
func testTimeSinceLastPlayed() throws {
|
func testTimeSinceLastPlayed() throws {
|
||||||
let fiveSecondsAgo = Date(timeIntervalSinceNow: -5)
|
let fiveSecondsAgo = Date(timeIntervalSinceNow: -5)
|
||||||
let lastPlayedMs = fiveSecondsAgo.timeIntervalSince1970 * 1000
|
let lastPlayedMs = fiveSecondsAgo.timeIntervalSince1970 * 1000
|
||||||
|
|
|
@ -14,7 +14,8 @@ class PlayerTimeUtils {
|
||||||
static func calcSeekBackTime(currentTime: TimeInterval, lastPlayedMs: Double?) -> TimeInterval {
|
static func calcSeekBackTime(currentTime: TimeInterval, lastPlayedMs: Double?) -> TimeInterval {
|
||||||
let sinceLastPlayed = timeSinceLastPlayed(lastPlayedMs)
|
let sinceLastPlayed = timeSinceLastPlayed(lastPlayedMs)
|
||||||
let timeToSeekBack = timeToSeekBackForSinceLastPlayed(sinceLastPlayed)
|
let timeToSeekBack = timeToSeekBackForSinceLastPlayed(sinceLastPlayed)
|
||||||
return currentTime.advanced(by: -timeToSeekBack)
|
let currentTimeAfterSeekBack = currentTime.advanced(by: -timeToSeekBack)
|
||||||
|
return max(currentTimeAfterSeekBack, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
static internal func timeSinceLastPlayed(_ lastPlayedMs: Double?) -> TimeInterval? {
|
static internal func timeSinceLastPlayed(_ lastPlayedMs: Double?) -> TimeInterval? {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue