Skip to content

Commit

Permalink
Fix(ios): another video caching fix (#3348)
Browse files Browse the repository at this point in the history
* fix: another fix from video caching

---------

Co-authored-by: olivier <[email protected]>
  • Loading branch information
freeboub and olivier authored Nov 16, 2023
1 parent fdbd6a6 commit 8777b0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions ios/VideoCaching/RCTVideoCachingHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 🎉")
})
}
Expand Down
5 changes: 4 additions & 1 deletion react-native-video.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8777b0a

Please sign in to comment.