AVAssetResourceLoaderDelegate未被调用 [英] AVAssetResourceLoaderDelegate not being called

查看:1548
本文介绍了AVAssetResourceLoaderDelegate未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 AVAssetResourceLoaderDelegate 协议上收到一些消息,但它似乎从来没有被调用。我已经验证一切都在主线程上发生;从创建 AVURLAsset ,创建 AVPlayerItem ,创建委托,委托队列设置为主线。我正在尝试流式传输网站托管的MP4内容和未加密的HLS内容。



我的声明:

  @property(readwrite,strong)AVPlayer *玩家; 
@property(强)AVPlayerItem * playerItem;
@property(strong)id< AVAssetResourceLoaderDelegate> resourceLoaderDelegate;

播放视频的代码:

  AVURLAsset * asset = [AVURLAsset URLAssetWithURL:url options:nil]; 
...
self> _resourceLoaderDelegate = [[MyAssetResourceLoaderDelegate alloc] init];
[asset.resourceLoader setDelegate:self> _resourceLoaderDelegate
queue:dispatch_get_main_queue()];
...
self> _playerItem = [AVPlayerItem playerItemWithAsset:asset];
...
[self setPlayer:[AVPlayer playerWithPlayerItem:self> _playerItem]];

然而,$ code> resourceLoader:shouldWaitForLoadingOfRequestedResource:调用(没有其他代理方法)。



为了清楚起见,我正在使用iOS Simulator以及运行iOS 8的iPhone 5(测试结果相同)进行测试。



我已经验证了所有代码正在主线程上执行,正如我在这个问题,一切都必须在同一个线程上。有没有人有任何建议,或者可能是引用一些可用的源代码,这个代理实际上被调用?



更新:我确定这个代码在url是本地文件时正常工作,但是当它到远程文件时仍然不起作用。这是预期的行为还是有一种我可以为远程文件执行此操作?

解决方案

AVAssetResourceLoaderDelegate仅在我们使用非标准/非保留url方案。 HTTP,HTTPS等被认为是保留的URL方案,如果url具有这些方案之一,则iOS将不会进行委托调用。
我最后做的是使用my_own_http作为https url和http_https的https url。它工作得很好
还有一件事要记住,
如果你有非标准方案的URL,它可能无法在其他支持HLS的设备上工作。


I've been trying to get some messages back on the AVAssetResourceLoaderDelegate protocol but it never seems to get called. I've verified that everything is happening on the main thread; from creation of AVURLAsset, creation of the AVPlayerItem, creation of the delegate, and the delegate queue is set to the main thread. I'm trying to stream web-hosted MP4 content and unencrypted HLS content.

My declarations:

@property (readwrite, strong) AVPlayer* player;
@property (strong) AVPlayerItem* playerItem;
@property (strong) id<AVAssetResourceLoaderDelegate> resourceLoaderDelegate;

Code for playing the video:

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
...
self->_resourceLoaderDelegate = [[MyAssetResourceLoaderDelegate alloc] init];
[asset.resourceLoader setDelegate:self->_resourceLoaderDelegate
                            queue:dispatch_get_main_queue()];
...
self->_playerItem = [AVPlayerItem playerItemWithAsset:asset];
...
[self setPlayer:[AVPlayer playerWithPlayerItem:self->_playerItem]];

However, resourceLoader:shouldWaitForLoadingOfRequestedResource: never gets called (neither do any of the other delegate methods).

For clarity's sake, I'm testing using the iOS Simulator as well as an iPhone 5s running iOS 8 (and the results appears identical).

I've verified that all of the code is being executed on the main thread, as I read in this question that everything must be on the same thread.

Does anyone have any suggestions, or perhaps a reference to some available source code where this delegate actually gets called?

Update: I've determined that this code works fine when the url is to a local file, but it still doesn't work when it's to a remote file. Is that expected behavior or is there a way I can do this for remote files?

解决方案

AVAssetResourceLoaderDelegate works only when we use a "Non Standard/Non Reserved" url scheme. HTTP, HTTPS etc are considered reserved URL schemes and iOS will not make a delegate call if the url has one of those schemes. What I ended up doing was using my_own_http for the http urls and my_own_https for the https urls. It works well. One more thing to remember, if you have the URL with non standard scheme, it may not work on other devices which support HLS.

这篇关于AVAssetResourceLoaderDelegate未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆