From 0576eacfddb32c4dcc072b6fd3cbf74cf25946a4 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Thu, 29 Aug 2024 12:27:07 +0200 Subject: [PATCH] fix(VisionOS): do not access to isExternalPlaybackActive on VisionOS (#4109) --- ios/Video/RCTVideo.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index bd1a916ea2..c394c8e90b 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -284,9 +284,18 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH // MARK: - App lifecycle handlers + func getIsExternalPlaybackActive() -> Bool { + #if os(visionOS) + let isExternalPlaybackActive = false + #else + let isExternalPlaybackActive = _player?.isExternalPlaybackActive ?? false + #endif + return isExternalPlaybackActive + } + @objc func applicationWillResignActive(notification _: NSNotification!) { - let isExternalPlaybackActive = _player?.isExternalPlaybackActive ?? false + let isExternalPlaybackActive = getIsExternalPlaybackActive() if _playInBackground || _playWhenInactive || !_isPlaying || isExternalPlaybackActive { return } _player?.pause() @@ -295,7 +304,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @objc func applicationDidBecomeActive(notification _: NSNotification!) { - let isExternalPlaybackActive = _player?.isExternalPlaybackActive ?? false + let isExternalPlaybackActive = getIsExternalPlaybackActive() if _playInBackground || _playWhenInactive || !_isPlaying || isExternalPlaybackActive { return } // Resume the player or any other tasks that should continue when the app becomes active. @@ -305,7 +314,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH @objc func applicationDidEnterBackground(notification _: NSNotification!) { - let isExternalPlaybackActive = _player?.isExternalPlaybackActive ?? false + let isExternalPlaybackActive = getIsExternalPlaybackActive() if !_playInBackground || isExternalPlaybackActive || isPipActive() { return } // Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html _playerLayer?.player = nil