From 2c1fc964bf2cb97624c8cc37ff8138465619fc61 Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Mon, 9 Sep 2024 15:46:53 +0200 Subject: [PATCH] fix(visionOS): remove unsupported apis (#4154) --- ios/Video/Features/RCTVideoSave.swift | 46 +++++++++++++++------------ ios/Video/RCTVideo.swift | 4 +-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ios/Video/Features/RCTVideoSave.swift b/ios/Video/Features/RCTVideoSave.swift index 76fc2901..e22b5671 100644 --- a/ios/Video/Features/RCTVideoSave.swift +++ b/ios/Video/Features/RCTVideoSave.swift @@ -19,26 +19,32 @@ enum RCTVideoSave { reject("ERROR_COULD_NOT_CREATE_EXPORT_SESSION", "Could not create export session", nil) return } - var path: String! - path = RCTVideoSave.generatePathInDirectory( - directory: URL(fileURLWithPath: RCTVideoSave.cacheDirectoryPath() ?? "").appendingPathComponent("Videos").path, - withExtension: ".mp4" - ) - let url: NSURL! = NSURL.fileURL(withPath: path) as NSURL - exportSession.outputFileType = AVFileType.mp4 - exportSession.outputURL = url as URL? - exportSession.videoComposition = playerItem?.videoComposition - exportSession.shouldOptimizeForNetworkUse = true - exportSession.exportAsynchronously(completionHandler: { - switch exportSession.status { - case .failed: - reject("ERROR_COULD_NOT_EXPORT_VIDEO", "Could not export video", exportSession.error) - case .cancelled: - reject("ERROR_EXPORT_SESSION_CANCELLED", "Export session was cancelled", exportSession.error) - default: - resolve(["uri": url.absoluteString]) - } - }) + + #if !os(visionOS) + var path: String! + path = RCTVideoSave.generatePathInDirectory( + directory: URL(fileURLWithPath: RCTVideoSave.cacheDirectoryPath() ?? "").appendingPathComponent("Videos").path, + withExtension: ".mp4" + ) + let url: NSURL! = NSURL.fileURL(withPath: path) as NSURL + exportSession.outputFileType = .mp4 + exportSession.outputFileType = AVFileType.mp4 + exportSession.outputURL = url as URL? + exportSession.videoComposition = playerItem?.videoComposition + exportSession.shouldOptimizeForNetworkUse = true + exportSession.exportAsynchronously(completionHandler: { + switch exportSession.status { + case .failed: + reject("ERROR_COULD_NOT_EXPORT_VIDEO", "Could not export video", exportSession.error) + case .cancelled: + reject("ERROR_EXPORT_SESSION_CANCELLED", "Export session was cancelled", exportSession.error) + default: + resolve(["uri": url.absoluteString]) + } + }) + #else + reject("ERROR_EXPORT_SESSION_CANCELLED", "this function is not supported on visionOS", nil) + #endif } static func generatePathInDirectory(directory: String?, withExtension extension: String?) -> String? { diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 345acbf0..11f7b57a 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -500,7 +500,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH NowPlayingInfoCenterManager.shared.registerPlayer(player: _player!) } } else { - #if !os(tvOS) + #if !os(tvOS) && !os(visionOS) if #available(iOS 16.0, *) { // This feature caused crashes, if the app was put in bg, before the source change // https://github.com/TheWidlarzGroup/react-native-video/issues/3900 @@ -508,7 +508,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } #endif _player?.replaceCurrentItem(with: playerItem) - #if !os(tvOS) + #if !os(tvOS) && !os(visionOS) if #available(iOS 16.0, *) { self._playerViewController?.allowsVideoFrameAnalysis = true }