Search code examples
iosencryptionaesavplayerhttp-live-streaming

How to play a AES-128 encrypted HLS video in AVPlayer


I'm able to play a normal HLS video in AV Player without any trouble. But how do I play a AES-128 encrypted HLS Video?


Solution

  • To decode an AES-128/similar encrypted HLS Video, just add 'Authorization' to your header.

    let headers = ["Authorization": "Bearer xxxxxxxxxxxxxxxx..."]
    let avAsset = AVURLAsset(url: videoURL, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
    let avItem = AVPlayerItem(asset: avAsset)
    let avPlayer = AVPlayer(playerItem: avItem)
    .
    .
    .
    

    Thanks @SeanLintern88 for helping me out on this.