From 722ae3477a68aecb812b26d71ea22a17dda71f50 Mon Sep 17 00:00:00 2001 From: Andrii Drobiazko <5869863+nethergrim@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:20:42 +0100 Subject: [PATCH] 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 --------- Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Co-authored-by: Krzysztof Moch --- ios/Video/RCTVideo.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 93203346..357ca247 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -145,6 +145,13 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH name: UIApplication.willResignActiveNotification, object: nil ) + + NotificationCenter.default.addObserver( + self, + selector: #selector(applicationDidBecomeActive(notification:)), + name: UIApplication.didBecomeActiveNotification, + object: nil + ) NotificationCenter.default.addObserver( self, @@ -193,6 +200,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH _player?.pause() _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!) { if !_playInBackground {