@UnstableApi
public final class HlsDownloader extends 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.Factory(cacheDataSourceFactory)
           .create(new MediaItem.Builder()
            .setUri(playlistUri)
             .setStreamKeys(
                ImmutableList.of(
                   new StreamKey(HlsMultivariantPlaylist.GROUP_INDEX_VARIANT, 0)))
              .build());
// Perform the download.
hlsDownloader.download(progressListener);
// Use the downloaded data for playback.
HlsMediaSource mediaSource =
    new HlsMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem);

Summary

Nested types

A factory for HLS downloaders.

Public constructors

HlsDownloader(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory
)

This method is deprecated.

Use create instead.

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

This method is deprecated.

Use create instead.

Protected methods

List<SegmentDownloader.Segment>
getSegments(
    DataSource dataSource,
    HlsPlaylist manifest,
    boolean removing
)

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

Inherited methods

From androidx.media3.exoplayer.offline.SegmentDownloader
void

Permanently cancels the downloading by this downloader.

final void

Downloads the content.

final T
<T> execute(RunnableFutureTask<T, Object> runnable, boolean removing)

Executes the provided RunnableFutureTask.

static DataSpec
final M
getManifest(DataSource dataSource, DataSpec dataSpec, boolean removing)

Loads and parses a manifest.

final void

Removes the content.

Public constructors

HlsDownloader

public HlsDownloader(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory
)

HlsDownloader

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

Protected methods

getSegments

protected List<SegmentDownloader.SegmentgetSegments(
    DataSource dataSource,
    HlsPlaylist 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 DataSource through which to load any required data.

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

Returns
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