ExoTrackSelection, TrackSelectionAdaptiveTrackSelection, FixedTrackSelection, RandomTrackSelectionpublic abstract class BaseTrackSelection extends Object implements ExoTrackSelection
ExoTrackSelection implementations.ExoTrackSelection.Definition, ExoTrackSelection.Factory| Modifier and Type | Field | Description |
|---|---|---|
protected TrackGroup |
group |
The selected
TrackGroup. |
protected int |
length |
The number of selected tracks within the
TrackGroup. |
protected int[] |
tracks |
The indices of the selected tracks in
group, in order of decreasing bandwidth. |
| Constructor | Description |
|---|---|
BaseTrackSelection(TrackGroup group,
int... tracks) |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
blacklist(int index,
long exclusionDurationMs) |
Attempts to exclude the track at the specified index in the selection, making it ineligible for
selection by calls to
ExoTrackSelection.updateSelectedTrack(long, long, long, List,
MediaChunkIterator[]) for the specified period of time. |
void |
disable() |
Disables this track selection.
|
void |
enable() |
Enables the track selection.
|
boolean |
equals(Object obj) |
|
int |
evaluateQueueSize(long playbackPositionUs,
List<? extends MediaChunk> queue) |
Returns the number of chunks that should be retained in the queue.
|
Format |
getFormat(int index) |
Returns the format of the track at a given index in the selection.
|
int |
getIndexInTrackGroup(int index) |
Returns the index in the track group of the track at a given index in the selection.
|
Format |
getSelectedFormat() |
Returns the
Format of the individual selected track. |
int |
getSelectedIndexInTrackGroup() |
Returns the index in the track group of the individual selected track.
|
TrackGroup |
getTrackGroup() |
Returns the
TrackGroup to which the selected tracks belong. |
int |
hashCode() |
|
int |
indexOf(int indexInTrackGroup) |
Returns the index in the selection of the track with the specified index in the track group.
|
int |
indexOf(Format format) |
Returns the index in the selection of the track with the specified format.
|
protected boolean |
isBlacklisted(int index,
long nowMs) |
Returns whether the track at the specified index in the selection is excluded.
|
int |
length() |
Returns the number of tracks in the selection.
|
void |
onPlaybackSpeed(float playbackSpeed) |
Called to notify the selection of the current playback speed.
|
getSelectedIndex, getSelectionData, getSelectionReason, onDiscontinuity, onPlayWhenReadyChanged, onRebuffer, shouldCancelChunkLoad, updateSelectedTrackprotected final TrackGroup group
TrackGroup.protected final int length
TrackGroup. Always greater than zero.protected final int[] tracks
group, in order of decreasing bandwidth.public BaseTrackSelection(TrackGroup group, int... tracks)
group - The TrackGroup. Must not be null.tracks - The indices of the selected tracks within the TrackGroup. Must not be
null or empty. May be in any order.public void enable()
ExoTrackSelectionExoTrackSelection.updateSelectedTrack(long, long, long,
List, MediaChunkIterator[]), ExoTrackSelection.evaluateQueueSize(long, List) or ExoTrackSelection.shouldCancelChunkLoad(long, Chunk, List) will only happen after this call.
This method may not be called when the track selection is already enabled.
enable in interface ExoTrackSelectionpublic void disable()
ExoTrackSelectionExoTrackSelection.updateSelectedTrack(long,
long, long, List, MediaChunkIterator[]), ExoTrackSelection.evaluateQueueSize(long, List) or ExoTrackSelection.shouldCancelChunkLoad(long, Chunk, List) will happen after this call.
This method may only be called when the track selection is already enabled.
disable in interface ExoTrackSelectionpublic final TrackGroup getTrackGroup()
TrackSelectionTrackGroup to which the selected tracks belong.getTrackGroup in interface TrackSelectionpublic final int length()
TrackSelectionlength in interface TrackSelectionpublic final Format getFormat(int index)
TrackSelectiongetFormat in interface TrackSelectionindex - The index in the selection.public final int getIndexInTrackGroup(int index)
TrackSelectiongetIndexInTrackGroup in interface TrackSelectionindex - The index in the selection.public final int indexOf(Format format)
TrackSelectionselection.indexOf(selection.getFormat(index)) ==
index even if multiple selected tracks have formats that contain the same values.indexOf in interface TrackSelectionformat - The format.C.INDEX_UNSET if the track with the specified
format is not part of the selection.public final int indexOf(int indexInTrackGroup)
TrackSelectionindexOf in interface TrackSelectionindexInTrackGroup - The index in the track group.C.INDEX_UNSET if the track with the specified
index is not part of the selection.public final Format getSelectedFormat()
ExoTrackSelectionFormat of the individual selected track.getSelectedFormat in interface ExoTrackSelectionpublic final int getSelectedIndexInTrackGroup()
ExoTrackSelectiongetSelectedIndexInTrackGroup in interface ExoTrackSelectionpublic void onPlaybackSpeed(float playbackSpeed)
ExoTrackSelectiononPlaybackSpeed in interface ExoTrackSelectionplaybackSpeed - The factor by which playback is sped up.public int evaluateQueueSize(long playbackPositionUs,
List<? extends MediaChunk> queue)
ExoTrackSelectionMay be called by sources that load media in discrete MediaChunks and
support discarding of buffered chunks.
To avoid excessive re-buffering, implementations should normally return the size of the queue. An example of a case where a smaller value may be returned is if network conditions have improved dramatically, allowing chunks to be discarded and re-buffered in a track of significantly higher quality. Discarding chunks may allow faster switching to a higher quality track in this case.
Note that even if the source supports discarding of buffered chunks, the actual number of
discarded chunks is not guaranteed. The source will call ExoTrackSelection.updateSelectedTrack(long,
long, long, List, MediaChunkIterator[]) with the updated queue of chunks before loading a new
chunk to allow switching to another quality.
This method will only be called when the selection is enabled and none of the MediaChunks in the queue are currently loading.
evaluateQueueSize in interface ExoTrackSelectionplaybackPositionUs - The current playback position in microseconds. If playback of the
period to which this track selection belongs has not yet started, the value will be the
starting position in the period minus the duration of any media in previous periods still
to be played.queue - The queue of buffered MediaChunks. Must not be modified.public final boolean blacklist(int index,
long exclusionDurationMs)
ExoTrackSelectionExoTrackSelection.updateSelectedTrack(long, long, long, List,
MediaChunkIterator[]) for the specified period of time.
Exclusion will fail if all other tracks are currently excluded. If excluding the currently
selected track, note that it will remain selected until the next call to ExoTrackSelection.updateSelectedTrack(long, long, long, List, MediaChunkIterator[]).
This method will only be called when the selection is enabled.
blacklist in interface ExoTrackSelectionindex - The index of the track in the selection.exclusionDurationMs - The duration of time for which the track should be excluded, in
milliseconds.protected final boolean isBlacklisted(int index,
long nowMs)
index - The index of the track in the selection.nowMs - The current time in the timebase of SystemClock.elapsedRealtime().