[英]AVAssetResourceLoaderDelegate not being called
I've been trying to get some messages back on the AVAssetResourceLoaderDelegate
protocol but it never seems to get called. 我一直试图在AVAssetResourceLoaderDelegate
协议上获得一些消息,但它似乎永远不会被调用。 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. 从创建AVURLAsset
,创建AVPlayerItem
,创建委托,以及委托队列设置为主线程。 I'm trying to stream web-hosted MP4 content and unencrypted HLS content. 我正在尝试流式传输网络托管的MP4内容和未加密的HLS内容。
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). 但是, resourceLoader:shouldWaitForLoadingOfRequestedResource:
永远不会被调用(任何其他委托方法都没有)。
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). 为了清楚起见,我正在使用iOS模拟器以及运行iOS 8的iPhone 5s进行测试(结果看起来相同)。
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. 更新:我确定当url是本地文件时,此代码可以正常工作,但是当它到达远程文件时仍然无法正常工作。 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. AVAssetResourceLoaderDelegate仅在我们使用“非标准/非保留”网址方案时才有效。 HTTP, HTTPS etc are considered reserved URL schemes and iOS will not make a delegate call if the url has one of those schemes. HTTP,HTTPS等被视为保留URL方案,如果url具有其中一种方案,iOS将不会进行委托调用。 What I ended up doing was using my_own_http for the http urls and my_own_https for the https urls. 我最终做的是使用my_own_http作为http urls,使用my_own_https作为https网址。 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. 还有一件事要记住,如果你有非标准方案的URL,它可能无法在其他支持HLS的设备上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.