# TrackSelection

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/TrackSelection.java+class:androidx.media3.exoplayer.trackselection.TrackSelection)

*** ** * ** ***


```
@UnstableApi
public interface TrackSelection
```

<br />

Known direct subclasses [ExoTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` | A `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection` that can change the individually selected track as a result of calling `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[])` or `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection#evaluateQueueSize(long,java.util.List<? extends androidx.media3.exoplayer.source.chunk.MediaChunk>)`. |

Known indirect subclasses [AdaptiveTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection), [BaseTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/BaseTrackSelection), [FakeTrackSelection](https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackSelection), [FixedTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/FixedTrackSelection), [ForwardingTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection), [RandomTrackSelection](https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/RandomTrackSelection)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection` | A bandwidth based adaptive `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection`, whose selected track is updated to be the highest priority track given the current network conditions and the state of the buffer. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/BaseTrackSelection` | An abstract base class suitable for most `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` implementations. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackSelection` | A fake `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` that supports selecting a subset of tracks within a `https://developer.android.com/reference/androidx/media3/common/TrackGroup`, returns 1 fixed track, and tracks the number of calls to its methods. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/FixedTrackSelection` | A `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection` consisting of a single track. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection` | An `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` forwarding all calls to a wrapped instance. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/RandomTrackSelection` | An `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/ExoTrackSelection` whose selected track is updated randomly. |

*** ** * ** ***

A track selection consisting of a static subset of selected tracks belonging to a `https://developer.android.com/reference/androidx/media3/common/TrackGroup`.

Tracks belonging to the subset are exposed in selection order with the highest priority track first, for example in decreasing bandwidth order.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(open = true, value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection.Type` Represents a type track selection. |

| ### Constants |
|---|---|
| `default 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. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET() = 0` An unspecified track selection type. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#getFormat(int)(int index)` Returns the format of the track at a given index in the selection. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#getIndexInTrackGroup(int)(int index)` Returns the index in the track group of the track at a given index in the selection. |
| `abstract https://developer.android.com/reference/androidx/media3/common/TrackGroup` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#getTrackGroup()()` Returns the `https://developer.android.com/reference/androidx/media3/common/TrackGroup` to which the selected tracks belong. |
| `abstract int` | `@https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection.Type https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#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. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#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. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#indexOf(int)(int indexInTrackGroup)` Returns the index in the selection of the track with the specified index in the track group. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/exoplayer/trackselection/TrackSelection#length()()` Returns the number of tracks in the selection. |

## Constants

### TYPE_CUSTOM_BASE

```
default static final int TYPE_CUSTOM_BASE = 10000
```

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

### TYPE_UNSET

```
default static final int TYPE_UNSET = 0
```

An unspecified track selection type.

## Public methods

### getFormat

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

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

### getTrackGroup

```
abstract TrackGroup getTrackGroup()
```

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

### getType

```
@TrackSelection.Type
abstract 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.

### indexOf

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

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

### length

```
abstract int length()
```

Returns the number of tracks in the selection.