Class HlsDownloader

  • All Implemented Interfaces:
    Downloader

    @Deprecated
    public final class HlsDownloader
    extends SegmentDownloader<HlsPlaylist>
    Deprecated.
    com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.
    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);