Class HlsDownloader

  • All Implemented Interfaces:
    Downloader

    public final class HlsDownloader
    extends SegmentDownloader<HlsPlaylist>
    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 DefaultHttpDataSourceFactory(userAgent));
     // Create a downloader for the first variant in a master playlist.
     HlsDownloader hlsDownloader =
         new HlsDownloader(
             new MediaItem.Builder()
                 .setUri(playlistUri)
                 .setStreamKeys(
                     Collections.singletonList(
                         new StreamKey(HlsMasterPlaylist.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);