自定义resourceLoader与AVComposition

时间:2015-10-22 21:05:34

标签: ios objective-c avfoundation avplayer avcomposition

有没有办法将自定义resourceLoader与AVComposition一起使用?当我在AVURLAsset上设置resourceLoader并使用该资产创建AVPlayerItem时,我得到AVAssetResourceLoaderDelegate回调。但是如果我在AVComposition中使用相同的AVURLAsset,我就不会得到委托回调。实际上,它永远不会从将资产插入到合成中的调用返回。

使用AVURLAsset调用的AVAssetResourceLoaderDelegate方法:

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方法未使用插入AVComposition的AVURLAsset调用:

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];

(实际上,它挂起在insertTimeRange:ofAsset:atTime:error。我想它会尝试从那时的munged url加载 - 但是不使用委托。)

调整url方案的方法,以便调用资源加载器委托:

- (NSURL*)mungeURL:(NSURL*)url
{
    NSURLComponents* components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
    components.scheme = @"fake-scheme";
    return [components URL];
}

0 个答案:

没有答案