SegmentDownloader
@UnstableApi
abstract class SegmentDownloader<M : FilterableManifest<M!>?> : 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 : FilterableManifest<M!>?> |
The type of the manifest object. |
Summary
Nested types |
|---|
protected abstract class SegmentDownloader.BaseFactory<M : FilterableManifest<M!>?>A base class of the factory of the concrete extension of |
protected class SegmentDownloader.Segment : ComparableSmallest unit of content to be downloaded. |
Constants |
|
|---|---|
const Long |
Public constructors |
|---|
SegmentDownloader( |
Protected constructors |
|---|
SegmentDownloader( |
Public functions |
|
|---|---|
Unit |
cancel()Permanently cancels the downloading by this downloader. |
Unit |
download(progressListener: Downloader.ProgressListener?)Downloads the content. |
Unit |
remove()Removes the content. |
Protected functions |
|
|---|---|
T! |
<T> execute(Executes the provided |
java-static DataSpec! |
getCompressibleDataSpec(uri: Uri!) |
M! |
getManifest(dataSource: DataSource!, dataSpec: DataSpec!, removing: Boolean)Loads and parses a manifest. |
M! |
getManifest(Loads and parses a manifest with a different parser than the base parser that parsed the initial manifest. |
abstract (Mutable)List<SegmentDownloader.Segment!>! |
getSegments(dataSource: DataSource!, manifest: M!, removing: Boolean)Returns a list of all downloadable |
Constants
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_MS
const val DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_MS = 20000: Long
Public constructors
SegmentDownloader
SegmentDownloader(
mediaItem: MediaItem!,
manifestParser: ParsingLoadable.Parser<M!>!,
cacheDataSourceFactory: CacheDataSource.Factory!,
executor: Executor!,
maxMergedSegmentStartTimeDiffMs: Long,
startPositionUs: Long,
durationUs: Long
)
| Parameters | |
|---|---|
mediaItem: MediaItem! |
The |
manifestParser: ParsingLoadable.Parser<M!>! |
A parser for manifests belonging to the media to be downloaded. |
cacheDataSourceFactory: CacheDataSource.Factory! |
A |
executor: Executor! |
An |
maxMergedSegmentStartTimeDiffMs: Long |
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. |
startPositionUs: Long |
The start position in microseconds that the download should start from. |
durationUs: Long |
The duration in microseconds from the |
Protected constructors
SegmentDownloader
protected SegmentDownloader(
mediaItem: MediaItem!,
manifestParser: ParsingLoadable.Parser<M!>!,
cacheDataSourceFactory: CacheDataSource.Factory!,
executor: Executor!,
maxMergedSegmentStartTimeDiffMs: Long
)
Public functions
cancel
fun cancel(): Unit
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
fun download(progressListener: Downloader.ProgressListener?): Unit
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 | |
|---|---|
progressListener: Downloader.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 functions
execute
protected fun <T> execute(
runnable: Supplier<RunnableFutureTask<T!, *>!>!,
removing: Boolean
): T!
Executes the provided RunnableFutureTask.
| Parameters | |
|---|---|
runnable: Supplier<RunnableFutureTask<T!, *>!>! |
A supplier for the |
removing: Boolean |
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 fun getManifest(dataSource: DataSource!, dataSpec: DataSpec!, removing: Boolean): M!
Loads and parses a manifest.
| Parameters | |
|---|---|
dataSource: DataSource! |
The source to use when loading the manifest. |
dataSpec: DataSpec! |
The manifest |
removing: Boolean |
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. |
getManifest
protected fun getManifest(
dataSource: DataSource!,
manifestParser: ParsingLoadable.Parser<M!>!,
dataSpec: DataSpec!,
removing: Boolean
): M!
Loads and parses a manifest with a different parser than the base parser that parsed the initial manifest.
This is useful for cases where the manifest needs to be loaded and parsed as a different type than the base parser. For example, HLS manifests can be parsed as media playlists that inherit variable declarations from the multivariant playlist.
| Parameters | |
|---|---|
dataSource: DataSource! |
The source to use when loading the manifest. |
manifestParser: ParsingLoadable.Parser<M!>! |
The parser to use when parsing the manifest. |
dataSpec: DataSpec! |
The manifest |
removing: Boolean |
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 fun getSegments(dataSource: DataSource!, manifest: M!, removing: Boolean): (Mutable)List<SegmentDownloader.Segment!>!
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 |
manifest: M! |
The manifest containing the segments. |
removing: Boolean |
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 | |
|---|---|
(Mutable)List<SegmentDownloader.Segment!>! |
The list of downloadable |
| Throws | |
|---|---|
java.io.IOException |
Thrown if |
java.lang.InterruptedException |