From a59f3bb9570df8f39c24a70d438c54f69d4f651f Mon Sep 17 00:00:00 2001 From: ronaldheft Date: Fri, 19 Aug 2022 21:20:53 -0400 Subject: [PATCH] Fix player reporting currentTime=0 --- ios/App/Shared/player/AudioPlayer.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ios/App/Shared/player/AudioPlayer.swift b/ios/App/Shared/player/AudioPlayer.swift index 3ba2da62..5c8db6a1 100644 --- a/ios/App/Shared/player/AudioPlayer.swift +++ b/ios/App/Shared/player/AudioPlayer.swift @@ -144,18 +144,22 @@ class AudioPlayer: NSObject { NSLog("queueStatusObserver: Current Item Ready to play. PlayWhenReady: \(self.playWhenReady)") self.updateNowPlaying() + // Seek the player before initializing, so a currentTime of 0 does not appear in MediaProgress / session let firstReady = self.status < 0 - self.status = 0 - if self.playWhenReady { + if firstReady || self.playWhenReady { self.seek(playbackSession.currentTime, from: "queueItemStatusObserver") + } + + // Mark the player as ready + self.status = 0 + + // Start the player, if requested + if self.playWhenReady { self.playWhenReady = false self.play() - } else if (firstReady) { // Only seek on first readyToPlay - self.seek(playbackSession.currentTime, from: "queueItemStatusObserver") } } else if (playerItem.status == .failed) { NSLog("queueStatusObserver: FAILED \(playerItem.error?.localizedDescription ?? "")") - NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.failed.rawValue), object: nil) } })