# CastTrackSelector

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

*** ** * ** ***


```
@UnstableApi
abstract class CastTrackSelector
```

<br />

*** ** * ** ***

Handles track selections and parameter changes for `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer`.

See `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)` for the most important uses of this class.

An instance of this class must not be reused across different `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer` instances. A new instance must be created for each player.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest` Holds parameters associated with a `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)`. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult` The result of a `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)`. |
| `class https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult.Builder` A builder for `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult`. |
| `@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/cast/CastTrackSelector.TrackSelectionRequestReason` The reason for track selection request. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#TRACK_SELECTION_REQUEST_REASON_INVALIDATION() = 0` The selection request is the result of a call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#invalidate()`. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#TRACK_SELECTION_REQUEST_REASON_PARAMETER_CHANGE() = 2` The selection request is the result of a call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer#setTrackSelectionParameters(androidx.media3.common.TrackSelectionParameters)`. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#TRACK_SELECTION_REQUEST_REASON_RECEIVER_UPDATE() = 1` The selection request is the result of an update from the Cast receiver app. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#CastTrackSelector()()` Constructor. |

| ### Public functions |
|---|---|
| `abstract https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult!` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)(request: https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest!)` Called by `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer` to optionally change the current track selections and/or parameters. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#invalidate()()` Triggers a new call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)`, so as to change the selected tracks. |

## Constants

### TRACK_SELECTION_REQUEST_REASON_INVALIDATION

```
const val TRACK_SELECTION_REQUEST_REASON_INVALIDATION = 0: Int
```

The selection request is the result of a call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#invalidate()`.

### TRACK_SELECTION_REQUEST_REASON_PARAMETER_CHANGE

```
const val TRACK_SELECTION_REQUEST_REASON_PARAMETER_CHANGE = 2: Int
```

The selection request is the result of a call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer#setTrackSelectionParameters(androidx.media3.common.TrackSelectionParameters)`.

### TRACK_SELECTION_REQUEST_REASON_RECEIVER_UPDATE

```
const val TRACK_SELECTION_REQUEST_REASON_RECEIVER_UPDATE = 1: Int
```

The selection request is the result of an update from the Cast receiver app.

## Protected constructors

### CastTrackSelector

```
protected CastTrackSelector()
```

Constructor.

## Public functions

### evaluate

```
abstract fun evaluate(request: CastTrackSelector.CastTrackSelectorRequest!): CastTrackSelector.CastTrackSelectorResult!
```

Called by `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer` to optionally change the current track selections and/or parameters.

You can implement this method to change the currently active tracks through `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult#selections()`. For example, in response to a change in the current track selection parameters, available through `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest#trackSelectionParameters()`.

Alternatively, you can also change the `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer#getTrackSelectionParameters()` in response to a receiver app track selection change.

You can trigger a call to this method by calling `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#invalidate()`, or by changing the `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer#setTrackSelectionParameters(androidx.media3.common.TrackSelectionParameters)`.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest!` | The `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest` that contains the current state to evaluate in order to provide a `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult` with updated track selections or parameters. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult!` | A `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult` to update the state of `https://developer.android.com/reference/kotlin/androidx/media3/cast/RemoteCastPlayer` and the receiver Cast application. |

### invalidate

```
fun invalidate(): Unit
```

Triggers a new call to `https://developer.android.com/reference/kotlin/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)`, so as to change the selected tracks.

Must be called on the main thread.