BaseTrackSelection


@UnstableApi
abstract class BaseTrackSelection : ExoTrackSelection

Known direct subclasses
AdaptiveTrackSelection

A bandwidth based adaptive ExoTrackSelection, whose selected track is updated to be the one of highest quality given the current network conditions and the state of the buffer.

FixedTrackSelection

A TrackSelection consisting of a single track.

RandomTrackSelection

An ExoTrackSelection whose selected track is updated randomly.


An abstract base class suitable for most ExoTrackSelection implementations.

Summary

Public constructors

BaseTrackSelection(group: TrackGroup!, tracks: IntArray!)
BaseTrackSelection(
    group: TrackGroup!,
    tracks: IntArray!,
    @TrackSelection.Type type: Int
)

Public functions

Unit

Disables this track selection.

Unit

Enables the track selection.

Boolean
equals(obj: Any?)
Int
evaluateQueueSize(
    playbackPositionUs: Long,
    queue: (Mutable)List<MediaChunk!>!
)

Returns the number of chunks that should be retained in the queue.

Boolean
excludeTrack(index: Int, exclusionDurationMs: Long)

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.

Format!
getFormat(index: Int)

Returns the format of the track at a given index in the selection.

Int

Returns the index in the track group of the track at a given index in the selection.

Format!

Returns the Format of the individual selected track.

Int

Returns the index in the track group of the individual selected track.

TrackGroup!

Returns the TrackGroup to which the selected tracks belong.

Int
Int
indexOf(format: Format!)

Returns the index in the selection of the track with the specified format.

Int
indexOf(indexInTrackGroup: Int)

Returns the index in the selection of the track with the specified index in the track group.

Boolean
isTrackExcluded(index: Int, nowMs: Long)

Returns whether the track at the specified index in the selection is excluded.

Int

Returns the number of tracks in the selection.

Unit
onPlaybackSpeed(playbackSpeed: Float)

Called to notify the selection of the current playback speed.

Public properties

Int

The type of the selection.

Protected properties

TrackGroup!

The selected TrackGroup.

Int

The number of selected tracks within the TrackGroup.

IntArray<Int>!

The indices of the selected tracks in group, in order of decreasing bandwidth.

Inherited Constants

From androidx.media3.exoplayer.trackselection.TrackSelection
const Int

The first value that can be used for application specific track selection types.

const Int

An unspecified track selection type.

Inherited functions

From androidx.media3.exoplayer.trackselection.ExoTrackSelection
Long

Returns the most recent bitrate estimate utilised for track selection.

abstract Int

Returns the index of the selected track.

abstract Any?

Returns optional data associated with the current track selection.

abstract Int

Returns the reason for the current track selection.

Unit

Called to notify the selection of a position discontinuity.

Unit

Called to notify when the playback is paused or resumed.

Unit

Called to notify when a rebuffer occurred.

Boolean
shouldCancelChunkLoad(
    playbackPositionUs: Long,
    loadingChunk: Chunk!,
    queue: (Mutable)List<MediaChunk!>!
)

Returns whether an ongoing load of a chunk should be canceled.

abstract Unit
updateSelectedTrack(
    playbackPositionUs: Long,
    bufferedDurationUs: Long,
    availableDurationUs: Long,
    queue: (Mutable)List<MediaChunk!>!,
    mediaChunkIterators: Array<MediaChunkIterator!>!
)

Updates the selected track for sources that load media in discrete MediaChunks.

Public constructors

BaseTrackSelection

BaseTrackSelection(group: TrackGroup!, tracks: IntArray!)
Parameters
group: TrackGroup!

The TrackGroup. Must not be null.

tracks: IntArray!

The indices of the selected tracks within the TrackGroup. Must not be null or empty. May be in any order.

BaseTrackSelection

BaseTrackSelection(
    group: TrackGroup!,
    tracks: IntArray!,
    @TrackSelection.Type type: Int
)
Parameters
group: TrackGroup!

The TrackGroup. Must not be null.

tracks: IntArray!

The indices of the selected tracks within the TrackGroup. Must not be null or empty. May be in any order.

@TrackSelection.Type type: Int

The type that will be returned from getType.

Public functions

disable

fun disable(): Unit

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

fun enable(): Unit

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.

equals

fun equals(obj: Any?): Boolean

evaluateQueueSize

fun evaluateQueueSize(
    playbackPositionUs: Long,
    queue: (Mutable)List<MediaChunk!>!
): Int

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
playbackPositionUs: Long

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: (Mutable)List<MediaChunk!>!

The queue of buffered MediaChunks. Must not be modified.

Returns
Int

The number of chunks to retain in the queue.

excludeTrack

fun excludeTrack(index: Int, exclusionDurationMs: Long): Boolean

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
index: Int

The index of the track in the selection.

exclusionDurationMs: Long

The duration of time for which the track should be excluded, in milliseconds.

Returns
Boolean

Whether exclusion was successful.

getFormat

fun getFormat(index: Int): Format!

Returns the format of the track at a given index in the selection.

Parameters
index: Int

The index in the selection.

Returns
Format!

The format of the selected track.

getIndexInTrackGroup

fun getIndexInTrackGroup(index: Int): Int

Returns the index in the track group of the track at a given index in the selection.

Parameters
index: Int

The index in the selection.

Returns
Int

The index of the selected track.

getSelectedFormat

fun getSelectedFormat(): Format!

Returns the Format of the individual selected track.

getSelectedIndexInTrackGroup

fun getSelectedIndexInTrackGroup(): Int

Returns the index in the track group of the individual selected track.

getTrackGroup

fun getTrackGroup(): TrackGroup!

Returns the TrackGroup to which the selected tracks belong.

hashCode

fun hashCode(): Int

indexOf

fun indexOf(format: Format!): Int

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 INDEX_UNSET if the track with the specified format is not part of the selection.

indexOf

fun indexOf(indexInTrackGroup: Int): Int

Returns the index in the selection of the track with the specified index in the track group.

Parameters
indexInTrackGroup: Int

The index in the track group.

Returns
Int

The index in the selection, or INDEX_UNSET if the track with the specified index is not part of the selection.

isTrackExcluded

fun isTrackExcluded(index: Int, nowMs: Long): Boolean

Returns whether the track at the specified index in the selection is excluded.

Parameters
index: Int

The index of the track in the selection.

nowMs: Long

The current time in the timebase of elapsedRealtime.

length

fun length(): Int

Returns the number of tracks in the selection.

onPlaybackSpeed

fun onPlaybackSpeed(playbackSpeed: Float): Unit

Called to notify the selection of the current playback speed. The playback speed may affect adaptive track selection.

Parameters
playbackSpeed: Float

The factor by which playback is sped up.

Public properties

type

@TrackSelection.Type
val typeInt

The type of the selection.

Protected properties

group

protected val groupTrackGroup!

The selected TrackGroup.

length

protected val lengthInt

The number of selected tracks within the TrackGroup. Always greater than zero.

tracks

protected val tracksIntArray<Int>!

The indices of the selected tracks in group, in order of decreasing bandwidth.