Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: iOS - Video Pauses When Exiting Fullscreen #4322

Open
giodevcoding opened this issue Dec 4, 2024 · 3 comments
Open

[BUG]: iOS - Video Pauses When Exiting Fullscreen #4322

giodevcoding opened this issue Dec 4, 2024 · 3 comments

Comments

@giodevcoding
Copy link
Contributor

giodevcoding commented Dec 4, 2024

Version

6.8.1

What platforms are you having the problem on?

iOS

System Version

6.8.1

On what device are you experiencing the issue?

Real device, Simulator

Architecture

New architecture with interop layer

What happened?

When playing a video, exiting fullscreen via native controls would automatically pause the video rather than persisting the playback state (playing). I would expect that the video would continue playing when exiting fullscreen via native controls.

I created a patch for this in my app. I have not yet created a PR as I'm not sure if it's the right way to fix the issue, but it was the only way I found I was able to fix the issue:

Patch

diff --git a/node_modules/react-native-video/ios/Video/RCTVideo.swift b/node_modules/react-native-video/ios/Video/RCTVideo.swift
index fde96d5..b729b0c 100644
--- a/node_modules/react-native-video/ios/Video/RCTVideo.swift
+++ b/node_modules/react-native-video/ios/Video/RCTVideo.swift
@@ -56,6 +56,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
     private var _fullscreenOrientation: String = "all"
     private var _fullscreenPlayerPresented = false
     private var _fullscreenUncontrolPlayerPresented = false // to call events switching full screen mode from player controls
+    private var _fullscreenExitedWhilePlaying = false
     private var _filterName: String!
     private var _filterEnabled = false
     private var _presentingViewController: UIViewController?
@@ -1187,6 +1188,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
         }
     }
 
+    func videoPlayerViewControllerFullScreenExited(playerViewController: AVPlayerViewController) {
+        if _isPlaying {
+            _fullscreenExitedWhilePlaying = true
+        }
+    }
+
     @objc
     func setFilter(_ filterName: String!) {
         _filterName = filterName
@@ -1498,8 +1505,21 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
         guard [.paused, .playing].contains(player.timeControlStatus) else {
             return
         }
+
         let isPlaying = player.timeControlStatus == .playing
 
+        if _fullscreenExitedWhilePlaying && !isPlaying {
+            _player?.play()
+            _player?.rate = _rate
+            return
+        }
+
+        if _fullscreenExitedWhilePlaying && isPlaying {
+            _isPlaying = isPlaying
+            _fullscreenExitedWhilePlaying = false
+            return
+        }
+
         guard _isPlaying != isPlaying else { return }
         _isPlaying = isPlaying
         onVideoPlaybackStateChanged?(["isPlaying": isPlaying, "isSeeking": self._pendingSeek == true, "target": reactTag as Any])
diff --git a/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewController.swift b/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewController.swift
index 11227b7..9857453 100644
--- a/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewController.swift
+++ b/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewController.swift
@@ -7,6 +7,8 @@ class RCTVideoPlayerViewController: AVPlayerViewController {
     var preferredOrientation: String?
     var autorotate: Bool?
 
+    private var _firstAppearance = false
+
     func shouldAutorotate() -> Bool {
         if autorotate! || preferredOrientation == nil || (preferredOrientation!.lowercased() == "all") {
             return true
@@ -22,6 +24,17 @@ class RCTVideoPlayerViewController: AVPlayerViewController {
         rctDelegate?.videoPlayerViewControllerDidDismiss(playerViewController: self)
     }
 
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
+
+        guard _firstAppearance else {
+            _firstAppearance = true
+            return
+        }
+
+        rctDelegate?.videoPlayerViewControllerFullScreenExited(playerViewController: self)
+    }
+
     #if !os(tvOS)
 
         func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
diff --git a/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewControllerDelegate.swift b/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewControllerDelegate.swift
index acce37e..2756954 100644
--- a/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewControllerDelegate.swift
+++ b/node_modules/react-native-video/ios/Video/RCTVideoPlayerViewControllerDelegate.swift
@@ -4,4 +4,5 @@ import Foundation
 protocol RCTVideoPlayerViewControllerDelegate: AnyObject {
     func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController)
     func videoPlayerViewControllerDidDismiss(playerViewController: AVPlayerViewController)
+    func videoPlayerViewControllerFullScreenExited(playerViewController: AVPlayerViewController)
 }

Reproduction Link

No response

Reproduction

Step to reproduce this bug are:

  1. Open Video
  2. Play Video
  3. Enter Fullscreen
  4. Exit Fullscreen
  5. Video should pause automatically on exiting fullscreen
Copy link

github-actions bot commented Dec 4, 2024

Previous bot comment (click to expand)

Thank you for your bug report. We will review it and get back to you if we need more information.

There is a newer version of the library available. You are using version 6.8.1, while the latest stable version is 6.8.2. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

Copy link

github-actions bot commented Dec 4, 2024

Thank you for your bug report. We will review it and get back to you if we need more information.

There is a newer version of the library available. You are using version 6.8.1, while the latest stable version is 6.8.2. Please update to the latest version and check if the issue still exists.

Note: If the issue still exists, please update the issue report with the latest information.

@harisheligarf
Copy link

i am also getting same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants