public final class DownloadHelper extends Object
The helper extracts track information from the media, selects tracks for downloading, and
creates download requests based on the selected tracks.
A typical usage of DownloadHelper follows these steps:
forMediaItem methods.
prepare(Callback) and wait for the callback.
getMappedTrackInfo(int) and getTrackSelections(int, int), and make adjustments using clearTrackSelections(int), replaceTrackSelections(int, Parameters) and addTrackSelection(int, Parameters).
getDownloadRequest(byte[]).
release().
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
DownloadHelper.Callback |
A callback to be notified when the
DownloadHelper is prepared. |
static class |
DownloadHelper.LiveContentUnsupportedException |
Thrown at an attempt to download live content.
|
| Modifier and Type | Field | Description |
|---|---|---|
static DefaultTrackSelector.Parameters |
DEFAULT_TRACK_SELECTOR_PARAMETERS |
Deprecated.
This instance does not have
Context constraints. |
static DefaultTrackSelector.Parameters |
DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT |
Default track selection parameters for downloading, but without any
Context
constraints. |
static DefaultTrackSelector.Parameters |
DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_VIEWPORT |
Deprecated.
This instance does not have
Context constraints. |
| Constructor | Description |
|---|---|
DownloadHelper(MediaItem mediaItem,
MediaSource mediaSource,
DefaultTrackSelector.Parameters trackSelectorParameters,
RendererCapabilities[] rendererCapabilities) |
Creates download helper.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
addAudioLanguagesToSelection(String... languages) |
Convenience method to add selections of tracks for all specified audio languages.
|
void |
addTextLanguagesToSelection(boolean selectUndeterminedTextLanguage,
String... languages) |
Convenience method to add selections of tracks for all specified text languages.
|
void |
addTrackSelection(int periodIndex,
DefaultTrackSelector.Parameters trackSelectorParameters) |
Adds a selection of tracks to be downloaded.
|
void |
addTrackSelectionForSingleRenderer(int periodIndex,
int rendererIndex,
DefaultTrackSelector.Parameters trackSelectorParameters,
List<DefaultTrackSelector.SelectionOverride> overrides) |
Convenience method to add a selection of tracks to be downloaded for a single renderer.
|
void |
clearTrackSelections(int periodIndex) |
Clears the selection of tracks for a period.
|
static MediaSource |
createMediaSource(DownloadRequest downloadRequest,
DataSource.Factory dataSourceFactory) |
Equivalent to
createMediaSource(downloadRequest, dataSourceFactory, null). |
static MediaSource |
createMediaSource(DownloadRequest downloadRequest,
DataSource.Factory dataSourceFactory,
DrmSessionManager drmSessionManager) |
Utility method to create a
MediaSource that only exposes the tracks defined in
downloadRequest. |
static DownloadHelper |
forDash(Context context,
Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory) |
Deprecated.
|
static DownloadHelper |
forDash(Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory,
DrmSessionManager drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) |
Deprecated.
|
static DownloadHelper |
forHls(Context context,
Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory) |
Deprecated.
|
static DownloadHelper |
forHls(Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory,
DrmSessionManager drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) |
Deprecated.
|
static DownloadHelper |
forMediaItem(Context context,
MediaItem mediaItem) |
Creates a
DownloadHelper for the given progressive media item. |
static DownloadHelper |
forMediaItem(Context context,
MediaItem mediaItem,
RenderersFactory renderersFactory,
DataSource.Factory dataSourceFactory) |
Creates a
DownloadHelper for the given media item. |
static DownloadHelper |
forMediaItem(MediaItem mediaItem,
DefaultTrackSelector.Parameters trackSelectorParameters,
RenderersFactory renderersFactory,
DataSource.Factory dataSourceFactory) |
Creates a
DownloadHelper for the given media item. |
static DownloadHelper |
forMediaItem(MediaItem mediaItem,
DefaultTrackSelector.Parameters trackSelectorParameters,
RenderersFactory renderersFactory,
DataSource.Factory dataSourceFactory,
DrmSessionManager drmSessionManager) |
Creates a
DownloadHelper for the given media item. |
static DownloadHelper |
forProgressive(Context context,
Uri uri) |
Deprecated.
|
static DownloadHelper |
forProgressive(Context context,
Uri uri,
String cacheKey) |
Deprecated.
|
static DownloadHelper |
forSmoothStreaming(Context context,
Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory) |
Deprecated.
|
static DownloadHelper |
forSmoothStreaming(Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory) |
Deprecated.
|
static DownloadHelper |
forSmoothStreaming(Uri uri,
DataSource.Factory dataSourceFactory,
RenderersFactory renderersFactory,
DrmSessionManager drmSessionManager,
DefaultTrackSelector.Parameters trackSelectorParameters) |
Deprecated.
|
static DefaultTrackSelector.Parameters |
getDefaultTrackSelectorParameters(Context context) |
Returns the default parameters used for track selection for downloading.
|
DownloadRequest |
getDownloadRequest(byte[] data) |
Builds a
DownloadRequest for downloading the selected tracks. |
DownloadRequest |
getDownloadRequest(String id,
byte[] data) |
Builds a
DownloadRequest for downloading the selected tracks. |
Object |
getManifest() |
Returns the manifest, or null if no manifest is loaded.
|
MappingTrackSelector.MappedTrackInfo |
getMappedTrackInfo(int periodIndex) |
Returns the mapped track info for the given period.
|
int |
getPeriodCount() |
Returns the number of periods for which media is available.
|
static RendererCapabilities[] |
getRendererCapabilities(RenderersFactory renderersFactory) |
Extracts renderer capabilities for the renderers created by the provided renderers factory.
|
TrackGroupArray |
getTrackGroups(int periodIndex) |
Returns the track groups for the given period.
|
List<ExoTrackSelection> |
getTrackSelections(int periodIndex,
int rendererIndex) |
Returns all
track selections for a period and renderer. |
void |
prepare(DownloadHelper.Callback callback) |
Initializes the helper for starting a download.
|
void |
release() |
Releases the helper and all resources it is holding.
|
void |
replaceTrackSelections(int periodIndex,
DefaultTrackSelector.Parameters trackSelectorParameters) |
Replaces a selection of tracks to be downloaded.
|
public static final DefaultTrackSelector.Parameters DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT
Context
constraints.
If possible, use getDefaultTrackSelectorParameters(Context) instead.
@Deprecated public static final DefaultTrackSelector.Parameters DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_VIEWPORT
Context constraints. Use getDefaultTrackSelectorParameters(Context) instead.@Deprecated public static final DefaultTrackSelector.Parameters DEFAULT_TRACK_SELECTOR_PARAMETERS
Context constraints. Use getDefaultTrackSelectorParameters(Context) instead.public DownloadHelper(MediaItem mediaItem, @Nullable MediaSource mediaSource, DefaultTrackSelector.Parameters trackSelectorParameters, RendererCapabilities[] rendererCapabilities)
mediaItem - The media item.mediaSource - A MediaSource for which tracks are selected, or null if no track
selection needs to be made.trackSelectorParameters - DefaultTrackSelector.Parameters for selecting tracks for
downloading.rendererCapabilities - The RendererCapabilities of the renderers for which tracks
are selected.public static DefaultTrackSelector.Parameters getDefaultTrackSelectorParameters(Context context)
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory)
renderersFactory - A RenderersFactory.RendererCapabilities for each renderer created by the
renderersFactory.@Deprecated public static DownloadHelper forProgressive(Context context, Uri uri)
@Deprecated public static DownloadHelper forProgressive(Context context, Uri uri, @Nullable String cacheKey)
@Deprecated public static DownloadHelper forDash(Context context, Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory)
@Deprecated public static DownloadHelper forDash(Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters)
@Deprecated public static DownloadHelper forHls(Context context, Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory)
@Deprecated public static DownloadHelper forHls(Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters)
@Deprecated public static DownloadHelper forSmoothStreaming(Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory)
@Deprecated public static DownloadHelper forSmoothStreaming(Context context, Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory)
@Deprecated public static DownloadHelper forSmoothStreaming(Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory, @Nullable DrmSessionManager drmSessionManager, DefaultTrackSelector.Parameters trackSelectorParameters)
public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem)
DownloadHelper for the given progressive media item.context - The context.mediaItem - A MediaItem.DownloadHelper for progressive streams.IllegalStateException - If the media item is of type DASH, HLS or SmoothStreaming.public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory)
DownloadHelper for the given media item.context - The context.mediaItem - A MediaItem.renderersFactory - A RenderersFactory creating the renderers for which tracks are
selected.dataSourceFactory - A DataSource.Factory used to load the manifest for adaptive
streams. This argument is required for adaptive streams and ignored for progressive
streams.DownloadHelper.IllegalStateException - If the corresponding module is missing for DASH, HLS or
SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.public static DownloadHelper forMediaItem(MediaItem mediaItem, DefaultTrackSelector.Parameters trackSelectorParameters, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory)
DownloadHelper for the given media item.mediaItem - A MediaItem.renderersFactory - A RenderersFactory creating the renderers for which tracks are
selected.trackSelectorParameters - DefaultTrackSelector.Parameters for selecting tracks for
downloading.dataSourceFactory - A DataSource.Factory used to load the manifest for adaptive
streams. This argument is required for adaptive streams and ignored for progressive
streams.DownloadHelper.IllegalStateException - If the corresponding module is missing for DASH, HLS or
SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.public static DownloadHelper forMediaItem(MediaItem mediaItem, DefaultTrackSelector.Parameters trackSelectorParameters, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory, @Nullable DrmSessionManager drmSessionManager)
DownloadHelper for the given media item.mediaItem - A MediaItem.renderersFactory - A RenderersFactory creating the renderers for which tracks are
selected.trackSelectorParameters - DefaultTrackSelector.Parameters for selecting tracks for
downloading.dataSourceFactory - A DataSource.Factory used to load the manifest for adaptive
streams. This argument is required for adaptive streams and ignored for progressive
streams.drmSessionManager - An optional DrmSessionManager. Used to help determine which
tracks can be selected.DownloadHelper.IllegalStateException - If the corresponding module is missing for DASH, HLS or
SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.public static MediaSource createMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory)
createMediaSource(downloadRequest, dataSourceFactory, null).public static MediaSource createMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory, @Nullable DrmSessionManager drmSessionManager)
MediaSource that only exposes the tracks defined in
downloadRequest.downloadRequest - A DownloadRequest.dataSourceFactory - A factory for DataSources to read the media.drmSessionManager - An optional DrmSessionManager to be passed to the MediaSource.MediaSource that only exposes the tracks defined in downloadRequest.public void prepare(DownloadHelper.Callback callback)
callback - A callback to be notified when preparation completes or fails.IllegalStateException - If the download helper has already been prepared.public void release()
@Nullable public Object getManifest()
public int getPeriodCount()
public TrackGroupArray getTrackGroups(int periodIndex)
Use getMappedTrackInfo(int) to get the track groups mapped to renderers.
periodIndex - The period index.TrackGroupArray.EMPTY for single stream
content.public MappingTrackSelector.MappedTrackInfo getMappedTrackInfo(int periodIndex)
periodIndex - The period index.MappingTrackSelector.MappedTrackInfo for the period.public List<ExoTrackSelection> getTrackSelections(int periodIndex, int rendererIndex)
track selections for a period and renderer. Must not be
called until after preparation completes.periodIndex - The period index.rendererIndex - The renderer index.track selections.public void clearTrackSelections(int periodIndex)
periodIndex - The period index for which track selections are cleared.public void replaceTrackSelections(int periodIndex,
DefaultTrackSelector.Parameters trackSelectorParameters)
periodIndex - The period index for which the track selection is replaced.trackSelectorParameters - The DefaultTrackSelector.Parameters to obtain the new
selection of tracks.public void addTrackSelection(int periodIndex,
DefaultTrackSelector.Parameters trackSelectorParameters)
periodIndex - The period index this track selection is added for.trackSelectorParameters - The DefaultTrackSelector.Parameters to obtain the new
selection of tracks.public void addAudioLanguagesToSelection(String... languages)
languages - A list of audio languages for which tracks should be added to the download
selection, as IETF BCP 47 conformant tags.public void addTextLanguagesToSelection(boolean selectUndeterminedTextLanguage,
String... languages)
selectUndeterminedTextLanguage - Whether a text track with undetermined language should be
selected for downloading if no track with one of the specified languages is
available.languages - A list of text languages for which tracks should be added to the download
selection, as IETF BCP 47 conformant tags.public void addTrackSelectionForSingleRenderer(int periodIndex,
int rendererIndex,
DefaultTrackSelector.Parameters trackSelectorParameters,
List<DefaultTrackSelector.SelectionOverride> overrides)
periodIndex - The period index the track selection is added for.rendererIndex - The renderer index the track selection is added for.trackSelectorParameters - The DefaultTrackSelector.Parameters to obtain the new
selection of tracks.overrides - A list of SelectionOverrides to apply to the
trackSelectorParameters. If empty, trackSelectorParameters are used as they are.public DownloadRequest getDownloadRequest(@Nullable byte[] data)
DownloadRequest for downloading the selected tracks. Must not be called until
after preparation completes. The uri of the DownloadRequest will be used as content id.data - Application provided data to store in DownloadRequest.data.DownloadRequest.public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data)
DownloadRequest for downloading the selected tracks. Must not be called until
after preparation completes.id - The unique content id.data - Application provided data to store in DownloadRequest.data.DownloadRequest.