From 3560ffacab1f1bb9ff78342de5520b7fc6f13bae Mon Sep 17 00:00:00 2001 From: Olivier Bouillet Date: Thu, 22 Aug 2024 11:17:01 +0200 Subject: [PATCH] fix(VisionOS): do not access to isExternalPlaybackActive on VisionOS --- 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 325a06f174..a75d143fe6 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