fix(ios): player is frozen after re-focusing on the app (#3326)

* [bugfix] player is frozen after re-focusing on the app

* Fix playback rate on resume

Co-authored-by: Krzysztof Moch <krzysmoch.programs@gmail.com>

---------

Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com>
Co-authored-by: Krzysztof Moch <krzysmoch.programs@gmail.com>
This commit is contained in:
Andrii Drobiazko 2023-11-06 10:20:42 +01:00 committed by GitHub
parent cdbc856387
commit 722ae3477a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,6 +146,13 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
object: nil object: nil
) )
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationDidBecomeActive(notification:)),
name: UIApplication.didBecomeActiveNotification,
object: nil
)
NotificationCenter.default.addObserver( NotificationCenter.default.addObserver(
self, self,
selector: #selector(applicationDidEnterBackground(notification:)), selector: #selector(applicationDidEnterBackground(notification:)),
@ -194,6 +201,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_player?.rate = 0.0 _player?.rate = 0.0
} }
@objc func applicationDidBecomeActive(notification: NSNotification!) {
if _playInBackground || _playWhenInactive || _paused { return }
// Resume the player or any other tasks that should continue when the app becomes active.
_player?.play()
_player?.rate = _rate
}
@objc func applicationDidEnterBackground(notification:NSNotification!) { @objc func applicationDidEnterBackground(notification:NSNotification!) {
if !_playInBackground { if !_playInBackground {
// Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html // Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html