From fbb260e9164194a55d2b26404aea000e924e2f04 Mon Sep 17 00:00:00 2001 From: langemike Date: Fri, 7 Nov 2025 16:40:30 +0100 Subject: [PATCH] fix: prevent `audiovisualBackgroundPlaybackPolicy` crash (#4763) --- ios/Video/RCTVideo.swift | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index a3f897ac..b8cd390d 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -573,14 +573,15 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player as Any) _player!.replaceCurrentItem(with: playerItem) - - if #available(iOS 15.0, *) { - if _playInBackground { - _player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible - } else { - _player!.audiovisualBackgroundPlaybackPolicy = .automatic + #if !os(tvOS) && !os(visionOS) + if #available(iOS 15.0, *) { + if _playInBackground { + _player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible + } else { + _player!.audiovisualBackgroundPlaybackPolicy = .automatic + } } - } + #endif if _showNotificationControls { // We need to register player after we set current item and only for init @@ -601,13 +602,15 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } #endif - if #available(iOS 15.0, *) { - if _playInBackground { - _player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible - } else { - _player!.audiovisualBackgroundPlaybackPolicy = .automatic + #if !os(tvOS) && !os(visionOS) + if #available(iOS 15.0, *) { + if _playInBackground { + _player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible + } else { + _player!.audiovisualBackgroundPlaybackPolicy = .automatic + } } - } + #endif // later we can just call "updateNowPlayingInfo: NowPlayingInfoCenterManager.shared.updateNowPlayingInfo() }