Play encrypted video with AVPlayer

喜欢而已 提交于 2019-12-09 08:30:23

问题


I'm implementing an application that contains video player. For some reasons video files are encrypted with AES, and size of these files can be rather big to avoid loading it to RAM as one piece. I'm looking for some way to play it with AVPlayer.

Tried:

1) Custom NSURLProtocol as suggested here http://aptogo.co.uk/2010/07/protecting-resources/ Didn't work, I suggest that AVPlayer uses it's own and mine does not get called.

2) Use AVAsset to chop video in small chunks and then feed them to AVPlayer - failed because there's no API in AVPlayer for that.

Any workaround would be greatly appreciated :)


回答1:


You have 2 options:

  1. If targeting iOS 7 and newer the check out AVAssetResourceLoaderDelegate. It allows you to do what you would with a custom NSURLProtocol but specifically for AVPlayer.

  2. Emulate an HTTP server with support for the Range header and point the AVURLAsset to localhost.

I implemented #2 before and can provide more info if needed.




回答2:


I just downloaded the Apple sample project https://developer.apple.com/library/ios/samplecode/sc1791/Listings/ReadMe_txt.html and it seems to do exactly what you want.

The delegate catch each AVURLAsset's AVAssetResourceLoader calls and makes up a brand new .m3a8 file with a custom decryption key in it.
Then it feeds the player with all .ts file URLs in the m3a8.

The project is a good overview of what it is possible to do with HLS feeds.



来源:https://stackoverflow.com/questions/9740949/play-encrypted-video-with-avplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!