From 8777b0a35ed24aef50a9b3be52d41742595e3094 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Thu, 16 Nov 2023 22:13:53 +0100 Subject: [PATCH] Fix(ios): another video caching fix (#3348) * fix: another fix from video caching --------- Co-authored-by: olivier --- ios/Video/RCTVideo.swift | 8 ++++---- ios/VideoCaching/RCTVideoCachingHandler.swift | 4 ++-- react-native-video.podspec | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 6779dfaec9..c95207a226 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -80,7 +80,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH private var _resouceLoaderDelegate: RCTResourceLoaderDelegate? private var _playerObserver: RCTPlayerObserver = RCTPlayerObserver() -#if canImport(RCTVideoCache) +#if USE_VIDEO_CACHING private let _videoCache:RCTVideoCachingHandler = RCTVideoCachingHandler() #endif @@ -174,7 +174,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH object: nil ) _playerObserver._handlers = self -#if canImport(RCTVideoCache) +#if USE_VIDEO_CACHING _videoCache.playerItemPrepareText = playerItemPrepareText #endif } @@ -316,11 +316,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH throw NSError(domain: "", code: 0, userInfo: nil) } - #if canImport(RCTVideoCache) +#if USE_VIDEO_CACHING if self._videoCache.shouldCache(source:source, textTracks:self._textTracks) { return self._videoCache.playerItemForSourceUsingCache(uri: source.uri, assetOptions:assetOptions) } - #endif +#endif if self._drm != nil || self._localSourceEncryptionKeyScheme != nil { self._resouceLoaderDelegate = RCTResourceLoaderDelegate( diff --git a/ios/VideoCaching/RCTVideoCachingHandler.swift b/ios/VideoCaching/RCTVideoCachingHandler.swift index 5f6ffb77c2..c09789ec18 100644 --- a/ios/VideoCaching/RCTVideoCachingHandler.swift +++ b/ios/VideoCaching/RCTVideoCachingHandler.swift @@ -77,8 +77,8 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate { // MARK: - DVAssetLoaderDelegate - func dvAssetLoaderDelegate(loaderDelegate:DVAssetLoaderDelegate!, didLoadData data:NSData!, forURL url:NSURL!) { - _videoCache.storeItem(data as Data?, forUri:url.absoluteString, withCallback:{ (success:Bool) in + func dvAssetLoaderDelegate(_ loaderDelegate: DVAssetLoaderDelegate!, didLoad data: Data!, for url: URL!) { + _videoCache.storeItem(data as Data?, forUri:url.absoluteString, withCallback:{ (success:Bool) in DebugLog("Cache data stored successfully 🎉") }) } diff --git a/react-native-video.podspec b/react-native-video.podspec index a68cf7330a..0098882520 100644 --- a/react-native-video.podspec +++ b/react-native-video.podspec @@ -32,7 +32,10 @@ Pod::Spec.new do |s| Pod::UI.puts "RNVideo: enable Video caching" ss.dependency "SPTPersistentCache", "~> 1.1.0" ss.dependency "DVAssetLoaderDelegate", "~> 0.3.1" - ss.source_files = "ios/Video/**/*.{h,m,swift}" "ios/VideoCaching/**/*.{h,m,swift}" + ss.source_files = "ios/*/**/*.{h,m,swift}" + ss.pod_target_xcconfig = { + 'OTHER_SWIFT_FLAGS' => '$(inherited) -D USE_VIDEO_CACHING' + } end end