fix(ios): don't pause playback when entering background (#3973)
This commit is contained in:
parent
a3ecc0108c
commit
ccffcfd709
@ -6,11 +6,11 @@ import React
|
||||
|
||||
#if os(iOS)
|
||||
class RCTPictureInPicture: NSObject, AVPictureInPictureControllerDelegate {
|
||||
public private(set) var _pipController: AVPictureInPictureController?
|
||||
private var _onPictureInPictureEnter: (() -> Void)?
|
||||
private var _onPictureInPictureExit: (() -> Void)?
|
||||
private var _onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)?
|
||||
private var _restoreUserInterfaceForPIPStopCompletionHandler: ((Bool) -> Void)?
|
||||
private var _pipController: AVPictureInPictureController?
|
||||
private var _isActive = false
|
||||
|
||||
init(
|
||||
|
@ -156,6 +156,15 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
|
||||
func handlePictureInPictureExit() {
|
||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
||||
|
||||
// To continue audio playback in backgroud we need to set
|
||||
// player in _playerLayer & _playerViewController to nil
|
||||
let appState = UIApplication.shared.applicationState
|
||||
if _playInBackground && appState == .background {
|
||||
_playerLayer?.player = nil
|
||||
_playerViewController?.player = nil
|
||||
_player?.play()
|
||||
}
|
||||
}
|
||||
|
||||
func handleRestoreUserInterfaceForPictureInPictureStop() {
|
||||
@ -293,7 +302,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
@objc
|
||||
func applicationDidEnterBackground(notification _: NSNotification!) {
|
||||
let isExternalPlaybackActive = _player?.isExternalPlaybackActive ?? false
|
||||
if _playInBackground || isExternalPlaybackActive { return }
|
||||
if !_playInBackground || isExternalPlaybackActive || _pip?._pipController?.isPictureInPictureActive == true { return }
|
||||
// Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html
|
||||
_playerLayer?.player = nil
|
||||
_playerViewController?.player = nil
|
||||
|
Loading…
Reference in New Issue
Block a user