SegmentDownloader

@UnstableApi
abstract class SegmentDownloader<M : FilterableManifest<M!>?> : Downloader

Known direct subclasses
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

Smallest unit of content to be downloaded.

Public constructors

SegmentDownloader(
    mediaItem: MediaItem!,
    manifestParser: ParsingLoadable.Parser<M!>!,
    cacheDataSourceFactory: CacheDataSource.Factory!,
    executor: Executor!
)

This function is deprecated.

Use SegmentDownloader instead.

SegmentDownloader(
    mediaItem: MediaItem!,
    manifestParser: ParsingLoadable.Parser<M!>!,
    cacheDataSourceFactory: CacheDataSource.Factory!,
    executor: Executor!,
    maxMergedSegmentStartTimeDiffMs: Long
)

Public functions

Unit

Permanently cancels the downloading by this downloader.

Unit

Downloads the content.

Unit

Removes the content.

Protected functions

T!
<T> execute(runnable: RunnableFutureTask<T!, Any!>!, removing: Boolean)

Executes the provided RunnableFutureTask.

java-static DataSpec!
M!
getManifest(dataSource: DataSource!, dataSpec: DataSpec!, removing: Boolean)

Loads and parses a manifest.

abstract (Mutable)List<SegmentDownloader.Segment!>!
getSegments(dataSource: DataSource!, manifest: M!, removing: Boolean)

Returns a list of all downloadable Segments for a given manifest.

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!
)

SegmentDownloader

SegmentDownloader(
    mediaItem: MediaItem!,
    manifestParser: ParsingLoadable.Parser<M!>!,
    cacheDataSourceFactory: CacheDataSource.Factory!,
    executor: Executor!,
    maxMergedSegmentStartTimeDiffMs: Long
)
Parameters
mediaItem: MediaItem!

The MediaItem to be downloaded.

manifestParser: ParsingLoadable.Parser<M!>!

A parser for manifests belonging to the media to be downloaded.

cacheDataSourceFactory: CacheDataSource.Factory!

A CacheDataSource.Factory for the cache into which the download will be written.

executor: 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.

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.

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 null.

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.

remove

fun remove(): Unit

Removes the content.

Protected functions

execute

protected fun <T> execute(runnable: RunnableFutureTask<T!, Any!>!, removing: Boolean): T!

Executes the provided RunnableFutureTask.

Parameters
runnable: RunnableFutureTask<T!, Any!>!

The RunnableFutureTask to execute.

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.

getCompressibleDataSpec

protected java-static fun getCompressibleDataSpec(uri: Uri!): DataSpec!

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 DataSpec.

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 DataSource through which to load any required data.

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 IOException will be thrown in this case.

Returns
(Mutable)List<SegmentDownloader.Segment!>!

The list of downloadable Segments.

Throws
java.io.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.

java.lang.InterruptedException