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?