# HlsDownloader

Artifact: [androidx.media3:media3-exoplayer-hls](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/hls/offline/HlsDownloader.java+class:androidx.media3.exoplayer.hls.offline.HlsDownloader)

*** ** * ** ***


```
@UnstableApi
public final class HlsDownloader extends SegmentDownloader<HlsPlaylist>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.media3.exoplayer.offline.SegmentDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader)\<[HlsPlaylist](https://developer.android.com/reference/androidx/media3/exoplayer/hls/playlist/HlsPlaylist)\> ||
|   | ↳ | [androidx.media3.exoplayer.hls.offline.HlsDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader) |

*** ** * ** ***

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 |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader.Factory extends https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.BaseFactory<https://developer.android.com/reference/androidx/media3/exoplayer/hls/playlist/HlsPlaylist>` A factory for `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader`. |

| ### Public constructors |
|---|
| `[HlsDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader#HlsDownloader(androidx.media3.common.MediaItem,androidx.media3.datasource.cache.CacheDataSource.Factory))( https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem, https://developer.android.com/reference/androidx/media3/datasource/cache/CacheDataSource.Factory cacheDataSourceFactory )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader.Factory#create(androidx.media3.common.MediaItem)` instead. <br /> |
| `[HlsDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader#HlsDownloader(androidx.media3.common.MediaItem,androidx.media3.datasource.cache.CacheDataSource.Factory,java.util.concurrent.Executor))( https://developer.android.com/reference/androidx/media3/common/MediaItem mediaItem, https://developer.android.com/reference/androidx/media3/datasource/cache/CacheDataSource.Factory cacheDataSourceFactory, https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader.Factory#create(androidx.media3.common.MediaItem)` instead. <br /> |

| ### Protected methods |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.Segment>` | `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader#getSegments(androidx.media3.datasource.DataSource,androidx.media3.exoplayer.hls.playlist.HlsPlaylist,boolean)( https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/androidx/media3/exoplayer/hls/playlist/HlsPlaylist manifest, boolean removing )` Returns a list of all downloadable `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.Segment`s for a given manifest. |

### Inherited Constants

From [androidx.media3.exoplayer.offline.SegmentDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader) `static final long` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_MS() = 20000`

### Inherited fields

From [androidx.media3.exoplayer.offline.SegmentDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader) `final long` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#durationUs()` `final long` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#startPositionUs()`

### Inherited methods

From [androidx.media3.exoplayer.offline.SegmentDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader) `void` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#cancel()()`

Permanently cancels the downloading by this downloader.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#download(androidx.media3.exoplayer.offline.Downloader.ProgressListener)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/offline/Downloader.ProgressListener progressListener)`

Downloads the content.
`final T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#execute(com.google.common.base.Supplier<androidx.media3.common.util.RunnableFutureTask<T,?>>,boolean)(
https://guava.dev/releases/snapshot-android/api/docs/com/google/common/base/Supplier.html<https://developer.android.com/reference/androidx/media3/common/util/RunnableFutureTask<T, @https://developer.android.com/reference/androidx/annotation/NonNull ?>> runnable,
boolean removing
)`

Executes the provided `https://developer.android.com/reference/androidx/media3/common/util/RunnableFutureTask`.
`static https://developer.android.com/reference/androidx/media3/datasource/DataSpec` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#getCompressibleDataSpec(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` `final M` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#getManifest(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)(https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec, boolean removing)`

Loads and parses a manifest.
`final M` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#getManifest(androidx.media3.datasource.DataSource,androidx.media3.exoplayer.upstream.ParsingLoadable.Parser<M>,androidx.media3.datasource.DataSpec,boolean)(
https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource,
https://developer.android.com/reference/androidx/media3/exoplayer/upstream/ParsingLoadable.Parser<M> manifestParser,
https://developer.android.com/reference/androidx/media3/datasource/DataSpec dataSpec,
boolean removing
)`

Loads and parses a manifest with a different parser than the base parser that parsed the initial manifest.
`final void` `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#remove()()`

Removes the content.

## Public constructors

### HlsDownloader

```
public [HlsDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader#HlsDownloader(androidx.media3.common.MediaItem,androidx.media3.datasource.cache.CacheDataSource.Factory))(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader.Factory#create(androidx.media3.common.MediaItem)` instead.

### HlsDownloader

```
public [HlsDownloader](https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader#HlsDownloader(androidx.media3.common.MediaItem,androidx.media3.datasource.cache.CacheDataSource.Factory,java.util.concurrent.Executor))(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory,
    Executor executor
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/media3/exoplayer/hls/offline/HlsDownloader.Factory#create(androidx.media3.common.MediaItem)` instead.

## Protected methods

### getSegments

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

Returns a list of all downloadable `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.Segment`s for a given manifest. Any required data should be loaded using `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#getManifest(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,boolean)` or `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader#execute(com.google.common.base.Supplier<androidx.media3.common.util.RunnableFutureTask<T,?>>,boolean)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | The `https://developer.android.com/reference/androidx/media3/datasource/DataSource` through which to load any required data. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/hls/playlist/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 `https://developer.android.com/reference/java/io/IOException.html` will be thrown in this case. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.Segment>` | The list of downloadable `https://developer.android.com/reference/androidx/media3/exoplayer/offline/SegmentDownloader.Segment`s. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | 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. |
| `https://developer.android.com/reference/java/lang/InterruptedException.html` |   |