I am playing audio on the Internet using AVPlayer and want to save the data / audio stream to local when avplayer finishes downloading the stream.
I implement it as the following:
let fileUrl = NSURL(string: strUrl)!
let asset = AVURLAsset(URL: fileUrl)
asset.resourceLoader.setDelegate(self, queue:dispatch_queue_create("AVARLDelegateDemo loader", nil))
self.pendingRequests = [AVAssetResourceLoadingRequest]()
asset.loadValuesAsynchronouslyForKeys(["playable"]){
dispatch_async( dispatch_get_main_queue()){
self.prepareToPlayAsset(asset, requestedKeys: ["playable"])
}
}
func resourceLoader(resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
.......
return false
}
When the URL is http / https , it does not call resourceLoader (resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource .... - when the URL is configured (for example: test '), it calls resourceLoader (resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequested
Who knows the reason, does resourceLoader not support http / https?