fix(tvOS): handle allowsPictureInPicturePlayback for tvOS (#4448)

This commit is contained in:
Philipp Mikheyev
2025-03-04 09:08:24 -05:00
committed by GitHub
parent b8459ca71d
commit 057c287f12

View File

@@ -65,16 +65,18 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
private var _lastBitrate = -2.0 private var _lastBitrate = -2.0
private var _enterPictureInPictureOnLeave = false { private var _enterPictureInPictureOnLeave = false {
didSet { didSet {
#if os(iOS) if isPictureInPictureActive() { return }
if isPictureInPictureActive() { return } if _enterPictureInPictureOnLeave {
if _enterPictureInPictureOnLeave { initPictureinPicture()
initPictureinPicture() if #available(iOS 9.0, tvOS 14.0, *) {
_playerViewController?.allowsPictureInPicturePlayback = true _playerViewController?.allowsPictureInPicturePlayback = true
} else { }
_pip?.deinitPipController() } else {
_pip?.deinitPipController()
if #available(iOS 9.0, tvOS 14.0, *) {
_playerViewController?.allowsPictureInPicturePlayback = false _playerViewController?.allowsPictureInPicturePlayback = false
} }
#endif }
} }
} }
@@ -1177,12 +1179,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
viewController.view.frame = self.bounds viewController.view.frame = self.bounds
viewController.player = player viewController.player = player
if #available(tvOS 14.0, *) { if #available(iOS 9.0, tvOS 14.0, *) {
viewController.allowsPictureInPicturePlayback = _enterPictureInPictureOnLeave viewController.allowsPictureInPicturePlayback = _enterPictureInPictureOnLeave
} }
#if os(iOS)
viewController.allowsPictureInPicturePlayback = _enterPictureInPictureOnLeave
#endif
return viewController return viewController
} }
@@ -1789,7 +1788,9 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
func enterPictureInPicture() { func enterPictureInPicture() {
if _pip?._pipController == nil { if _pip?._pipController == nil {
initPictureinPicture() initPictureinPicture()
_playerViewController?.allowsPictureInPicturePlayback = true if #available(iOS 9.0, tvOS 14.0, *) {
_playerViewController?.allowsPictureInPicturePlayback = true
}
} }
_pip?.enterPictureInPicture() _pip?.enterPictureInPicture()
} }
@@ -1799,15 +1800,17 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
guard isPictureInPictureActive() else { return } guard isPictureInPictureActive() else { return }
_pip?.exitPictureInPicture() _pip?.exitPictureInPicture()
#if os(iOS) if _enterPictureInPictureOnLeave {
if _enterPictureInPictureOnLeave { initPictureinPicture()
initPictureinPicture() if #available(iOS 9.0, tvOS 14.0, *) {
_playerViewController?.allowsPictureInPicturePlayback = true _playerViewController?.allowsPictureInPicturePlayback = true
} else { }
_pip?.deinitPipController() } else {
_pip?.deinitPipController()
if #available(iOS 9.0, tvOS 14.0, *) {
_playerViewController?.allowsPictureInPicturePlayback = false _playerViewController?.allowsPictureInPicturePlayback = false
} }
#endif }
} }
// Workaround for #3418 - https://github.com/TheWidlarzGroup/react-native-video/issues/3418#issuecomment-2043508862 // Workaround for #3418 - https://github.com/TheWidlarzGroup/react-native-video/issues/3418#issuecomment-2043508862