Is there any way to use a custom resourceLoader with an AVComposition? I get the AVAssetResourceLoaderDelegate callbacks when I set the resourceLoader on an AVURLAsset and create an AVPlayerItem with that asset. But if I use that same AVURLAsset in an AVComposition, I don't get the delegate callbacks. In fact it never returns from the call to insert the asset into the composition.
AVAssetResourceLoaderDelegate methods called with AVURLAsset:
NSURL* mungedURL = [self mungeURL:itemURL];
AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:mungedURL options:nil];
[asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
AVAssetResourceLoaderDelegate methods NOT called with AVURLAsset inserted into AVComposition:
NSURL* mungedURL = [self mungeURL:itemURL];
AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:mungedURL options:nil];
[asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
AVMutableComposition* composition = [AVMutableComposition composition];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
[composition insertTimeRange:timeRange ofAsset:asset atTime:kCMTimeZero error:nil];
self.playerItem = [AVPlayerItem playerItemWithAsset:composition];
(actually, it hangs at insertTimeRange:ofAsset:atTime:error. I guess it tries to load from the munged url at that point - but doesn't use delegate.)
Method to tweak url scheme so resource loader delegate is called:
- (NSURL*)mungeURL:(NSURL*)url
{
NSURLComponents* components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
components.scheme = @"fake-scheme";
return [components URL];
}