Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch committed Dec 26, 2023
1 parent 6211b4d commit ead39d4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ios/VideoCaching/RCTVideoCachingHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Promises

class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
private var _videoCache: RCTVideoCache! = RCTVideoCache.sharedInstance()
var playerItemPrepareText: ((AVAsset?, NSDictionary?, String) -> AVPlayerItem)?
var playerItemPrepareText: ((AVAsset?, NSDictionary?, String) -> Promise<AVPlayerItem>)?

override init() {
super.init()
Expand All @@ -29,7 +29,7 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
func playerItemForSourceUsingCache(uri: String!, assetOptions options: NSDictionary!) -> Promise<AVPlayerItem?> {
let url = URL(string: uri)
return getItemForUri(uri)
.then { [weak self] (videoCacheStatus: RCTVideoCacheStatus, cachedAsset: AVAsset?) -> AVPlayerItem in
.then { [weak self] (videoCacheStatus: RCTVideoCacheStatus, cachedAsset: AVAsset?) -> Promise<AVPlayerItem> in
guard let self = self, let playerItemPrepareText = self.playerItemPrepareText else { throw NSError(domain: "", code: 0, userInfo: nil) }
switch videoCacheStatus {
case .missingFileExtension:
Expand All @@ -56,7 +56,9 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
if let cachedAsset = cachedAsset {
DebugLog("Playing back uri '\(uri)' from cache")
// See note in playerItemForSource about not being able to support text tracks & caching
return AVPlayerItem(asset: cachedAsset)
return Promise {
AVPlayerItem(asset: cachedAsset)
}
}
}

Expand All @@ -75,7 +77,12 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
asset?.resourceLoader.setDelegate(resourceLoaderDelegate, queue: DispatchQueue.main)
*/

return AVPlayerItem(asset: asset)
return Promise {
AVPlayerItem(asset: asset)
}
}.then { playerItem -> AVPlayerItem? in
guard let playerItem = playerItem else { throw NSError(domain: "", code: 0, userInfo: nil) }
return playerItem
}
}

Expand Down

0 comments on commit ead39d4

Please sign in to comment.