Downloading Adaptive Streams

Erdem Guven
AndroidX Media3
Published in
2 min readJul 9, 2018

There have been major changes since the writing of this post please see the new page on our developer site for the latest information on downloading.

This is a follow up post for Downloading Streams, covering the details related to downloading adaptive streams.

Adaptive streams (DASH, SmoothStreaming and HLS) consist of multiple media tracks, often the same content in different qualities (for example there can be SD, HD and 4K video) or in different languages (for audio and subtitle). For playback, a client can pick any of these tracks to play depending on the device and network capabilities.

Similarly for downloading, it is often enough to download only a few of the tracks. The tracks which need to be downloaded should be chosen manually before the download starts.

Choosing Tracks to Download

To choose tracks you want to download, you can use one of the DownloadHelper subclasses, depending on the type of the stream you want to download:

Storing DownloadActions

By keeping DownloadActions even after the download is over, you can use them to play downloaded content (described in the next section) and also to track what has been downloaded.

DownloadAction has two static methods, serializeToStream and deserializeFromStream, which can be used to store and load DownloadActions to/from a persistent storage.

For an example of how to do this, see the DownloadTracker class in the ExoPlayer demo app.

Playing Downloaded Adaptive Streams

While downloading an adaptive stream, the original manifest file is stored on the disk. If this manifest file is used as it is for playback, the tracks which haven’t been downloaded might be chosen. To prevent this, after the manifest file is loaded, it can be filtered to keep only downloaded tracks.

To create a MediaSource with a filtered manifest file you can use the download action which was used to download the stream:

Removing Downloaded Adaptive Streams

Removing an adaptive stream is the same as removing a progressive stream. It can be done by creating a remove action in the specific type of stream:

This removes all of the tracks belonging to the stream.

For a working example of what is described here, please take a look at the ExoPlayer demo app.

I hope this post makes it easy to start downloading adaptive streams. For questions and bugs please go to ExoPlayer Github issue tracker.

--

--