1

有没有办法将自定义资源加载器与 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 方法未在 AVURLAsset 插入 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];

(实际上,它挂在 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];
}
4

0 回答 0