Class DownloadHelper
- java.lang.Object
-
- com.google.android.exoplayer2.offline.DownloadHelper
-
@Deprecated public final class DownloadHelper extends Object
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:
- Build the helper using one of the
forMediaItem
methods. - Prepare the helper using
prepare(Callback)
and wait for the callback. - Optional: Inspect the selected tracks using
getMappedTrackInfo(int)
andgetTrackSelections(int, int)
, and make adjustments usingclearTrackSelections(int)
,replaceTrackSelections(int, TrackSelectionParameters)
andaddTrackSelection(int, TrackSelectionParameters)
. - Create a download request for the selected track using
getDownloadRequest(byte[])
. - Release the helper using
release()
.
- Build the helper using one of the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DownloadHelper.Callback
Deprecated.A callback to be notified when theDownloadHelper
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 anyContext
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 tocreateMediaSource(downloadRequest, dataSourceFactory, null)
.static MediaSource
createMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager)
Deprecated.Utility method to create aMediaSource
that only exposes the tracks defined indownloadRequest
.static DownloadHelper
forMediaItem(Context context, MediaItem mediaItem)
Deprecated.Creates aDownloadHelper
for the given progressive media item.static DownloadHelper
forMediaItem(Context context, MediaItem mediaItem, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory)
Deprecated.Creates aDownloadHelper
for the given media item.static DownloadHelper
forMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory)
Deprecated.Creates aDownloadHelper
for the given media item.static DownloadHelper
forMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager)
Deprecated.Creates aDownloadHelper
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 aDownloadRequest
for downloading the selected tracks.DownloadRequest
getDownloadRequest(String id, byte[] data)
Deprecated.Builds aDownloadRequest
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.ReturnsTracks
for the given period.List<ExoTrackSelection>
getTrackSelections(int periodIndex, int rendererIndex)
Deprecated.Returns alltrack 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.
-
-
-
Field Detail
-
DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT
public static final DefaultTrackSelector.Parameters DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT
Deprecated.Default track selection parameters for downloading, but without anyContext
constraints.If possible, use
getDefaultTrackSelectorParameters(Context)
instead.
-
-
Constructor Detail
-
DownloadHelper
public DownloadHelper(MediaItem mediaItem, @Nullable MediaSource mediaSource, TrackSelectionParameters trackSelectionParameters, RendererCapabilities[] rendererCapabilities)
Deprecated.Creates download helper.- Parameters:
mediaItem
- The media item.mediaSource
- AMediaSource
for which tracks are selected, or null if no track selection needs to be made.trackSelectionParameters
-TrackSelectionParameters
for selecting tracks for downloading.rendererCapabilities
- TheRendererCapabilities
of the renderers for which tracks are selected.
-
-
Method Detail
-
getDefaultTrackSelectorParameters
public static DefaultTrackSelector.Parameters getDefaultTrackSelectorParameters(Context context)
Deprecated.Returns the default parameters used for track selection for downloading.
-
getRendererCapabilities
public static RendererCapabilities[] getRendererCapabilities(RenderersFactory renderersFactory)
Deprecated.Extracts renderer capabilities for the renderers created by the provided renderers factory.- Parameters:
renderersFactory
- ARenderersFactory
.- Returns:
- The
RendererCapabilities
for each renderer created by therenderersFactory
.
-
forMediaItem
public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem)
Deprecated.Creates aDownloadHelper
for the given progressive media item.- Parameters:
context
- The context.mediaItem
- AMediaItem
.- Returns:
- A
DownloadHelper
for progressive streams. - Throws:
IllegalStateException
- If the media item is of type DASH, HLS or SmoothStreaming.
-
forMediaItem
public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory)
Deprecated.Creates aDownloadHelper
for the given media item.- Parameters:
context
- The context.mediaItem
- AMediaItem
.renderersFactory
- ARenderersFactory
creating the renderers for which tracks are selected.dataSourceFactory
- ADataSource.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 thedataSourceFactory
is null for adaptive streams.
-
forMediaItem
public static DownloadHelper forMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory)
Deprecated.Creates aDownloadHelper
for the given media item.- Parameters:
mediaItem
- AMediaItem
.renderersFactory
- ARenderersFactory
creating the renderers for which tracks are selected.trackSelectionParameters
-TrackSelectionParameters
for selecting tracks for downloading.dataSourceFactory
- ADataSource.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 thedataSourceFactory
is null for adaptive streams.
-
forMediaItem
public static DownloadHelper forMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory, @Nullable DrmSessionManager drmSessionManager)
Deprecated.Creates aDownloadHelper
for the given media item.- Parameters:
mediaItem
- AMediaItem
.renderersFactory
- ARenderersFactory
creating the renderers for which tracks are selected.trackSelectionParameters
-TrackSelectionParameters
for selecting tracks for downloading.dataSourceFactory
- ADataSource.Factory
used to load the manifest for adaptive streams. This argument is required for adaptive streams and ignored for progressive streams.drmSessionManager
- An optionalDrmSessionManager
. 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 thedataSourceFactory
is null for adaptive streams.
-
createMediaSource
public static MediaSource createMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory)
Deprecated.Equivalent tocreateMediaSource(downloadRequest, dataSourceFactory, null)
.
-
createMediaSource
public static MediaSource createMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory, @Nullable DrmSessionManager drmSessionManager)
Deprecated.Utility method to create aMediaSource
that only exposes the tracks defined indownloadRequest
.- Parameters:
downloadRequest
- ADownloadRequest
.dataSourceFactory
- A factory forDataSource
s to read the media.drmSessionManager
- An optionalDrmSessionManager
to be passed to theMediaSource
.- Returns:
- A
MediaSource
that only exposes the tracks defined indownloadRequest
.
-
prepare
public void prepare(DownloadHelper.Callback 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 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 getTracks(int periodIndex)
Deprecated.ReturnsTracks
for the given period. Must not be called until after preparation completes.- Parameters:
periodIndex
- The period index.- Returns:
- The
Tracks
for the period. May beTracks.EMPTY
for single stream content.
-
getTrackGroups
public TrackGroupArray 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 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<ExoTrackSelection> getTrackSelections(int periodIndex, int rendererIndex)
Deprecated.Returns alltrack 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 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
- TheTrackSelectionParameters
to obtain the new selection of tracks.
-
addTrackSelection
public void addTrackSelection(int periodIndex, TrackSelectionParameters 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
- TheTrackSelectionParameters
to obtain the new selection of tracks.
-
addAudioLanguagesToSelection
public void addAudioLanguagesToSelection(String... 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... 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 specifiedlanguages
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 trackSelectorParameters, List<DefaultTrackSelector.SelectionOverride> 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
- TheDefaultTrackSelector.Parameters
to obtain the new selection of tracks.overrides
- A list ofSelectionOverrides
to apply to thetrackSelectorParameters
. If empty,trackSelectorParameters
are used as they are.
-
getDownloadRequest
public DownloadRequest getDownloadRequest(@Nullable byte[] data)
Deprecated.Builds aDownloadRequest
for downloading the selected tracks. Must not be called until after preparation completes. The uri of theDownloadRequest
will be used as content id.- Parameters:
data
- Application provided data to store inDownloadRequest.data
.- Returns:
- The built
DownloadRequest
.
-
getDownloadRequest
public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data)
Deprecated.Builds aDownloadRequest
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 inDownloadRequest.data
.- Returns:
- The built
DownloadRequest
.
-
-