Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play encrypted video with AVPlayer

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 :)

like image 732
Asya Avatar asked Mar 16 '12 16:03

Asya


People also ask

Are video streams encrypted?

In live video streaming, broadcasters can use AES video encryption for secure streaming. When the video is encrypted, a special key scrambles the video content. They can't access the video unless the viewer has the correct digital access key.


1 Answers

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.

like image 101
Jernej Strasner Avatar answered Sep 18 '22 08:09

Jernej Strasner