7

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?

MxSagan
  • 123
  • 1
  • 7
  • Can you post the code where _playerItem and _resourceLoaderDelegate are declared? – Acey Oct 15 '14 at 00:07
  • I've updated the code above. Also, I've determined that if the url points to a local file the delegate gets called. Is there some way of tricking it into calling the delegate? – MxSagan Oct 15 '14 at 17:25
  • Your may have similar problem http://stackoverflow.com/questions/26649865/avassetresourceloaderdelegate-methods-not-working-on-device And there is my answer. – Chugaister Dec 29 '14 at 16:46

1 Answers1

9

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.

Dvyz
  • 479
  • 4
  • 9
  • `AVAssetResourceLoaderDelegate works only when we use a "Non Standard/Non Reserved" url scheme.` This doesn't seems like true. I am using https for key url and it's always called when it doesn't find the location of the key mentioned in m3u8 playlist. However, if you're not connected to internet, it'll not be called. Like in the case of persisted video when you try to fetch the key from keychain or app sandbox. – abhinavroy23 Sep 06 '17 at 10:18