@UnstableApi
class HlsDownloader : SegmentDownloader


A downloader for HLS streams.

Example usage:

SimpleCache cache = new SimpleCache(downloadFolder, new NoOpCacheEvictor(), databaseProvider);
CacheDataSource.Factory cacheDataSourceFactory =
    new CacheDataSource.Factory()
        .setCache(cache)
        .setUpstreamDataSourceFactory(new DefaultHttpDataSource.Factory());
// Create a downloader for the first variant in a multivariant playlist.
HlsDownloader hlsDownloader =
    new HlsDownloader(
        new MediaItem.Builder()
            .setUri(playlistUri)
            .setStreamKeys(
                Collections.singletonList(
                    new StreamKey(HlsMultivariantPlaylist.GROUP_INDEX_VARIANT, 0)))
            .build(),
        Collections.singletonList();
// Perform the download.
hlsDownloader.download(progressListener);
// Use the downloaded data for playback.
HlsMediaSource mediaSource =
    new HlsMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem);

Summary

Public constructors

HlsDownloader(
    mediaItem: MediaItem!,
    cacheDataSourceFactory: CacheDataSource.Factory!
)

Creates a new instance.

HlsDownloader(
    mediaItem: MediaItem!,
    cacheDataSourceFactory: CacheDataSource.Factory!,
    executor: Executor!
)

Creates a new instance.

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

This function is deprecated.

Use HlsDownloader instead.

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

Creates a new instance.

Protected functions

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

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

Inherited functions

From androidx.media3.exoplayer.offline.SegmentDownloader
Unit

Permanently cancels the downloading by this downloader.

Unit

Downloads the content.

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.

Unit

Removes the content.

Public constructors

HlsDownloader

HlsDownloader(
    mediaItem: MediaItem!,
    cacheDataSourceFactory: CacheDataSource.Factory!
)

Creates a new instance.

Parameters
mediaItem: MediaItem!

The MediaItem to be downloaded.

cacheDataSourceFactory: CacheDataSource.Factory!

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

HlsDownloader

HlsDownloader(
    mediaItem: MediaItem!,
    cacheDataSourceFactory: CacheDataSource.Factory!,
    executor: Executor!
)

Creates a new instance.

Parameters
mediaItem: MediaItem!

The MediaItem 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.

HlsDownloader

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

HlsDownloader

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

Creates a new instance.

Parameters
mediaItem: MediaItem!

The MediaItem to be downloaded.

manifestParser: ParsingLoadable.Parser<HlsPlaylist!>!

A parser for HLS playlists.

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.

Protected functions

getSegments

protected fun getSegments(
    dataSource: DataSource!,
    manifest: HlsPlaylist!,
    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: HlsPlaylist!

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