@UnstableApi
public final class SsDownloader extends SegmentDownloader


A downloader for SmoothStreaming 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 track of the first stream element.
SsDownloader ssDownloader =
    new SsDownloader(
        new MediaItem.Builder()
            .setUri(manifestUri)
            .setStreamKeys(Collections.singletonList(new StreamKey(0, 0)))
            .build(),
        cacheDataSourceFactory);
// Perform the download.
ssDownloader.download(progressListener);
// Use the downloaded data for playback.
SsMediaSource mediaSource =
    new SsMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem);

Summary

Public constructors

SsDownloader(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory
)

Creates an instance.

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

Creates an instance.

SsDownloader(
    MediaItem mediaItem,
    ParsingLoadable.Parser<SsManifest> manifestParser,
    CacheDataSource.Factory cacheDataSourceFactory,
    Executor executor
)

This method is deprecated.

Use SsDownloader instead.

SsDownloader(
    MediaItem mediaItem,
    ParsingLoadable.Parser<SsManifest> manifestParser,
    CacheDataSource.Factory cacheDataSourceFactory,
    Executor executor,
    long maxMergedSegmentStartTimeDiffMs
)

Creates a new instance.

Protected methods

List<SegmentDownloader.Segment>
getSegments(
    DataSource dataSource,
    SsManifest 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

SsDownloader

public SsDownloader(
    MediaItem mediaItem,
    CacheDataSource.Factory cacheDataSourceFactory
)

Creates an instance.

Parameters
MediaItem mediaItem

The MediaItem to be downloaded.

CacheDataSource.Factory cacheDataSourceFactory

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

SsDownloader

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

Creates an instance.

Parameters
MediaItem mediaItem

The MediaItem to be downloaded.

CacheDataSource.Factory cacheDataSourceFactory

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.

SsDownloader

public SsDownloader(
    MediaItem mediaItem,
    ParsingLoadable.Parser<SsManifest> manifestParser,
    CacheDataSource.Factory cacheDataSourceFactory,
    Executor executor
)

SsDownloader

public SsDownloader(
    MediaItem mediaItem,
    ParsingLoadable.Parser<SsManifest> manifestParser,
    CacheDataSource.Factory cacheDataSourceFactory,
    Executor executor,
    long maxMergedSegmentStartTimeDiffMs
)

Creates a new instance.

Parameters
MediaItem mediaItem

The MediaItem to be downloaded.

ParsingLoadable.Parser<SsManifest> manifestParser

A parser for SmoothStreaming manifests.

CacheDataSource.Factory cacheDataSourceFactory

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.

long maxMergedSegmentStartTimeDiffMs

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 methods

getSegments

protected List<SegmentDownloader.SegmentgetSegments(
    DataSource dataSource,
    SsManifest 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.

SsManifest 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.