fix(ios): stabilize NowPlaying controls (#4857)

* fix(ios): stabilize NowPlaying controls

* fix(ios): dispatch NowPlaying update to main thread (#4862)

* docs: remove comment (#4863)

* rename player with `_`
This commit is contained in:
Kamil Moskała
2026-03-18 18:35:42 +01:00
committed by GitHub
parent eccf78b650
commit 0a403dd62d
3 changed files with 13 additions and 4 deletions
@@ -24,9 +24,12 @@ class NowPlayingInfoCenterManager {
var receivingRemoteControlEvents = false {
didSet {
if receivingRemoteControlEvents {
DispatchQueue.main.async {
DispatchQueue.main.async { [weak self] in
VideoManager.shared.setRemoteControlEventsActive(true)
UIApplication.shared.beginReceivingRemoteControlEvents()
if self?.currentPlayer?.currentItem != nil {
self?.updateNowPlayingInfo()
}
}
} else {
DispatchQueue.main.async {
@@ -317,10 +320,10 @@ class NowPlayingInfoCenterManager {
// We will observe players rate to find last active player that info will be displayed
private func observePlayers(player: AVPlayer) -> NSKeyValueObservation {
return player.observe(\.rate) { [weak self] player, change in
return player.observe(\.rate) { [weak self] player, _ in
guard let self else { return }
let rate = change.newValue
let rate = player.rate
// case where there is new player that is not paused
// In this case event is triggered by non currentPlayer
@@ -175,6 +175,13 @@ extension HybridVideoPlayer: VideoPlayerObserverDelegate {
)
}
func onPlayerItemChange(player _: AVPlayer, playerItem: AVPlayerItem?) {
guard showNotificationControls, let playerItem else { return }
DispatchQueue.main.async {
NowPlayingInfoCenterManager.shared.updateStaticInfo(ifCurrentItem: playerItem)
}
}
func onPlayerItemWillChange(hasNewPlayerItem: Bool) {
if hasNewPlayerItem {
// Set initial buffering state when playerItem is assigned
@@ -342,7 +342,6 @@ class HybridVideoPlayer: HybridVideoPlayerSpec, NativeVideoPlayerSpec {
try await self.initializePlayerItem()
}
self.player.replaceCurrentItem(with: self.playerItem)
NowPlayingInfoCenterManager.shared.updateNowPlayingInfo()
promise.resolve(withResult: ())
} catch {
if error is CancellationError {