fix: prevent audiovisualBackgroundPlaybackPolicy crash (#4763)

This commit is contained in:
langemike
2025-11-07 16:40:30 +01:00
committed by GitHub
parent 90ccf4be29
commit fbb260e916

View File

@@ -573,7 +573,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player as Any)
_player!.replaceCurrentItem(with: playerItem)
#if !os(tvOS) && !os(visionOS)
if #available(iOS 15.0, *) {
if _playInBackground {
_player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible
@@ -581,6 +581,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_player!.audiovisualBackgroundPlaybackPolicy = .automatic
}
}
#endif
if _showNotificationControls {
// We need to register player after we set current item and only for init
@@ -601,6 +602,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
#endif
#if !os(tvOS) && !os(visionOS)
if #available(iOS 15.0, *) {
if _playInBackground {
_player!.audiovisualBackgroundPlaybackPolicy = .continuesIfPossible
@@ -608,6 +610,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_player!.audiovisualBackgroundPlaybackPolicy = .automatic
}
}
#endif
// later we can just call "updateNowPlayingInfo:
NowPlayingInfoCenterManager.shared.updateNowPlayingInfo()
}