Downloading Media through Exoplayer Part 1

Promise Ochornma
2 min readSep 7, 2020

--

Photo by Markus Winkler on Unsplash

Exoplayer provides a method, through which we can cache a media source for playback through the app as seen on YouTube download.

The figure below depicts how the exoplayer download works.

Figure from Exoplayer developer guides
  1. The download service is a wrapper that allows the download manger work on the background

2. The download manger is responsible for reading the data from an HTTP data-source

3. The download index is responsible for persisting the state of the download

To use the exoplayer download manager, you need to subclass it’s download service and as expected, declare it in the Manifest

In order to make the DownloadManager be shared across all components of the app you can initialize it a custom application class. Exoplayer also advised that ExoDatabaseProvider should be a singleton and that download cache should not evict media

Below is the App Container Class

I have explained the reason I choose 30sec as the timeout as against the default 8sec provided by exoplayer and also allowed cross-protocol redirects, in my previous post Developing an android radio app for phones and Wear OS

Below is the subclass of the exoplayer download service

In Part 2, we will send a download request to the download service, retrieve the downloaded items and play them.

--

--