ExoPlayer has nice features for downloading video for later offline use. It also provides CacheEvictor for selecting behaviour when the disk space is getting low. However, I would like to provide user possibility to clean up some space before even starting the download, or a chance to choose poorer quality for less space consumption.
Since we are talking about adaptive streams, not single mp4 files, learning the needed disk space seems not to be trivial. I am fine with a reasonably accurate estimate, but I can't come up even with that. Naturally it has to be available after user has selected the bitrate(s) to be downloaded and before the actual download. Download
class has contentLength
variable, but it seem to be zero (on adaptive streams?). DownloadRequest
has streamKeys
as indices to selected streams, but I have not found any place where I could use those. From our own metadata I can find out the length of the stream in seconds, so I guess there are three alternatives I am looking for:
from which I assume the middle one is the most likely to be available. Any ideas or knowledge?
As I pointed out in the question, with the length and the bitrate it is possible to calculate reasonable estimate. Getting length should be trivial and may be implementation specific, for getting selected bitrate (or help for selecting the bitrate) following classes and method calls will be useful (parameters and details excluded):
DownloadHelper.getMappedTrackInfo().getRenderedType()
DownloadHelper.getMappedTrackInfo().getRenderedType()
DownloadHelper.getMappedTrackInfo().getTrackGroups().get().getFormat().bitrate