Class SegmentDownloader<M extends FilterableManifest<M>>
- Type Parameters:
M- The type of the manifest object.
- All Implemented Interfaces:
public abstract class SegmentDownloader<M extends FilterableManifest<M>> extends Object implements DownloaderBase class for multi segment stream downloaders.
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
cancel()Permanently cancels the downloading by this downloader.
download(Downloader.ProgressListener progressListener)Downloads the content.
protected <T> T
execute(RunnableFutureTask<T,?> runnable, boolean removing)Executes the provided
protected static DataSpec
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.
remove()Removes the content.
public SegmentDownloader(MediaItem mediaItem, ParsingLoadable.Parser<M> manifestParser, CacheDataSource.Factory cacheDataSourceFactory, Executor executor)
MediaItemto be downloaded.
manifestParser- A parser for manifests belonging to the media to be downloaded.
CacheDataSource.Factoryfor the cache into which the download will be written.
Executorused to make requests for the media being downloaded. Providing an
Executorthat 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, InterruptedExceptionDownloads the content.
If downloading fails, this method can be called again to resume the download. It cannot be called again after the download has been
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.
public void cancel()Permanently cancels the downloading by this downloader. The caller should also interrupt the downloading thread immediately after calling this method.
Downloader.download(com.google.android.exoplayer2.offline.Downloader.ProgressListener)cannot be called again.
protected final M getManifest(DataSource dataSource, DataSpec dataSpec, boolean removing) throws InterruptedException, IOExceptionLoads and parses a manifest.
dataSpec- The manifest
removing- Whether the manifest is being loaded as part of the download being removed.
- The loaded manifest.
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, IOExceptionExecutes the provided
protected abstract List<SegmentDownloader.Segment> getSegments(DataSource dataSource, M manifest, boolean removing) throws IOException, InterruptedExceptionReturns a list of all downloadable
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).
DataSourcethrough 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
IOExceptionwill be thrown in this case.
- The list of downloadable
IOException- Thrown if
allowPartialIndexis false and an execution error occurs, or if the media is not in a form that allows for its segments to be listed.