# 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
public abstract class CastTrackSelector
```

<br />

*** ** * ** ***

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

See `https://developer.android.com/reference/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/androidx/media3/cast/RemoteCastPlayer` instances. A new instance must be created for each player.

## Summary

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

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/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/androidx/media3/cast/CastTrackSelector#invalidate()`. |
| `static final int` | `https://developer.android.com/reference/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/androidx/media3/cast/RemoteCastPlayer#setTrackSelectionParameters(androidx.media3.common.TrackSelectionParameters)`. |
| `static final int` | `https://developer.android.com/reference/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/androidx/media3/cast/CastTrackSelector#CastTrackSelector()()` Constructor. |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/androidx/media3/cast/CastTrackSelector.CastTrackSelectorResult` | `https://developer.android.com/reference/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)(https://developer.android.com/reference/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest request)` Called by `https://developer.android.com/reference/androidx/media3/cast/RemoteCastPlayer` to optionally change the current track selections and/or parameters. |
| `final void` | `https://developer.android.com/reference/androidx/media3/cast/CastTrackSelector#invalidate()()` Triggers a new call to `https://developer.android.com/reference/androidx/media3/cast/CastTrackSelector#evaluate(androidx.media3.cast.CastTrackSelector.CastTrackSelectorRequest)`, so as to change the selected tracks. |

## Constants

### TRACK_SELECTION_REQUEST_REASON_INVALIDATION

```
public static final int TRACK_SELECTION_REQUEST_REASON_INVALIDATION = 0
```

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

### TRACK_SELECTION_REQUEST_REASON_PARAMETER_CHANGE

```
public static final int TRACK_SELECTION_REQUEST_REASON_PARAMETER_CHANGE = 2
```

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

### TRACK_SELECTION_REQUEST_REASON_RECEIVER_UPDATE

```
public static final int TRACK_SELECTION_REQUEST_REASON_RECEIVER_UPDATE = 1
```

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

## Protected constructors

### CastTrackSelector

```
protected CastTrackSelector()
```

Constructor.

## Public methods

### evaluate

```
public abstract CastTrackSelector.CastTrackSelectorResult evaluate(CastTrackSelector.CastTrackSelectorRequest request)
```

Called by `https://developer.android.com/reference/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/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/androidx/media3/cast/CastTrackSelector.CastTrackSelectorRequest#trackSelectionParameters()`.

Alternatively, you can also change the `https://developer.android.com/reference/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/androidx/media3/cast/CastTrackSelector#invalidate()`, or by changing the `https://developer.android.com/reference/androidx/media3/cast/RemoteCastPlayer#setTrackSelectionParameters(androidx.media3.common.TrackSelectionParameters)`.

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

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

### invalidate

```
public final void invalidate()
```

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

Must be called on the main thread.