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 requestsbased on the selected tracks.A typical usage of DownloadHelper follows these steps:
- Build the helper using one of the
forMediaItemmethods. - 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 interfaceDownloadHelper.CallbackDeprecated.A callback to be notified when theDownloadHelperis prepared.static classDownloadHelper.LiveContentUnsupportedExceptionDeprecated.Thrown at an attempt to download live content.
-
Field Summary
Fields Modifier and Type Field Description static DefaultTrackSelector.ParametersDEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXTDeprecated.Default track selection parameters for downloading, but without anyContextconstraints.
-
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 voidaddAudioLanguagesToSelection(String... languages)Deprecated.Convenience method to add selections of tracks for all specified audio languages.voidaddTextLanguagesToSelection(boolean selectUndeterminedTextLanguage, String... languages)Deprecated.Convenience method to add selections of tracks for all specified text languages.voidaddTrackSelection(int periodIndex, TrackSelectionParameters trackSelectionParameters)Deprecated.Adds a selection of tracks to be downloaded.voidaddTrackSelectionForSingleRenderer(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.voidclearTrackSelections(int periodIndex)Deprecated.Clears the selection of tracks for a period.static MediaSourcecreateMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory)Deprecated.Equivalent tocreateMediaSource(downloadRequest, dataSourceFactory, null).static MediaSourcecreateMediaSource(DownloadRequest downloadRequest, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager)Deprecated.Utility method to create aMediaSourcethat only exposes the tracks defined indownloadRequest.static DownloadHelperforMediaItem(Context context, MediaItem mediaItem)Deprecated.Creates aDownloadHelperfor the given progressive media item.static DownloadHelperforMediaItem(Context context, MediaItem mediaItem, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory)Deprecated.Creates aDownloadHelperfor the given media item.static DownloadHelperforMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory)Deprecated.Creates aDownloadHelperfor the given media item.static DownloadHelperforMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, RenderersFactory renderersFactory, DataSource.Factory dataSourceFactory, DrmSessionManager drmSessionManager)Deprecated.Creates aDownloadHelperfor the given media item.static DefaultTrackSelector.ParametersgetDefaultTrackSelectorParameters(Context context)Deprecated.Returns the default parameters used for track selection for downloading.DownloadRequestgetDownloadRequest(byte[] data)Deprecated.Builds aDownloadRequestfor downloading the selected tracks.DownloadRequestgetDownloadRequest(String id, byte[] data)Deprecated.Builds aDownloadRequestfor downloading the selected tracks.ObjectgetManifest()Deprecated.Returns the manifest, or null if no manifest is loaded.MappingTrackSelector.MappedTrackInfogetMappedTrackInfo(int periodIndex)Deprecated.Returns the mapped track info for the given period.intgetPeriodCount()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.TrackGroupArraygetTrackGroups(int periodIndex)Deprecated.Returns the track groups for the given period.TracksgetTracks(int periodIndex)Deprecated.ReturnsTracksfor the given period.List<ExoTrackSelection>getTrackSelections(int periodIndex, int rendererIndex)Deprecated.Returns alltrack selectionsfor a period and renderer.voidprepare(DownloadHelper.Callback callback)Deprecated.Initializes the helper for starting a download.voidrelease()Deprecated.Releases the helper and all resources it is holding.voidreplaceTrackSelections(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 anyContextconstraints.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- AMediaSourcefor which tracks are selected, or null if no track selection needs to be made.trackSelectionParameters-TrackSelectionParametersfor selecting tracks for downloading.rendererCapabilities- TheRendererCapabilitiesof 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
RendererCapabilitiesfor each renderer created by therenderersFactory.
-
forMediaItem
public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem)
Deprecated.Creates aDownloadHelperfor the given progressive media item.- Parameters:
context- The context.mediaItem- AMediaItem.- Returns:
- A
DownloadHelperfor 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 aDownloadHelperfor the given media item.- Parameters:
context- The context.mediaItem- AMediaItem.renderersFactory- ARenderersFactorycreating the renderers for which tracks are selected.dataSourceFactory- ADataSource.Factoryused 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 thedataSourceFactoryis null for adaptive streams.
-
forMediaItem
public static DownloadHelper forMediaItem(MediaItem mediaItem, TrackSelectionParameters trackSelectionParameters, @Nullable RenderersFactory renderersFactory, @Nullable DataSource.Factory dataSourceFactory)
Deprecated.Creates aDownloadHelperfor the given media item.- Parameters:
mediaItem- AMediaItem.renderersFactory- ARenderersFactorycreating the renderers for which tracks are selected.trackSelectionParameters-TrackSelectionParametersfor selecting tracks for downloading.dataSourceFactory- ADataSource.Factoryused 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 thedataSourceFactoryis 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 aDownloadHelperfor the given media item.- Parameters:
mediaItem- AMediaItem.renderersFactory- ARenderersFactorycreating the renderers for which tracks are selected.trackSelectionParameters-TrackSelectionParametersfor selecting tracks for downloading.dataSourceFactory- ADataSource.Factoryused 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 thedataSourceFactoryis 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 aMediaSourcethat only exposes the tracks defined indownloadRequest.- Parameters:
downloadRequest- ADownloadRequest.dataSourceFactory- A factory forDataSources to read the media.drmSessionManager- An optionalDrmSessionManagerto be passed to theMediaSource.- Returns:
- A
MediaSourcethat 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.ReturnsTracksfor the given period. Must not be called until after preparation completes.- Parameters:
periodIndex- The period index.- Returns:
- The
Tracksfor the period. May beTracks.EMPTYfor 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.EMPTYfor 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.MappedTrackInfofor the period.
-
getTrackSelections
public List<ExoTrackSelection> getTrackSelections(int periodIndex, int rendererIndex)
Deprecated.Returns alltrack selectionsfor 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- TheTrackSelectionParametersto 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- TheTrackSelectionParametersto 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 specifiedlanguagesis 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.Parametersto obtain the new selection of tracks.overrides- A list ofSelectionOverridesto apply to thetrackSelectorParameters. If empty,trackSelectorParametersare used as they are.
-
getDownloadRequest
public DownloadRequest getDownloadRequest(@Nullable byte[] data)
Deprecated.Builds aDownloadRequestfor downloading the selected tracks. Must not be called until after preparation completes. The uri of theDownloadRequestwill 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 aDownloadRequestfor 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.
-
-