From 6a885b7241adcbd0b389aff1e0439ae7bf23927e Mon Sep 17 00:00:00 2001 From: ronaldheft Date: Tue, 23 Aug 2022 17:13:43 -0400 Subject: [PATCH] Fix session time using milliseconds instead of seconds --- ios/App/Shared/player/PlayerProgress.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ios/App/Shared/player/PlayerProgress.swift b/ios/App/Shared/player/PlayerProgress.swift index 017cf9e3..8dcf7a35 100644 --- a/ios/App/Shared/player/PlayerProgress.swift +++ b/ios/App/Shared/player/PlayerProgress.swift @@ -49,16 +49,18 @@ class PlayerProgress { guard let session = PlayerHandler.getPlaybackSession() else { return nil } guard !currentTime.isNaN else { return nil } // Prevent bad data on player stop - let now = Date().timeIntervalSince1970 * 1000 - let lastUpdate = session.updatedAt ?? now - let timeSinceLastUpdate = now - lastUpdate + let nowInSeconds = Date().timeIntervalSince1970 + let nowInMilliseconds = nowInSeconds * 1000 + let lastUpdateInMilliseconds = session.updatedAt ?? nowInMilliseconds + let lastUpdateInSeconds = lastUpdateInMilliseconds / 1000 + let secondsSinceLastUpdate = nowInSeconds - lastUpdateInSeconds session.update { session.currentTime = currentTime - session.updatedAt = now + session.updatedAt = nowInMilliseconds if includesPlayProgress { - session.timeListening += timeSinceLastUpdate + session.timeListening += secondsSinceLastUpdate } }