I'm currently trying to implement download of an encrypted HLS stream to an iOS device. iOS 10 seems to support that out of the box (see https://developer.apple.com/videos/play/wwdc2016/504), but I can't get it to work.
I am basically using the AssetPersistenceManager
from the Apple sample code (https://developer.apple.com/library/content/samplecode/HLSCatalog/Introduction/Intro.html), which calls makeAssetDownloadTask
of AVAssetDownloadURLSession
. It works fine in online mode, but the playback fails when playing the asset from the stored file.
Now the WWDC video indicates that you should use AVAssetResourceLoaderDelegate
to provide an offline encryption key. As http and https don't seem to be supported by the AVAssetResourceLoader
(see e.g. AVAssetResourceLoaderDelegate methods not working on device), I tried using a custom scheme for the key URI and provide a local aes key in shouldWaitForLoadingOfRequestedResource
of AVAssetResourceLoaderDelegate
. Here it also works when streaming online, but no matter whether I'm using the remote key URL or override it with a local key, AVPlayer always fails playing the AVAsset offline.
Does anyone have experience with downloading encrypted HLS or has a working example on how to provide an encryption key for playing a local encrypted AVURLAsset offline?
The sample HSL file I'm using is here:http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel-aes.ism/.m3u8
First, you need to download the key and save it.
Second, after you finish downloaded the HLS, you will get a folder name like "XXXXXX.movpkg". In the folder, there are two file you need to modified.
Inside both of files, there is a line
#EXT-X-KEY:METHOD=AES-128,URI="XXXXXX",IV=XXXXXXXXX
replace the URI with your local key location URL
That's it! Now you can get the key from local and play it normally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With