M - The type of the manifest object.DownloaderDashDownloader, HlsDownloader, SsDownloaderpublic abstract class SegmentDownloader<M extends FilterableManifest<M>> extends Object implements Downloader
| Modifier and Type | Class | Description |
|---|---|---|
protected static class |
SegmentDownloader.Segment |
Smallest unit of content to be downloaded.
|
Downloader.ProgressListener| Constructor | Description |
|---|---|
SegmentDownloader(MediaItem mediaItem,
ParsingLoadable.Parser<M> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
cancel() |
Permanently cancels the downloading by this downloader.
|
void |
download(Downloader.ProgressListener progressListener) |
Downloads the content.
|
protected <T> T |
execute(RunnableFutureTask<T,?> runnable,
boolean removing) |
Executes the provided
RunnableFutureTask. |
protected static DataSpec |
getCompressibleDataSpec(Uri uri) |
|
protected M |
getManifest(DataSource dataSource,
DataSpec dataSpec,
boolean removing) |
Loads and parses a manifest.
|
protected abstract List<SegmentDownloader.Segment> |
getSegments(DataSource dataSource,
M manifest,
boolean removing) |
Returns a list of all downloadable
SegmentDownloader.Segments for a given manifest. |
void |
remove() |
Removes the content.
|
public SegmentDownloader(MediaItem mediaItem, ParsingLoadable.Parser<M> manifestParser, CacheDataSource.Factory cacheDataSourceFactory, Executor executor)
mediaItem - The MediaItem to be downloaded.manifestParser - A parser for manifests belonging to the media to be downloaded.cacheDataSourceFactory - A CacheDataSource.Factory for the cache into which the
download will be written.executor - An Executor used to make requests for the media being downloaded.
Providing an Executor that uses multiple threads will speed up the download by
allowing parts of it to be executed in parallel.public final void download(@Nullable
Downloader.ProgressListener progressListener)
throws IOException,
InterruptedException
DownloaderIf downloading fails, this method can be called again to resume the download. It cannot be
called again after the download has been canceled.
If downloading is canceled whilst this method is executing, then it is expected that it will return reasonably quickly. However, there are no guarantees about how the method will return, meaning that it can return without throwing, or by throwing any of its documented exceptions. The caller must use its own knowledge about whether downloading has been canceled to determine whether this is why the method has returned, rather than relying on the method returning in a particular way.
download in interface DownloaderprogressListener - A listener to receive progress updates, or null.IOException - If the download failed to complete successfully.InterruptedException - If the download was interrupted.public void cancel()
DownloaderOnce canceled, Downloader.download(com.google.android.exoplayer2.offline.Downloader.ProgressListener) cannot be called again.
cancel in interface Downloaderpublic final void remove()
Downloaderremove in interface Downloaderprotected final M getManifest(DataSource dataSource, DataSpec dataSpec, boolean removing) throws InterruptedException, IOException
dataSpec - The manifest DataSpec.removing - Whether the manifest is being loaded as part of the download being removed.InterruptedException - If the thread on which the method is called is interrupted.IOException - If an error occurs during execution.protected final <T> T execute(RunnableFutureTask<T,?> runnable, boolean removing) throws InterruptedException, IOException
RunnableFutureTask.runnable - The RunnableFutureTask to execute.removing - Whether the execution is part of the download being removed.InterruptedException - If the thread on which the method is called is interrupted.IOException - If an error occurs during execution.protected abstract List<SegmentDownloader.Segment> getSegments(DataSource dataSource, M manifest, boolean removing) throws IOException, InterruptedException
SegmentDownloader.Segments for a given manifest. Any required data
should be loaded using getManifest(com.google.android.exoplayer2.upstream.DataSource, com.google.android.exoplayer2.upstream.DataSpec, boolean) or execute(com.google.android.exoplayer2.util.RunnableFutureTask<T, ?>, boolean).dataSource - The DataSource through which to load any required data.manifest - The manifest containing the segments.removing - Whether the segments are being obtained as part of a removal. If true then a
partial segment list is returned in the case that a load error prevents all segments from
being listed. If false then an IOException will be thrown in this case.SegmentDownloader.Segments.IOException - Thrown if allowPartialIndex is false and an execution error occurs,
or if the media is not in a form that allows for its segments to be listed.InterruptedException