Back to Exoplayer

DownloadHelper (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/offline/DownloadHelper.html

latest30.3 KB
Original Source

Package com.google.android.exoplayer2.offline

Class DownloadHelper


[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public final classDownloadHelperextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")

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 helper for initializing and removing downloads.

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:

  1. Build the helper using one of the forMediaItem methods.
  2. Prepare the helper using prepare(Callback) and wait for the callback.
  3. Optional: Inspect the selected tracks using getMappedTrackInfo(int) and getTrackSelections(int, int), and make adjustments using clearTrackSelections(int), replaceTrackSelections(int, TrackSelectionParameters) and addTrackSelection(int, TrackSelectionParameters).
  4. Create a download request for the selected track using getDownloadRequest(byte[]).
  5. Release the helper using release().

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static interface | DownloadHelper.Callback | Deprecated.

A callback to be notified when the DownloadHelper is prepared. | | static class | DownloadHelper.LiveContentUnsupportedException | Deprecated.

Thrown at an attempt to download live content. |

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static DefaultTrackSelector.Parameters | DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT | Deprecated.

Default track selection parameters for downloading, but without any Context constraints. |

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | DownloadHelper​(MediaItem mediaItem, MediaSource mediaSource, TrackSelectionParameters trackSelectionParameters, RendererCapabilities[] rendererCapabilities) | Deprecated.

Creates download helper. |

Method Summary

All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | addAudioLanguagesToSelection​(String... languages) | Deprecated.

Convenience method to add selections of tracks for all specified audio languages. | | void | addTextLanguagesToSelection​(boolean selectUndeterminedTextLanguage, String... languages) | Deprecated.

Convenience method to add selections of tracks for all specified text languages. | | void | addTrackSelection​(int periodIndex, TrackSelectionParameters trackSelectionParameters) | Deprecated.

Adds a selection of tracks to be downloaded. | | void | addTrackSelectionForSingleRenderer​(int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<DefaultTrackSelector.SelectionOverride> overrides) | Deprecated.

Convenience method to add a selection of tracks to be downloaded for a single renderer. | | void | clearTrackSelections​(int periodIndex) | Deprecated.

Clears the selection of tracks for a period. | | static MediaSource | createMediaSource​(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory) | Deprecated.

Equivalent to createMediaSource(downloadRequest, dataSourceFactory, null). | | static MediaSource | createMediaSource​(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager) | Deprecated.

Utility method to create a MediaSource that only exposes the tracks defined in downloadRequest. | | static DownloadHelper | forMediaItem​(Context context, MediaItem mediaItem) | Deprecated.

Creates a DownloadHelper for the given progressive media item. | | static DownloadHelper | forMediaItem​(Context context, MediaItem mediaItem, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory) | Deprecated.

Creates a DownloadHelper for the given media item. | | static DownloadHelper | forMediaItem​(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory) | Deprecated.

Creates a DownloadHelper for the given media item. | | static DownloadHelper | forMediaItem​(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager) | Deprecated.

Creates a DownloadHelper for the given media item. | | static DefaultTrackSelector.Parameters | getDefaultTrackSelectorParameters​(Context context) | Deprecated.

Returns the default parameters used for track selection for downloading. | | DownloadRequest | getDownloadRequest​(byte[] data) | Deprecated.

Builds a DownloadRequest for downloading the selected tracks. | | DownloadRequest | getDownloadRequest​(String id, byte[] data) | Deprecated.

Builds a DownloadRequest for downloading the selected tracks. | | Object | getManifest() | Deprecated.

Returns the manifest, or null if no manifest is loaded. | | MappingTrackSelector.MappedTrackInfo | getMappedTrackInfo​(int periodIndex) | Deprecated.

Returns the mapped track info for the given period. | | int | getPeriodCount() | Deprecated.

Returns the number of periods for which media is available. | | static RendererCapabilities[] | getRendererCapabilities​(RenderersFactory renderersFactory) | Deprecated.

Extracts renderer capabilities for the renderers created by the provided renderers factory. | | TrackGroupArray | getTrackGroups​(int periodIndex) | Deprecated.

Returns the track groups for the given period. | | Tracks | getTracks​(int periodIndex) | Deprecated.

Returns Tracks for the given period. | | List<ExoTrackSelection> | getTrackSelections​(int periodIndex, int rendererIndex) | Deprecated.

Returns all track selections for a period and renderer. | | void | prepare​(DownloadHelper.Callback callback) | Deprecated.

Initializes the helper for starting a download. | | void | release() | Deprecated.

Releases the helper and all resources it is holding. | | void | replaceTrackSelections​(int periodIndex, TrackSelectionParameters trackSelectionParameters) | Deprecated.

Replaces a selection of tracks to be downloaded. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

- 

DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT

public static final[DefaultTrackSelector.Parameters](../trackselection/DefaultTrackSelector.Parameters.html "class in com.google.android.exoplayer2.trackselection")DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT

Deprecated.

Default track selection parameters for downloading, but without any Context constraints.

If possible, use getDefaultTrackSelectorParameters(Context) instead.

See Also:DefaultTrackSelector.Parameters.DEFAULT_WITHOUT_CONTEXT

Constructor Detail

- 

DownloadHelper

public DownloadHelper​([MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem,
                      @Nullable[MediaSource](../source/MediaSource.html "interface in com.google.android.exoplayer2.source")mediaSource,[TrackSelectionParameters](../trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectionParameters,[RendererCapabilities](../RendererCapabilities.html "interface in com.google.android.exoplayer2")[] rendererCapabilities)

Deprecated.

Creates download helper. Parameters:mediaItem - The media item.mediaSource - A MediaSource for which tracks are selected, or null if no track selection needs to be made.trackSelectionParameters - TrackSelectionParameters for selecting tracks for downloading.rendererCapabilities - The RendererCapabilities of the renderers for which tracks are selected.

Method Detail

- 

getDefaultTrackSelectorParameters

public static[DefaultTrackSelector.Parameters](../trackselection/DefaultTrackSelector.Parameters.html "class in com.google.android.exoplayer2.trackselection")getDefaultTrackSelectorParameters​([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context)

Deprecated.

Returns the default parameters used for track selection for downloading.

- 

getRendererCapabilities

public static[RendererCapabilities](../RendererCapabilities.html "interface in com.google.android.exoplayer2")[] getRendererCapabilities​([RenderersFactory](../RenderersFactory.html "interface in com.google.android.exoplayer2")renderersFactory)

Deprecated.

Extracts renderer capabilities for the renderers created by the provided renderers factory. Parameters:renderersFactory - A RenderersFactory.Returns:The RendererCapabilities for each renderer created by the renderersFactory.

- 

forMediaItem

public static[DownloadHelper](DownloadHelper.html "class in com.google.android.exoplayer2.offline")forMediaItem​([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem)

Deprecated.

Creates a DownloadHelper for the given progressive media item. Parameters:context - The context.mediaItem - A MediaItem.Returns:A DownloadHelper for progressive streams.Throws:IllegalStateException - If the media item is of type DASH, HLS or SmoothStreaming.

- 

forMediaItem

public static[DownloadHelper](DownloadHelper.html "class in com.google.android.exoplayer2.offline")forMediaItem​([Context](https://developer.android.com/reference/android/content/Context.html "class or interface in android.content")context,[MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem,
                                          @Nullable[RenderersFactory](../RenderersFactory.html "interface in com.google.android.exoplayer2")renderersFactory,
                                          @Nullable[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")dataSourceFactory)

Deprecated.

Creates a DownloadHelper for the given media item. Parameters: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.Returns:A DownloadHelper.Throws:IllegalStateException - If the corresponding module is missing for DASH, HLS or SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.

- 

forMediaItem

public static[DownloadHelper](DownloadHelper.html "class in com.google.android.exoplayer2.offline")forMediaItem​([MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem,[TrackSelectionParameters](../trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectionParameters,
                                          @Nullable[RenderersFactory](../RenderersFactory.html "interface in com.google.android.exoplayer2")renderersFactory,
                                          @Nullable[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")dataSourceFactory)

Deprecated.

Creates a DownloadHelper for the given media item. Parameters:mediaItem - A MediaItem.renderersFactory - A RenderersFactory creating the renderers for which tracks are selected.trackSelectionParameters - TrackSelectionParameters 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.Returns:A DownloadHelper.Throws:IllegalStateException - If the corresponding module is missing for DASH, HLS or SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.

- 

forMediaItem

public static[DownloadHelper](DownloadHelper.html "class in com.google.android.exoplayer2.offline")forMediaItem​([MediaItem](../MediaItem.html "class in com.google.android.exoplayer2")mediaItem,[TrackSelectionParameters](../trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectionParameters,
                                          @Nullable[RenderersFactory](../RenderersFactory.html "interface in com.google.android.exoplayer2")renderersFactory,
                                          @Nullable[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")dataSourceFactory,
                                          @Nullable[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager)

Deprecated.

Creates a DownloadHelper for the given media item. Parameters:mediaItem - A MediaItem.renderersFactory - A RenderersFactory creating the renderers for which tracks are selected.trackSelectionParameters - TrackSelectionParameters 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.Returns:A DownloadHelper.Throws:IllegalStateException - If the corresponding module is missing for DASH, HLS or SmoothStreaming media items.IllegalArgumentException - If the dataSourceFactory is null for adaptive streams.

- 

createMediaSource

public static[MediaSource](../source/MediaSource.html "interface in com.google.android.exoplayer2.source")createMediaSource​([DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")downloadRequest,[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")dataSourceFactory)

Deprecated.

Equivalent to createMediaSource(downloadRequest, dataSourceFactory, null).

- 

createMediaSource

public static[MediaSource](../source/MediaSource.html "interface in com.google.android.exoplayer2.source")createMediaSource​([DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")downloadRequest,[DataSource.Factory](../upstream/DataSource.Factory.html "interface in com.google.android.exoplayer2.upstream")dataSourceFactory,
                                            @Nullable[DrmSessionManager](../drm/DrmSessionManager.html "interface in com.google.android.exoplayer2.drm")drmSessionManager)

Deprecated.

Utility method to create a MediaSource that only exposes the tracks defined in downloadRequest. Parameters:downloadRequest - A DownloadRequest.dataSourceFactory - A factory for DataSources to read the media.drmSessionManager - An optional DrmSessionManager to be passed to the MediaSource.Returns:A MediaSource that only exposes the tracks defined in downloadRequest.

- 

prepare

public void prepare​([DownloadHelper.Callback](DownloadHelper.Callback.html "interface in com.google.android.exoplayer2.offline")callback)

Deprecated.

Initializes the helper for starting a download. Parameters:callback - A callback to be notified when preparation completes or fails.Throws:IllegalStateException - If the download helper has already been prepared.

- 

release

public void release()

Deprecated.

Releases the helper and all resources it is holding.

- 

getManifest

@Nullable
public[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")getManifest()

Deprecated.

Returns the manifest, or null if no manifest is loaded. Must not be called until after preparation completes.

- 

getPeriodCount

public int getPeriodCount()

Deprecated.

Returns the number of periods for which media is available. Must not be called until after preparation completes.

- 

getTracks

public[Tracks](../Tracks.html "class in com.google.android.exoplayer2")getTracks​(int periodIndex)

Deprecated.

Returns Tracks for the given period. Must not be called until after preparation completes. Parameters:periodIndex - The period index.Returns:The Tracks for the period. May be Tracks.EMPTY for single stream content.

- 

getTrackGroups

public[TrackGroupArray](../source/TrackGroupArray.html "class in com.google.android.exoplayer2.source")getTrackGroups​(int periodIndex)

Deprecated.

Returns the track groups for the given period. Must not be called until after preparation completes.

Use getMappedTrackInfo(int) to get the track groups mapped to renderers.

Parameters:periodIndex - The period index.Returns:The track groups for the period. May be TrackGroupArray.EMPTY for single stream content.

- 

getMappedTrackInfo

public[MappingTrackSelector.MappedTrackInfo](../trackselection/MappingTrackSelector.MappedTrackInfo.html "class in com.google.android.exoplayer2.trackselection")getMappedTrackInfo​(int periodIndex)

Deprecated.

Returns the mapped track info for the given period. Must not be called until after preparation completes. Parameters:periodIndex - The period index.Returns:The MappingTrackSelector.MappedTrackInfo for the period.

- 

getTrackSelections

public[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[ExoTrackSelection](../trackselection/ExoTrackSelection.html "interface in com.google.android.exoplayer2.trackselection")> getTrackSelections​(int periodIndex,
                                                  int rendererIndex)

Deprecated.

Returns all track selections for a period and renderer. Must not be called until after preparation completes. Parameters:periodIndex - The period index.rendererIndex - The renderer index.Returns:A list of selected track selections.

- 

clearTrackSelections

public void clearTrackSelections​(int periodIndex)

Deprecated.

Clears the selection of tracks for a period. Must not be called until after preparation completes. Parameters:periodIndex - The period index for which track selections are cleared.

- 

replaceTrackSelections

public void replaceTrackSelections​(int periodIndex,[TrackSelectionParameters](../trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectionParameters)

Deprecated.

Replaces a selection of tracks to be downloaded. Must not be called until after preparation completes. Parameters:periodIndex - The period index for which the track selection is replaced.trackSelectionParameters - The TrackSelectionParameters to obtain the new selection of tracks.

- 

addTrackSelection

public void addTrackSelection​(int periodIndex,[TrackSelectionParameters](../trackselection/TrackSelectionParameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectionParameters)

Deprecated.

Adds a selection of tracks to be downloaded. Must not be called until after preparation completes. Parameters:periodIndex - The period index this track selection is added for.trackSelectionParameters - The TrackSelectionParameters to obtain the new selection of tracks.

- 

addAudioLanguagesToSelection

public void addAudioLanguagesToSelection​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")... languages)

Deprecated.

Convenience method to add selections of tracks for all specified audio languages. If an audio track in one of the specified languages is not available, the default fallback audio track is used instead. Must not be called until after preparation completes. Parameters:languages - A list of audio languages for which tracks should be added to the download selection, as IETF BCP 47 conformant tags.

- 

addTextLanguagesToSelection

public void addTextLanguagesToSelection​(boolean selectUndeterminedTextLanguage,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")... languages)

Deprecated.

Convenience method to add selections of tracks for all specified text languages. Must not be called until after preparation completes. Parameters: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.

- 

addTrackSelectionForSingleRenderer

public void addTrackSelectionForSingleRenderer​(int periodIndex,
                                               int rendererIndex,[DefaultTrackSelector.Parameters](../trackselection/DefaultTrackSelector.Parameters.html "class in com.google.android.exoplayer2.trackselection")trackSelectorParameters,[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[DefaultTrackSelector.SelectionOverride](../trackselection/DefaultTrackSelector.SelectionOverride.html "class in com.google.android.exoplayer2.trackselection")> overrides)

Deprecated.

Convenience method to add a selection of tracks to be downloaded for a single renderer. Must not be called until after preparation completes. Parameters: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.

- 

getDownloadRequest

public[DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")getDownloadRequest​(@Nullable
                                          byte[] data)

Deprecated.

Builds a 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. Parameters:data - Application provided data to store in DownloadRequest.data.Returns:The built DownloadRequest.

- 

getDownloadRequest

public[DownloadRequest](DownloadRequest.html "class in com.google.android.exoplayer2.offline")getDownloadRequest​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")id,
                                          @Nullable
                                          byte[] data)

Deprecated.

Builds a DownloadRequest for downloading the selected tracks. Must not be called until after preparation completes. Parameters:id - The unique content id.data - Application provided data to store in DownloadRequest.data.Returns:The built DownloadRequest.