fix: entering PiP mode when controls are true (#4776)
This commit is contained in:
@@ -68,14 +68,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
if isPictureInPictureActive() { return }
|
if isPictureInPictureActive() { return }
|
||||||
if _enterPictureInPictureOnLeave {
|
if _enterPictureInPictureOnLeave {
|
||||||
initPictureinPicture()
|
initPictureinPicture()
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
|
||||||
_playerViewController?.allowsPictureInPicturePlayback = true
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_pip?.deinitPipController()
|
_pip?.deinitPipController()
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
|
||||||
_playerViewController?.allowsPictureInPicturePlayback = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,6 +99,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private var _pip: RCTPictureInPicture?
|
private var _pip: RCTPictureInPicture?
|
||||||
|
private var _isPictureInPictureActive = false
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
@objc var onVideoLoadStart: RCTDirectEventBlock?
|
@objc var onVideoLoadStart: RCTDirectEventBlock?
|
||||||
@@ -138,19 +133,21 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
@objc
|
@objc
|
||||||
func _onPictureInPictureEnter() {
|
func _onPictureInPictureEnter() {
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
|
handlePictureInPictureEnter()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
func _onPictureInPictureExit() {
|
func _onPictureInPictureExit() {
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
handlePictureInPictureExit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePictureInPictureEnter() {
|
func handlePictureInPictureEnter() {
|
||||||
|
_isPictureInPictureActive = true
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
|
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePictureInPictureExit() {
|
func handlePictureInPictureExit() {
|
||||||
|
_isPictureInPictureActive = false
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
||||||
|
|
||||||
// To continue audio playback in backgroud we need to set
|
// To continue audio playback in backgroud we need to set
|
||||||
@@ -169,7 +166,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
func isPictureInPictureActive() -> Bool {
|
func isPictureInPictureActive() -> Bool {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
return _pip?._pipController?.isPictureInPictureActive == true
|
return _isPictureInPictureActive
|
||||||
#else
|
#else
|
||||||
return false
|
return false
|
||||||
#endif
|
#endif
|
||||||
@@ -1211,9 +1208,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
|
||||||
viewController.allowsPictureInPicturePlayback = _enterPictureInPictureOnLeave
|
|
||||||
}
|
|
||||||
return viewController
|
return viewController
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1244,6 +1238,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
func setControls(_ controls: Bool) {
|
func setControls(_ controls: Bool) {
|
||||||
if _controls != controls || ((_playerLayer == nil) && (_playerViewController == nil)) {
|
if _controls != controls || ((_playerLayer == nil) && (_playerViewController == nil)) {
|
||||||
_controls = controls
|
_controls = controls
|
||||||
|
#if os(iOS)
|
||||||
|
if !isPictureInPictureActive() {
|
||||||
|
_pip?.deinitPipController()
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if _controls {
|
if _controls {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.removePlayerLayer()
|
self.removePlayerLayer()
|
||||||
@@ -1828,15 +1827,38 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
private func findPlayerLayer(in view: UIView) -> AVPlayerLayer? {
|
||||||
func enterPictureInPicture() {
|
if let layer = view.layer as? AVPlayerLayer {
|
||||||
if _pip?._pipController == nil {
|
return layer
|
||||||
initPictureinPicture()
|
}
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
for sublayer in view.layer.sublayers ?? [] {
|
||||||
_playerViewController?.allowsPictureInPicturePlayback = true
|
if let playerLayer = sublayer as? AVPlayerLayer {
|
||||||
|
return playerLayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_pip?.enterPictureInPicture()
|
for subview in view.subviews {
|
||||||
|
if let playerLayer = findPlayerLayer(in: subview) {
|
||||||
|
return playerLayer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
func enterPictureInPicture() {
|
||||||
|
#if os(iOS)
|
||||||
|
if _pip == nil {
|
||||||
|
initPictureinPicture()
|
||||||
|
}
|
||||||
|
|
||||||
|
if _pip?._pipController == nil, let playerViewController = _playerViewController, _controls {
|
||||||
|
if let existingPlayerLayer = findPlayerLayer(in: playerViewController.view) {
|
||||||
|
_pip?.setupPipController(existingPlayerLayer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_pip?.enterPictureInPicture()
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
@@ -1846,14 +1868,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
_pip?.exitPictureInPicture()
|
_pip?.exitPictureInPicture()
|
||||||
if _enterPictureInPictureOnLeave {
|
if _enterPictureInPictureOnLeave {
|
||||||
initPictureinPicture()
|
initPictureinPicture()
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
|
||||||
_playerViewController?.allowsPictureInPicturePlayback = true
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_pip?.deinitPipController()
|
_pip?.deinitPipController()
|
||||||
if #available(iOS 9.0, tvOS 14.0, *) {
|
|
||||||
_playerViewController?.allowsPictureInPicturePlayback = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user