DownloadHelper
@UnstableApi
class DownloadHelper
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
forMediaItemmethods. - Prepare the helper using
prepareand wait for the callback. - Optional: Inspect the selected tracks using
getMappedTrackInfoandgetTrackSelections, and make adjustments usingclearTrackSelections,replaceTrackSelectionsandaddTrackSelection. - Create a download request for the selected track using
getDownloadRequest. - Release the helper using
release.
Summary
Nested types |
|---|
interface DownloadHelper.CallbackA callback to be notified when the |
class DownloadHelper.FactoryA factory of |
|
Thrown at an attempt to download live content. |
Constants |
|
|---|---|
const DefaultTrackSelector.Parameters! |
Default track selection parameters for downloading. |
const DefaultTrackSelector.Parameters! |
This property is deprecated. Use |
Public constructors |
|---|
DownloadHelper(Creates download helper. |
DownloadHelper(Creates download helper. |
Public functions |
|
|---|---|
Unit |
addAudioLanguagesToSelection(languages: Array<String!>!)Convenience method to add selections of tracks for all specified audio languages. |
Unit |
addTextLanguagesToSelection(Convenience method to add selections of tracks for all specified text languages. |
Unit |
addTrackSelection(Adds a selection of tracks to be downloaded. |
Unit |
addTrackSelectionForSingleRenderer(Convenience method to add a selection of tracks to be downloaded for a single renderer. |
Unit |
clearTrackSelections(periodIndex: Int)Clears the selection of tracks for a period. |
java-static MediaSource! |
createMediaSource(Equivalent to |
java-static MediaSource! |
createMediaSource(Utility method to create a |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DownloadHelper! |
This function is deprecated. Use |
java-static DefaultTrackSelector.Parameters! |
This function is deprecated. Use |
DownloadRequest! |
getDownloadRequest(data: ByteArray?)Builds a |
DownloadRequest! |
getDownloadRequest(id: String!, data: ByteArray?)Builds a |
DownloadRequest! |
getDownloadRequest(Builds a |
DownloadRequest! |
getDownloadRequest(Builds a |
Any? |
Returns the manifest, or null if no manifest is loaded. |
MappingTrackSelector.MappedTrackInfo! |
getMappedTrackInfo(periodIndex: Int)Returns the mapped track info for the given period. |
Int |
Returns the number of periods for which media is available. |
TrackGroupArray! |
getTrackGroups(periodIndex: Int)Returns the track groups for the given period. |
(Mutable)List<ExoTrackSelection!>! |
getTrackSelections(periodIndex: Int, rendererIndex: Int)Returns all |
Tracks! |
Returns |
Unit |
prepare(callback: DownloadHelper.Callback!)Initializes the helper for starting a download. |
Unit |
release()Releases the helper and all resources it is holding. |
Unit |
replaceTrackSelections(Replaces a selection of tracks to be downloaded. |
Constants
DEFAULT_TRACK_SELECTOR_PARAMETERS
const val DEFAULT_TRACK_SELECTOR_PARAMETERS: DefaultTrackSelector.Parameters!
Default track selection parameters for downloading.
DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT
const val DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT: DefaultTrackSelector.Parameters!
Public constructors
DownloadHelper
DownloadHelper(
mediaItem: MediaItem!,
mediaSource: MediaSource?,
trackSelectionParameters: TrackSelectionParameters!,
rendererCapabilities: RendererCapabilitiesList!
)
Creates download helper.
| Parameters | |
|---|---|
mediaItem: MediaItem! |
The media item. |
mediaSource: MediaSource? |
A |
trackSelectionParameters: TrackSelectionParameters! |
|
rendererCapabilities: RendererCapabilitiesList! |
The |
DownloadHelper
DownloadHelper(
mediaItem: MediaItem!,
mediaSource: MediaSource?,
trackSelectionParameters: TrackSelectionParameters!,
rendererCapabilities: RendererCapabilitiesList!,
debugLoggingEnabled: Boolean
)
Creates download helper.
| Parameters | |
|---|---|
mediaItem: MediaItem! |
The media item. |
mediaSource: MediaSource? |
A |
trackSelectionParameters: TrackSelectionParameters! |
|
rendererCapabilities: RendererCapabilitiesList! |
The |
debugLoggingEnabled: Boolean |
Whether to log debug information. |
Public functions
addAudioLanguagesToSelection
fun addAudioLanguagesToSelection(languages: Array<String!>!): Unit
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 onPrepared is triggered and the passed tracksInfoAvailable is true.
addTextLanguagesToSelection
fun addTextLanguagesToSelection(
selectUndeterminedTextLanguage: Boolean,
languages: Array<String!>!
): Unit
Convenience method to add selections of tracks for all specified text languages. Must not be called until onPrepared is triggered and the passed tracksInfoAvailable is true.
| Parameters | |
|---|---|
selectUndeterminedTextLanguage: Boolean |
Whether a text track with undetermined language should be selected for downloading if no track with one of the specified |
languages: Array<String!>! |
A list of text languages for which tracks should be added to the download selection, as IETF BCP 47 conformant tags. |
addTrackSelection
fun addTrackSelection(
periodIndex: Int,
trackSelectionParameters: TrackSelectionParameters!
): Unit
Adds a selection of tracks to be downloaded. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index this track selection is added for. |
trackSelectionParameters: TrackSelectionParameters! |
The |
addTrackSelectionForSingleRenderer
fun addTrackSelectionForSingleRenderer(
periodIndex: Int,
rendererIndex: Int,
trackSelectorParameters: DefaultTrackSelector.Parameters!,
overrides: (Mutable)List<DefaultTrackSelector.SelectionOverride!>!
): Unit
Convenience method to add a selection of tracks to be downloaded for a single renderer. Must not be called until onPrepared is triggered and the passed tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index the track selection is added for. |
rendererIndex: Int |
The renderer index the track selection is added for. |
trackSelectorParameters: DefaultTrackSelector.Parameters! |
The |
overrides: (Mutable)List<DefaultTrackSelector.SelectionOverride!>! |
A list of |
clearTrackSelections
fun clearTrackSelections(periodIndex: Int): Unit
Clears the selection of tracks for a period. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index for which track selections are cleared. |
createMediaSource
java-static fun createMediaSource(
downloadRequest: DownloadRequest!,
dataSourceFactory: DataSource.Factory!
): MediaSource!
Equivalent to createMediaSource(downloadRequest, dataSourceFactory, null).
createMediaSource
java-static fun createMediaSource(
downloadRequest: DownloadRequest!,
dataSourceFactory: DataSource.Factory!,
drmSessionManager: DrmSessionManager?
): MediaSource!
Utility method to create a MediaSource that only exposes the tracks defined in
downloadRequest.
| Parameters | |
|---|---|
downloadRequest: DownloadRequest! |
|
dataSourceFactory: DataSource.Factory! |
A factory for |
drmSessionManager: DrmSessionManager? |
An optional |
| Returns | |
|---|---|
MediaSource! |
A |
forMediaItem
java-static funforMediaItem(context: Context!, mediaItem: MediaItem!): DownloadHelper!
forMediaItem
java-static funforMediaItem(
context: Context!,
mediaItem: MediaItem!,
dataSourceFactory: DataSource.Factory!
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
context: Context!,
mediaItem: MediaItem!,
dataSourceFactory: DataSource.Factory!,
debugLoggingEnabled: Boolean
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
context: Context!,
mediaItem: MediaItem!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
mediaItem: MediaItem!,
trackSelectionParameters: TrackSelectionParameters!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
context: Context!,
mediaItem: MediaItem!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?,
debugLoggingEnabled: Boolean
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
mediaItem: MediaItem!,
trackSelectionParameters: TrackSelectionParameters!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?,
debugLoggingEnabled: Boolean
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
mediaItem: MediaItem!,
trackSelectionParameters: TrackSelectionParameters!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?,
drmSessionManager: DrmSessionManager?
): DownloadHelper!
forMediaItem
java-static funforMediaItem(
mediaItem: MediaItem!,
trackSelectionParameters: TrackSelectionParameters!,
renderersFactory: RenderersFactory?,
dataSourceFactory: DataSource.Factory?,
drmSessionManager: DrmSessionManager?,
debugLoggingEnabled: Boolean
): DownloadHelper!
getDefaultTrackSelectorParameters
java-static fungetDefaultTrackSelectorParameters(context: Context!): DefaultTrackSelector.Parameters!
getDownloadRequest
fun getDownloadRequest(data: ByteArray?): DownloadRequest!
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.
getDownloadRequest
fun getDownloadRequest(id: String!, data: ByteArray?): DownloadRequest!
Builds a DownloadRequest for downloading the selected tracks. Must not be called until after preparation completes.
getDownloadRequest
fun getDownloadRequest(
data: ByteArray?,
startPositionMs: Long,
durationMs: Long
): DownloadRequest!
Builds a DownloadRequest for downloading the selected tracks and time range. Must not be called until preparation completes.
This method is only supported for progressive streams.
| Parameters | |
|---|---|
data: ByteArray? |
Application provided data to store in |
startPositionMs: Long |
The start position (in milliseconds) of the media that download should cover from, or |
durationMs: Long |
The end position (in milliseconds) of the media that download should cover to, or |
getDownloadRequest
fun getDownloadRequest(
id: String!,
data: ByteArray?,
startPositionMs: Long,
durationMs: Long
): DownloadRequest!
Builds a DownloadRequest for downloading the selected tracks and time range. Must not be called until preparation completes.
This method is only supported for progressive streams.
| Parameters | |
|---|---|
id: String! |
The unique content id. |
data: ByteArray? |
Application provided data to store in |
startPositionMs: Long |
The start position (in milliseconds) of the media that download should cover from, or |
durationMs: Long |
The duration (in milliseconds) of the media that download should cover, or |
getManifest
fun getManifest(): Any?
Returns the manifest, or null if no manifest is loaded. Must not be called until onPrepared is triggered.
getMappedTrackInfo
fun getMappedTrackInfo(periodIndex: Int): MappingTrackSelector.MappedTrackInfo!
Returns the mapped track info for the given period. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index. |
| Returns | |
|---|---|
MappingTrackSelector.MappedTrackInfo! |
The |
getPeriodCount
fun getPeriodCount(): Int
Returns the number of periods for which media is available. Must not be called until onPrepared is triggered.
getTrackGroups
fun getTrackGroups(periodIndex: Int): TrackGroupArray!
Returns the track groups for the given period. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
Use getMappedTrackInfo to get the track groups mapped to renderers.
| Parameters | |
|---|---|
periodIndex: Int |
The period index. |
| Returns | |
|---|---|
TrackGroupArray! |
The track groups for the period. May be |
getTrackSelections
fun getTrackSelections(periodIndex: Int, rendererIndex: Int): (Mutable)List<ExoTrackSelection!>!
Returns all track selections for a period and renderer. Must not be called until onPrepared is triggered and the passed tracksInfoAvailable is true.
| Returns | |
|---|---|
(Mutable)List<ExoTrackSelection!>! |
A list of selected |
getTracks
fun getTracks(periodIndex: Int): Tracks!
Returns Tracks for the given period. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index. |
prepare
fun prepare(callback: DownloadHelper.Callback!): Unit
Initializes the helper for starting a download.
| Parameters | |
|---|---|
callback: DownloadHelper.Callback! |
A callback to be notified when preparation completes or fails. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the download helper has already been prepared. |
replaceTrackSelections
fun replaceTrackSelections(
periodIndex: Int,
trackSelectionParameters: TrackSelectionParameters!
): Unit
Replaces a selection of tracks to be downloaded. Must not be called until onPrepared is triggered and the passed
tracksInfoAvailable is true.
| Parameters | |
|---|---|
periodIndex: Int |
The period index for which the track selection is replaced. |
trackSelectionParameters: TrackSelectionParameters! |
The |