AVAssetResourceLoaderDelegate设置问题

时间:2014-07-02 09:33:48

标签: ios ios7 avplayer avasset

尝试设置AVAssetResourceLoaderDelegate时遇到了一个奇怪的问题。使用此代码时,它大部分时间都在设备上工作,但它根本不在模拟器上工作:

NSURL *url = [NSURL URLWithString:@"xxx://name"];
AVURLAsset *asset = [AVURLAsset assetWithURL:url];

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
[asset.resourceLoader setDelegate:self queue:self.queue];

AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[avPlayer play];

问题是委托方法永远不会被调用:

- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest

但是,这段代码非常合适:

NSURL *url = [NSURL URLWithString:@"xxx://name"];
AVURLAsset *asset = [AVURLAsset assetWithURL:url];

[asset.resourceLoader setDelegate:self queue:self.queue];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];

AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[avPlayer play];

唯一的区别是我们先设置委托,然后用资产创建AVPlayerItem。在第一种情况下,创建AVPlayerItem时不会复制资产,如果我们检查playerItem.asset.resourceLoader.delegate,则委托设置正确,但它永远不会被调用。

我很感激任何帮助。

谢谢, 米甲

0 个答案:

没有答案