NSURLProtocol registerClass works in simulator but not device for AVPlayer

Hi,


I was posting a follow-up question to an old thread at here. But I am not sure if anyone would see it. Hence I took the liberty to post a separate thread. Thanks for understanding.


I am using a custom protocol (Cronet network stack from Chromium) to play back video using AVPlayer. The code called [NSURLProtocol registerClass] to register its custom protocol and it works well in Xcode 11.3 iOS simulator testing. But the same code does not work on real device (iPhone, iOS 13).


The old thread I referred above seems to suggest that AVPlayer would never "see" the registered custom protocol, but I am wondering why it worked in simulator. And is it still true in recent iOS versions that AVPlayer would use a separate process (mediaserverd ?) to play back the video hence ignoring the custom protocol?


btw, I also tried to use AVAssetResourceLoaderDelegate to hijack the URL loading for AVPlayer, but did not work either in real device.


Thanks.

Han

Accepted Reply

I don’t think the situation here has changed since 2017. If you want to load video using a custom protocol, you must use

AVAssetResourceLoaderDelegate
. Fortunately, it seems that you’re starting with an
AVPlayer
, which means you have access to the
AVAsset
, so this shouldn’t be a problem.

As to why

AVAssetResourceLoaderDelegate
is not working for you, that’s an entirely different kettle of fish. I’m not an expert on that API — because it’s more of an AVFoundation thing that a networking thing — so my advice is that you ask for help with it over in Media > AVFoundation (Video and Camera). If that doesn’t pan out, you can open a DTS tech support incident and talk to one of DTS’s AVFoundation specialists.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

I don’t think the situation here has changed since 2017. If you want to load video using a custom protocol, you must use

AVAssetResourceLoaderDelegate
. Fortunately, it seems that you’re starting with an
AVPlayer
, which means you have access to the
AVAsset
, so this shouldn’t be a problem.

As to why

AVAssetResourceLoaderDelegate
is not working for you, that’s an entirely different kettle of fish. I’m not an expert on that API — because it’s more of an AVFoundation thing that a networking thing — so my advice is that you ask for help with it over in Media > AVFoundation (Video and Camera). If that doesn’t pan out, you can open a DTS tech support incident and talk to one of DTS’s AVFoundation specialists.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you eskimo! I will look into more with AVAssetResourceLoaderDelegate. I'm curious why [NSURLProtocol registerClass] worked for AVPlayer in iOS simulator ?

I'm curious why

+[NSURLProtocol registerClass]
worked for AVPlayer in iOS simulator?

I don’t know enough about the internals of AVFoundation to give you a definitive answer to that, but my guess is that AVFoundation does its networking in-process when built for the simulator, that is, there is no

mediaserverd
. You see this sort of thing all the time in the simulator. It’s called the simulator, not the emulator, for a reason (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"