From 0c3def6379874dbf1194c8d7d4a2366798e33341 Mon Sep 17 00:00:00 2001 From: imbererzin Date: Tue, 1 Oct 2024 11:22:03 +0300 Subject: [PATCH] fix bugs --- .../AVPlayerEngine+Observation.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Classes/Player/AVPlayerEngine/AVPlayerEngine+Observation.swift b/Classes/Player/AVPlayerEngine/AVPlayerEngine+Observation.swift index bad522d8..c0f59c1a 100644 --- a/Classes/Player/AVPlayerEngine/AVPlayerEngine+Observation.swift +++ b/Classes/Player/AVPlayerEngine/AVPlayerEngine+Observation.swift @@ -205,13 +205,18 @@ extension AVPlayerEngine { @objc func timebaseChanged(notification: Notification) { // For some reason timebase rate changed is received on a background thread. // in order to check self.rate we must make sure we are on the main thread. + DispatchQueue.main.async { guard let timebase = self.currentItem?.timebase else { return } PKLog.verbose("timebase changed, current timebase: \(String(describing: timebase))") let timebaseRate = CMTimebaseGetRate(timebase) if timebaseRate > 0 && self.lastTimebaseRate != timebaseRate { + PKLog.verbose("timebaseChanged->PlayerEvent.Playing") + self.post(event: PlayerEvent.Playing()) } else if timebaseRate == 0 && self.rate == 0 && self.lastTimebaseRate != timebaseRate { + PKLog.verbose("timebaseChanged->PlayerEvent.Pause") + self.post(event: PlayerEvent.Pause()) } // Make sure to save the last value so we could only post events only when currentTimebase != lastTimebase @@ -223,7 +228,7 @@ extension AVPlayerEngine { */ /// Handles changes in player rate private func handleRate() { - PKLog.debug("player rate was changed, now: \(self.rate)") + PKLog.verbose("player rate was changed, now: \(self.rate)") if let isPlaybackLikelyToKeepUp = self.currentItem?.isPlaybackLikelyToKeepUp, isPlaybackLikelyToKeepUp == false { if self.rate == 0, self.currentState == .buffering || self.currentState == .ready { @@ -233,10 +238,15 @@ extension AVPlayerEngine { // In all other cases, the player manages pause in the timebaseChanged event! //This is only when the user clicks the pause button on the TV and the app needs refreshing UI in BG. + PKLog.verbose("isAppInBackground = \(isAppInBackground)") if isAppInBackground{ + let isPaused = self.rate == 0 - if isPaused && self.lastTimebaseRate > 0{ + PKLog.verbose("isPaused = \(isPaused)") + + if isPaused{ if self.currentState != .idle && self.currentState != .ended && self.currentState != .error { + PKLog.verbose("player send pause event!!!") self.lastTimebaseRate = 0 self.post(event: PlayerEvent.Pause()) }