# 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
interface TrackSelection
```

<br />

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

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ExoTrackSelection` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection` that can change the individually selected track as a result of calling `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection), [BaseTrackSelection](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/BaseTrackSelection), [FakeTrackSelection](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeTrackSelection), [FixedTrackSelection](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/FixedTrackSelection), [ForwardingTrackSelection](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection), [RandomTrackSelection](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/RandomTrackSelection)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/AdaptiveTrackSelection` | A bandwidth based adaptive `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/exoplayer/trackselection/BaseTrackSelection` | An abstract base class suitable for most `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ExoTrackSelection` implementations. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeTrackSelection` | A fake `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ExoTrackSelection` that supports selecting a subset of tracks within a `https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup`, returns 1 fixed track, and tracks the number of calls to its methods. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/FixedTrackSelection` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection` consisting of a single track. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ForwardingTrackSelection` | An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/ExoTrackSelection` forwarding all calls to a wrapped instance. |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/RandomTrackSelection` | An `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/annotation/IntDef(open = true, value = ) annotation https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection.Type` Represents a type track selection. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_CUSTOM_BASE() = 10000` The first value that can be used for application specific track selection types. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET() = 0` An unspecified track selection type. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#getFormat(int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the format of the track at a given index in the selection. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#getIndexInTrackGroup(int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the index in the track group of the track at a given index in the selection. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#getTrackGroup()()` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/TrackGroup` to which the selected tracks belong. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection.Type https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#getType()()` Returns an integer specifying the type of the selection, or `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#TYPE_UNSET()` if not specified. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#indexOf(androidx.media3.common.Format)(format: https://developer.android.com/reference/kotlin/androidx/media3/common/Format!)` Returns the index in the selection of the track with the specified format. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#indexOf(int)(indexInTrackGroup: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the index in the selection of the track with the specified index in the track group. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/trackselection/TrackSelection#length()()` Returns the number of tracks in the selection. |

## Constants

### TYPE_CUSTOM_BASE

```
const val TYPE_CUSTOM_BASE = 10000: Int
```

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

### TYPE_UNSET

```
const val TYPE_UNSET = 0: Int
```

An unspecified track selection type.

## Public functions

### getFormat

```
fun getFormat(index: Int): Format!
```

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

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index in the selection. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index in the selection. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the selected track. |

### getTrackGroup

```
fun getTrackGroup(): TrackGroup!
```

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

### getType

```
@TrackSelection.Type
fun getType(): Int
```

Returns an integer specifying the type of the selection, or `https://developer.android.com/reference/kotlin/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/kotlin/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

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index in the selection, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index in the track group. |

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

### length

```
fun length(): Int
```

Returns the number of tracks in the selection.