Ran into this requirement recently, and despite a couple open questions on Stackoverflow and ExoPlayer’s issues page, there wasn’t much guidance.

Turns out this is relatively straightforward if you’re not streaming the video (e.g., you’re playing it from a local file).

The DataSource interface has 3 methods: open, close, and read. When the renderer is trying to play the file, it invokes read to get the bytes it needs. Open and close are basically setup and teardown – open happens when a source is first queried, and close happens when ExoPlayer thinks it no longer needs to read from the source.

If we look at most existing implementations:


We can see that in most cases, they’re just grabbing an InputStream on open, and reading from that in read. So with an encrypted file, simply decrypt it on the line before and convert that output (probably a byte array) to a Stream. Here’s an example based of ContentDataSource: