BaseTrackSelection
@UnstableApi
public abstract class BaseTrackSelection implements ExoTrackSelection
AdaptiveTrackSelection |
A bandwidth based adaptive |
FakeTrackSelection |
A fake |
FixedTrackSelection |
A |
RandomTrackSelection |
An |
An abstract base class suitable for most ExoTrackSelection
implementations.
Summary
Public fields |
|
---|---|
final int |
The type of the selection. |
Protected fields |
|
---|---|
final TrackGroup |
The selected |
final int |
The number of selected tracks within the |
boolean |
The current value of whether playback will proceed when ready. |
final int[] |
The indices of the selected tracks in |
Public constructors |
---|
BaseTrackSelection(TrackGroup group, int[] tracks) |
BaseTrackSelection( |
Public methods |
|
---|---|
void |
disable() Disables this track selection. |
void |
enable() Enables the track selection. |
boolean |
|
int |
evaluateQueueSize(long playbackPositionUs, List<MediaChunk> queue) Returns the number of chunks that should be retained in the queue. |
boolean |
excludeTrack(int index, long exclusionDurationMs) Attempts to exclude the track at the specified index in the selection, making it ineligible for selection by calls to |
final Format |
getFormat(int index) Returns the format of the track at a given index in the selection. |
final int |
getIndexInTrackGroup(int index) Returns the index in the track group of the track at a given index in the selection. |
final Format |
Returns the |
final int |
Returns the index in the track group of the individual selected track. |
final TrackGroup |
Returns the |
final int |
getType() Returns an integer specifying the type of the selection, or |
int |
hashCode() |
final int |
Returns the index in the selection of the track with the specified format. |
final int |
indexOf(int indexInTrackGroup) Returns the index in the selection of the track with the specified index in the track group. |
boolean |
isTrackExcluded(int index, long nowMs) Returns whether the track at the specified index in the selection is excluded. |
final int |
length() Returns the number of tracks in the selection. |
void |
@CallSuper Called to notify when the playback is paused or resumed. |
void |
onPlaybackSpeed(float playbackSpeed) Called to notify the selection of the current playback speed. |
Protected methods |
|
---|---|
final boolean |
Returns whether the playback using this track selection will proceed when ready. |
Inherited Constants |
||||
---|---|---|---|---|
|
Inherited methods |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public fields
Protected fields
length
protected final int length
The number of selected tracks within the TrackGroup
. Always greater than zero.
playWhenReady
protected boolean playWhenReady
The current value of whether playback will proceed when ready.
Public constructors
BaseTrackSelection
public BaseTrackSelection(TrackGroup group, int[] tracks)
Parameters | |
---|---|
TrackGroup group |
The |
int[] tracks |
The indices of the selected tracks within the |
BaseTrackSelection
public BaseTrackSelection(
TrackGroup group,
int[] tracks,
@TrackSelection.Type int type
)
Parameters | |
---|---|
TrackGroup group |
The |
int[] tracks |
The indices of the selected tracks within the |
@TrackSelection.Type int type |
The type that will be returned from |
Public methods
disable
public void disable()
Disables this track selection. No further dynamic changes via updateSelectedTrack
, evaluateQueueSize
or shouldCancelChunkLoad
will happen after this call.
This method may only be called when the track selection is already enabled.
enable
public void enable()
Enables the track selection. Dynamic changes via updateSelectedTrack
, evaluateQueueSize
or shouldCancelChunkLoad
will only happen after this call.
This method may not be called when the track selection is already enabled.
evaluateQueueSize
public int evaluateQueueSize(long playbackPositionUs, List<MediaChunk> queue)
Returns the number of chunks that should be retained in the queue.
May 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 updateSelectedTrack
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.
Parameters | |
---|---|
long playbackPositionUs |
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. |
List<MediaChunk> queue |
The queue of buffered |
Returns | |
---|---|
int |
The number of chunks to retain in the queue. |
excludeTrack
public boolean excludeTrack(int index, long exclusionDurationMs)
Attempts to exclude the track at the specified index in the selection, making it ineligible for selection by calls to updateSelectedTrack
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 updateSelectedTrack
.
This method will only be called when the selection is enabled.
Parameters | |
---|---|
int index |
The index of the track in the selection. |
long exclusionDurationMs |
The duration of time for which the track should be excluded, in milliseconds. |
Returns | |
---|---|
boolean |
Whether exclusion was successful. |
getFormat
public final Format getFormat(int index)
Returns the format of the track at a given index in the selection.
Parameters | |
---|---|
int index |
The index in the selection. |
Returns | |
---|---|
Format |
The format of the selected track. |
getIndexInTrackGroup
public final int getIndexInTrackGroup(int index)
Returns the index in the track group of the track at a given index in the selection.
Parameters | |
---|---|
int index |
The index in the selection. |
Returns | |
---|---|
int |
The index of the selected track. |
getSelectedFormat
public final Format getSelectedFormat()
Returns the Format
of the individual selected track.
getSelectedIndexInTrackGroup
public final int getSelectedIndexInTrackGroup()
Returns the index in the track group of the individual selected track.
getTrackGroup
public final TrackGroup getTrackGroup()
Returns the TrackGroup
to which the selected tracks belong.
getType
public final int getType()
Returns an integer specifying the type of the selection, or TYPE_UNSET
if not specified.
Track selection types are specific to individual applications, but should be defined starting from TYPE_CUSTOM_BASE
to ensure they don't conflict with any types that may be added to the library in the future.
indexOf
public final int indexOf(Format format)
Returns the index in the selection of the track with the specified format. The format is located by identity so, for example, selection.indexOf(selection.getFormat(index)) ==
index
even if multiple selected tracks have formats that contain the same values.
Parameters | |
---|---|
Format format |
The format. |
Returns | |
---|---|
int |
The index in the selection, or |
indexOf
public final int indexOf(int indexInTrackGroup)
Returns the index in the selection of the track with the specified index in the track group.
Parameters | |
---|---|
int indexInTrackGroup |
The index in the track group. |
Returns | |
---|---|
int |
The index in the selection, or |
isTrackExcluded
public boolean isTrackExcluded(int index, long nowMs)
Returns whether the track at the specified index in the selection is excluded.
Parameters | |
---|---|
int index |
The index of the track in the selection. |
long nowMs |
The current time in the timebase of |
onPlayWhenReadyChanged
@CallSuper
public void onPlayWhenReadyChanged(boolean playWhenReady)
Called to notify when the playback is paused or resumed.
Parameters | |
---|---|
boolean playWhenReady |
Whether playback will proceed when ready. |
onPlaybackSpeed
public void onPlaybackSpeed(float playbackSpeed)
Called to notify the selection of the current playback speed. The playback speed may affect adaptive track selection.
Parameters | |
---|---|
float playbackSpeed |
The factor by which playback is sped up. |
Protected methods
getPlayWhenReady
protected final boolean getPlayWhenReady()
Returns whether the playback using this track selection will proceed when ready.