fix(ios): don't pause playback when entering background (#3973)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user