Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用AVAssetResourceLoaderDelegate_Ios_Objective C_Delegates_Avfoundation_Http Live Streaming - Fatal编程技术网

Ios 未调用AVAssetResourceLoaderDelegate

Ios 未调用AVAssetResourceLoaderDelegate,ios,objective-c,delegates,avfoundation,http-live-streaming,Ios,Objective C,Delegates,Avfoundation,Http Live Streaming,我一直试图通过AVAssetResourceLoaderDelegate协议获取一些消息,但似乎从未被调用。我已经验证了所有的事情都发生在主线程上;通过创建avurlaste、创建AVPlayerItem、创建委托以及将委托队列设置为主线程。我正在尝试流式传输网络托管的MP4内容和未加密的HLS内容 我的声明: @property (readwrite, strong) AVPlayer* player; @property (strong) AVPlayerItem* playerItem;

我一直试图通过
AVAssetResourceLoaderDelegate
协议获取一些消息,但似乎从未被调用。我已经验证了所有的事情都发生在主线程上;通过创建
avurlaste
、创建
AVPlayerItem
、创建委托以及将委托队列设置为主线程。我正在尝试流式传输网络托管的MP4内容和未加密的HLS内容

我的声明:

@property (readwrite, strong) AVPlayer* player;
@property (strong) AVPlayerItem* playerItem;
@property (strong) id<AVAssetResourceLoaderDelegate> resourceLoaderDelegate;
但是,
resourceLoader:shouldWaitforLoadingFrequestedResource:
从未被调用(其他任何委托方法也不被调用)

为了清楚起见,我正在使用iOS模拟器以及运行iOS 8的iPhone 5s进行测试(结果看起来完全相同)

我已经验证了所有代码都是在主线程上执行的,正如我在文章中读到的,所有代码都必须在同一个线程上

是否有人有任何建议,或者对调用此委托的某些可用源代码的引用


更新:我已经确定,当url指向本地文件时,此代码可以正常工作,但当url指向远程文件时,此代码仍然不工作。这是预期的行为还是我可以为远程文件执行此操作?

只有在使用“非标准/非保留”url方案时,AVAssetResourceLoaderDelegate才起作用。HTTP、HTTPS等被视为保留URL方案,如果URL具有这些方案之一,iOS将不会进行委托调用。 我最后做的是使用我自己的http作为http URL,使用我自己的https作为https URL。它工作得很好。 还有一件事要记住,
如果URL具有非标准方案,则它可能无法在支持HLS的其他设备上工作

你能把代码发布在声明了_playerItem和_resourceLoaderDelegate的地方吗?我已经更新了上面的代码。此外,我还确定,如果url指向本地文件,则会调用委托。有没有办法诱使它调用代理?你可能有类似的问题,这就是我的答案。
AVAssetResourceLoaderDelegate只有在我们使用“非标准/非保留”url方案时才起作用。
这似乎不是真的。我使用https作为键url,当它找不到m3u8播放列表中提到的键的位置时,它总是被调用。但是,如果您未连接到internet,则不会调用它。就像在持久化视频的情况下,当您尝试从keychain或app沙盒获取密钥时。
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]];