public final class HlsDownloader extends SegmentDownloader<HlsPlaylist>
Example usage:
SimpleCache cache = new SimpleCache(downloadFolder, new NoOpCacheEvictor());
DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory("ExoPlayer", null);
DownloaderConstructorHelper constructorHelper =
new DownloaderConstructorHelper(cache, factory);
// Create a downloader for the first variant in a master playlist.
HlsDownloader hlsDownloader =
new HlsDownloader(
playlistUri,
Collections.singletonList(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, 0)),
constructorHelper);
// Perform the download.
hlsDownloader.download();
// Access downloaded data using CacheDataSource
CacheDataSource cacheDataSource =
new CacheDataSource(cache, factory.createDataSource(), CacheDataSource.FLAG_BLOCK_ON_CACHE);
SegmentDownloader.Segment
Constructor and Description |
---|
HlsDownloader(Uri playlistUri,
List<StreamKey> streamKeys,
DownloaderConstructorHelper constructorHelper) |
Modifier and Type | Method and Description |
---|---|
protected HlsPlaylist |
getManifest(DataSource dataSource,
Uri uri)
Loads and parses the manifest.
|
protected List<SegmentDownloader.Segment> |
getSegments(DataSource dataSource,
HlsPlaylist playlist,
boolean allowIncompleteList)
Returns a list of all downloadable
SegmentDownloader.Segment s for a given manifest. |
cancel, download, getDownloadedBytes, getDownloadPercentage, remove
public HlsDownloader(Uri playlistUri, List<StreamKey> streamKeys, DownloaderConstructorHelper constructorHelper)
playlistUri
- The Uri
of the playlist to be downloaded.streamKeys
- Keys defining which renditions in the playlist should be selected for
download. If empty, all renditions are downloaded.constructorHelper
- A DownloaderConstructorHelper
instance.protected HlsPlaylist getManifest(DataSource dataSource, Uri uri) throws IOException
SegmentDownloader
getManifest
in class SegmentDownloader<HlsPlaylist>
dataSource
- The DataSource
through which to load.uri
- The manifest uri.IOException
- If an error occurs reading data.protected List<SegmentDownloader.Segment> getSegments(DataSource dataSource, HlsPlaylist playlist, boolean allowIncompleteList) throws IOException
SegmentDownloader
SegmentDownloader.Segment
s for a given manifest.getSegments
in class SegmentDownloader<HlsPlaylist>
dataSource
- The DataSource
through which to load any required data.playlist
- The manifest containing the segments.allowIncompleteList
- Whether to continue in the case that a load error prevents all
segments from being listed. If true then a partial segment list will be returned. If false
an IOException
will be thrown.SegmentDownloader.Segment
s.IOException
- Thrown if allowPartialIndex
is false and a load error occurs, or if
the media is not in a form that allows for its segments to be listed.