I´ve been struggling to get AirPlay to work with encrypted streams playing in AVPlayer.
Reading this page by Apple doesn´t do me much good.
Serve keys from a protected HTTPS realm. Before playback begins, your app can use NSURLConnection to authenticate itself, providing credentials that are kept hidden.
I could only get this to work in the simulator. Not on the device.
Use cookies over HTTPS. Your app can make a connection to an HTTPS server and authenticate the application in an application-defined way. Your server can then issue a cookie that applies to the key URLs. You should set the cookie to expire long after playback is complete. The server must then require the presence of a valid session cookie in future GET requests for the keys. For maximum reliability, if the expiration date is in the near future, the server should update the cookie’s expiration date in its response to future GET requests.
Haven´t actually tried this since I don´t have direct access to the server setup, but I am going to if no other answers appear.
Specify the keys in the .m3u8 files using an application-defined URL scheme. The app should register a custom NSURLProtocol to handle requests for those URLs. The player then calls back into your app when it needs to load a key URL; your app can then obtain the key using a secure side channel and can provide it to the player.
This doesn´t seem to work because AVPlayer HTTP connections bypass the NSURLProtocol system completely. You just can´t intercept any of the HTTP requests made by the AVPlayer.
I would be eternally grateful if anyone has a way of solving the encryption key serving problem in a manner that works with AVPlayer and AirPlay.