# ForwardingTrackSelection

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/trackselection/ForwardingTrackSelection.java+class:androidx.media3.exoplayer.trackselection.ForwardingTrackSelection)

*** ** * ** ***


```
@UnstableApi
public class ForwardingTrackSelection implements ExoTrackSelection
```

<br />

*** ** * ** ***

An `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` forwarding all calls to a wrapped instance.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#ForwardingTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection)(https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection)` Creates the forwarding track selection. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#clearTrackExclusions()()` Clears the existing track exclusions. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#disable()()` Disables this track selection. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#enable()()` Enables the track selection. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html obj)` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#evaluateQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)(long playbackPositionUs, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue)` Returns the number of chunks that should be retained in the queue. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#excludeTrack(int,long)(int index, long exclusionDurationMs)` Attempts to exclude the track at the specified index in the selection, making it ineligible for selection by calls to `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])` for the specified period of time. |
| `https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getFormat(int)(int index)` Returns the format of the track at a given index in the selection. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getIndexInTrackGroup(int)(int index)` Returns the index in the track group of the track at a given index in the selection. |
| `long` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getLatestBitrateEstimate()()` Returns the most recent bitrate estimate utilised for track selection. |
| `https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getSelectedFormat()()` Returns the `https://developer.android.com/reference/androidx/media3/common/Format` of the individual selected track. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getSelectedIndex()()` Returns the index of the selected track. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getSelectedIndexInTrackGroup()()` Returns the index in the track group of the individual selected track. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getSelectionData()()` Returns optional data associated with the current track selection. |
| `int` | `@https://developer.android.com/reference/androidx/media3/common/C.SelectionReason https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getSelectionReason()()` Returns the reason for the current track selection. |
| `https://developer.android.com/reference/androidx/media3/common/TrackGroup` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getTrackGroup()()` Returns the `https://developer.android.com/reference/androidx/media3/common/TrackGroup` to which the selected tracks belong. |
| `int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection.Type https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getType()()` Returns an integer specifying the type of the selection, or `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET()` if not specified. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#getWrappedInstance()()` Returns the wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection`. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#hashCode()()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#indexOf(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Returns the index in the selection of the track with the specified format. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#indexOf(int)(int indexInTrackGroup)` Returns the index in the selection of the track with the specified index in the track group. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#isTrackExcluded(int,long)(int index, long nowMs)` Returns whether the track at the specified index in the selection is excluded. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#length()()` Returns the number of tracks in the selection. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#onDiscontinuity()()` Called to notify the selection of a position discontinuity. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#onPlayWhenReadyChanged(boolean)(boolean playWhenReady)` Called to notify when the playback is paused or resumed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#onPlaybackSpeed(float)(float playbackSpeed)` Called to notify the selection of the current playback speed. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#onRebuffer()()` Called to notify when a rebuffer occurred. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#shouldCancelChunkLoad(long,androidx.media3.exoplayer.source.chunk.Chunk,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)( long playbackPositionUs, https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadingChunk, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue )` Returns whether an ongoing load of a chunk should be canceled. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators )` Updates the selected track for sources that load media in discrete `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s. |

| ### Inherited Constants |
|---|
| From [androidx.media3.exoplayer.trackselection.TrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection) |---|---| | `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_CUSTOM_BASE() = 10000` The first value that can be used for application specific track selection types. | | `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET() = 0` An unspecified track selection type. | |

## Public constructors

### ForwardingTrackSelection

```
public ForwardingTrackSelection(ExoTrackSelection trackSelection)
```

Creates the forwarding track selection.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection trackSelection` | The wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection`. |

## Public methods

### clearTrackExclusions

```
public void clearTrackExclusions()
```

Clears the existing track exclusions. The excluded tracks will be eligible for selection from the next call to `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])`.

### disable

```
public void disable()
```

Disables this track selection. No further dynamic changes via `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])`, `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#evaluateQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)` or `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#shouldCancelChunkLoad(long,androidx.media3.exoplayer.source.chunk.Chunk,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)` 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 `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])`, `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#evaluateQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)` or `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#shouldCancelChunkLoad(long,androidx.media3.exoplayer.source.chunk.Chunk,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)` will only happen after this call.

This method may not be called when the track selection is already enabled.

### equals

```
public boolean equals(@Nullable Object obj)
```

### 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 `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` 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 `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.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 `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` 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. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`. Must not be modified. |

| 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 `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.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 `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])`.

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 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format` | The format of the selected track. |

### getIndexInTrackGroup

```
public 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. |

### getLatestBitrateEstimate

```
public long getLatestBitrateEstimate()
```

Returns the most recent bitrate estimate utilised for track selection.

The default behavior is to return `https://developer.android.com/reference/androidx/media3/common/C#RATE_UNSET_INT()`, indicating that the bitrate estimate was not computed for the track selection decision.

### getSelectedFormat

```
public Format getSelectedFormat()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/Format` of the individual selected track.

### getSelectedIndex

```
public int getSelectedIndex()
```

Returns the index of the selected track.

### getSelectedIndexInTrackGroup

```
public int getSelectedIndexInTrackGroup()
```

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

### getSelectionData

```
public @Nullable Object getSelectionData()
```

Returns optional data associated with the current track selection.

### getSelectionReason

```
@C.SelectionReason
public int getSelectionReason()
```

Returns the reason for the current track selection.

### getTrackGroup

```
public TrackGroup getTrackGroup()
```

Returns the `https://developer.android.com/reference/androidx/media3/common/TrackGroup` to which the selected tracks belong.

### getType

```
@TrackSelection.Type
public int getType()
```

Returns an integer specifying the type of the selection, or `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET()` if not specified.

Track selection types are specific to individual applications, but should be defined starting from `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_CUSTOM_BASE()` to ensure they don't conflict with any types that may be added to the library in the future.

### getWrappedInstance

```
public ExoTrackSelection getWrappedInstance()
```

Returns the wrapped `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection`.

### hashCode

```
public int hashCode()
```

### indexOf

```
public 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The format. |

| Returns |
|---|---|
| `int` | The index in the selection, or `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the track with the specified format is not part of the selection. |

### indexOf

```
public 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 `https://developer.android.com/reference/androidx/media3/common/C#INDEX_UNSET()` if the track with the specified index is not part of the selection. |

### 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 `https://developer.android.com/reference/android/os/SystemClock.html#elapsedRealtime()`. |

### length

```
public int length()
```

Returns the number of tracks in the selection.

### onDiscontinuity

```
public void onDiscontinuity()
```

Called to notify the selection of a position discontinuity.

This happens when the playback position jumps, e.g., as a result of a seek being performed.

### onPlayWhenReadyChanged

```
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. |

### onRebuffer

```
public void onRebuffer()
```

Called to notify when a rebuffer occurred.

A rebuffer is defined to be caused by buffer depletion rather than a user action. Hence this method is not called during initial buffering or when buffering as a result of a seek operation.

### shouldCancelChunkLoad

```
public boolean shouldCancelChunkLoad(
    long playbackPositionUs,
    Chunk loadingChunk,
    List<MediaChunk> queue
)
```

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

May be called by sources that load media in discrete `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` and support canceling the ongoing chunk load. The ongoing chunk load is either the last `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk` in the queue or another type of `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk`, for example, if the source loads initialization or encryption data.

To avoid excessive re-buffering, implementations should normally return `false`. An example where `true` might be returned is if a load of a high quality chunk gets stuck and canceling this load in favor of a lower quality alternative may avoid a rebuffer.

The source will call `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#evaluateQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)` after the cancelation finishes to allow discarding of chunks, and `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#updateSelectedTrack(long,long,long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>,androidx.media3.exoplayer.source.chunk.MediaChunkIterator[])` before loading a new chunk to allow switching to another quality.

This method will only be called when the selection is enabled.

| 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. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk loadingChunk` | The currently loading `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/Chunk` that will be canceled if this method returns `true`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`, including the ` loadingChunk` if it's a `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`. Must not be modified. |

| Returns |
|---|---|
| `boolean` | Whether the ongoing load of `loadingChunk` should be canceled. |

### updateSelectedTrack

```
public void updateSelectedTrack(
    long playbackPositionUs,
    long bufferedDurationUs,
    long availableDurationUs,
    List<MediaChunk> queue,
    MediaChunkIterator[] mediaChunkIterators
)
```

Updates the selected track for sources that load media in discrete `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s.

This method will only be called when the selection is enabled.

| 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. |
| `long bufferedDurationUs` | The duration of media currently buffered from the current playback position, in microseconds. Note that the next load position can be calculated as ` (playbackPositionUs + bufferedDurationUs)`. |
| `long availableDurationUs` | The duration of media available for buffering from the current playback position, in microseconds, or `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()` if media can be buffered to the end of the current period. Note that if not set to `https://developer.android.com/reference/androidx/media3/common/C#TIME_UNSET()`, the position up to which media is available for buffering can be calculated as `(playbackPositionUs + availableDurationUs)`. |
| `https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk> queue` | The queue of already buffered `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunk`s. Must not be modified. |
| `MediaChunkIterator[] mediaChunkIterators` | An array of `https://developer.android.com/reference/androidx/media3/exoplayer/source/chunk/MediaChunkIterator`s providing information about the sequence of upcoming media chunks for each track in the selection. All iterators start from the media chunk which will be loaded next if the respective track is selected. Note that this information may not be available for all tracks, and so some iterators may be empty. |