Is it possible to AirPlay with a Custom AVAssetResourceLoader?

I currently am using AVQueuePlayer to play back a series of encrypted mp3 files. I do this by using a cusom AVAssetReasourceLoader and a custom url protocol. There are 2 reasons for this:


1) I am unable to store on device unencrypted files.
2) I support streaming content directly from our webserver.


The custom reasouce loader determines where to get data when AVPlayer sends a request. If the file is not saved to disk it will redirect to a web URL to be streamed. If the file is on disk however the reaource loader will decrypt the required bytes and ship them back to the player to be played. This dynamic is working and is working extremely well.




However Airplay is proving to be a problem. When testing AirPlay to an Apple TV everything will work if the reaource loader is redircting to the webserver for streaming playback. What does not work is playing from a file on the device. The reasource loader seems to behave as normal by decrypting the bytes and handing them off but the Apple TV instead just displays an error.


After 3 days of researching the only information I can find on this is a post on stack overflow :

(http://stackoverflow.com/questions/30752659/avassetresourceloader-backed-avurlasset-playback-fails-only-via-airplay).

In which the person states "I have now received a response from Apple (via a TSI) to this question. Video AirPlay is not supported when using a custom resource loader."


I also just found another post on your very forums of someone asking a simlar qustion to mine and referenceing the same small post:
https://forums.developer.apple.com/message/93507#93507


Both of these posts are talking about video however I am attempting to just play audio through AirPlay. Is this a possibilty with the current code setup I have described? If not what can I do to accomplish the same effect that is supported by Apple.

Replies

I am facing same issue, Do u have any update on this.

I'm working on playing FairPlay-encrypted audio, supporting offline playback via persistent keys. When I try to AirPlay, I get an error that the AVAssetResourceLoadingRequest's contentInformationRequest's allowedContentTypes (iOS 11.2+) doesn't contain AVStreamingKeyDeliveryPersistentContentKeyType. It won't accept my persistent key. And when I try to request a non-persistent key from my KSM, I get an error back from streamingContentKeyRequestDataForApp:.


Hilariously, if I set my AVPlayer's allowsExternalPlayback to NO, everything works.

I asked about this in the labs at WWDC 2018. My scenario is playing FairPlay-encrypted audio, using persistable content keys for offline playback. Persistable content keys only work on iOS, so the AppleTV can't handle them. I was told to file a radar about getting an error back from streamingContentKeyRequestDataForApp. The reason turning allowsExternalPlayback to NO works is that it causes the iOS device to stream the audio, decrypt it with the persistable content key, then re-encrypt it and stream it over AirPlay. Happiness all around.

Turns out the reason I was having an issue with allowsExternalPlayback set to YES was that I was passing YES for AVAssetResourceLoadingRequestStreamingContentKeyRequestRequiresPersistentKey in the options passed to streamingContentKeyRequestDataForApp, even when persistent keys weren't allowed (i.e. AVStreamingKeyDeliveryPersistentContentKeyType wasn't in loadingRequest.contentInformationRequest.allowedContentTypes). Pass NO there or omit it from the options and everything works great.