SegmentDownloader
@UnstableApi
public abstract class SegmentDownloader<M extends FilterableManifest<M>> implements Downloader
DashDownloader |
A downloader for DASH streams. |
HlsDownloader |
A downloader for HLS streams. |
SsDownloader |
A downloader for SmoothStreaming streams. |
Base class for multi segment stream downloaders.
| Parameters | |
|---|---|
<M extends FilterableManifest<M>> |
The type of the manifest object. |
Summary
Nested types |
|---|
protected abstract class SegmentDownloader.BaseFactory<M extends FilterableManifest<M>>A base class of the factory of the concrete extension of |
protected class SegmentDownloader.Segment implements ComparableSmallest unit of content to be downloaded. |
Constants |
|
|---|---|
static final long |
Public fields |
|
|---|---|
final long |
|
final long |
Public constructors |
|---|
SegmentDownloader( |
Protected constructors |
|---|
SegmentDownloader( |
Public methods |
|
|---|---|
void |
cancel()Permanently cancels the downloading by this downloader. |
final void |
download(@Nullable Downloader.ProgressListener progressListener)Downloads the content. |
final void |
remove()Removes the content. |
Protected methods |
|
|---|---|
final T |
<T> execute(RunnableFutureTask<T, Object> runnable, boolean removing)Executes the provided |
static DataSpec |
|
final M |
getManifest(DataSource dataSource, DataSpec dataSpec, boolean removing)Loads and parses a manifest. |
abstract List<SegmentDownloader.Segment> |
getSegments(DataSource dataSource, M manifest, boolean removing)Returns a list of all downloadable |
Constants
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_MS
public static final long DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_MS = 20000
Public fields
Public constructors
SegmentDownloader
public SegmentDownloader(
MediaItem mediaItem,
ParsingLoadable.Parser<M> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffMs,
long startPositionUs,
long durationUs
)
| Parameters | |
|---|---|
MediaItem mediaItem |
The |
ParsingLoadable.Parser<M> manifestParser |
A parser for manifests belonging to the media to be downloaded. |
CacheDataSource.Factory cacheDataSourceFactory |
A |
Executor executor |
An |
long maxMergedSegmentStartTimeDiffMs |
The maximum difference of the start time of two segments, up to which the segments (of the same URI) should be merged into a single download segment, in milliseconds. |
long startPositionUs |
The start position in microseconds that the download should start from. |
long durationUs |
The duration in microseconds from the |
Protected constructors
SegmentDownloader
protected SegmentDownloader(
MediaItem mediaItem,
ParsingLoadable.Parser<M> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor,
long maxMergedSegmentStartTimeDiffMs
)
Public methods
cancel
public void cancel()
Permanently cancels the downloading by this downloader. The caller should also interrupt the downloading thread immediately after calling this method.
Once canceled, download cannot be called again.
download
public final void download(@Nullable Downloader.ProgressListener progressListener)
Downloads 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 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.
| Parameters | |
|---|---|
@Nullable Downloader.ProgressListener progressListener |
A listener to receive progress updates, or |
| Throws | |
|---|---|
java.io.IOException |
If the download failed to complete successfully. |
java.lang.InterruptedException |
If the download was interrupted. |
java.util.concurrent.CancellationException |
If the download was canceled. |
Protected methods
execute
protected final T <T> execute(RunnableFutureTask<T, Object> runnable, boolean removing)
Executes the provided RunnableFutureTask.
| Parameters | |
|---|---|
RunnableFutureTask<T, Object> runnable |
The |
boolean removing |
Whether the execution is part of the download being removed. |
| Returns | |
|---|---|
T |
The result. |
| Throws | |
|---|---|
java.lang.InterruptedException |
If the thread on which the method is called is interrupted. |
java.io.IOException |
If an error occurs during execution. |
getManifest
protected final M getManifest(DataSource dataSource, DataSpec dataSpec, boolean removing)
Loads and parses a manifest.
| Parameters | |
|---|---|
DataSource dataSource |
The source to use when loading the manifest. |
DataSpec dataSpec |
The manifest |
boolean removing |
Whether the manifest is being loaded as part of the download being removed. |
| Returns | |
|---|---|
M |
The loaded manifest. |
| Throws | |
|---|---|
java.lang.InterruptedException |
If the thread on which the method is called is interrupted. |
java.io.IOException |
If an error occurs during execution. |
getSegments
protected abstract List<SegmentDownloader.Segment> getSegments(DataSource dataSource, M manifest, boolean removing)
Returns a list of all downloadable Segments for a given manifest. Any required data should be loaded using getManifest or execute.
| Parameters | |
|---|---|
DataSource dataSource |
The |
M manifest |
The manifest containing the segments. |
boolean 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 |
| Returns | |
|---|---|
List<SegmentDownloader.Segment> |
The list of downloadable |
| Throws | |
|---|---|
java.io.IOException |
Thrown if |
java.lang.InterruptedException |