> Documentation index: https://developer.android.com/reference/llms.txt

# PlaybackSpeedToggleButton

## Functions summary

|---|---|
| `Unit` | `@UnstableApi @Composable PlaybackSpeedToggleButton( player: Player?, modifier: Modifier, speedSelection: List<Float>, shape: Shape, colors: ButtonColors, elevation: ButtonElevation?, border: BorderStroke?, contentPadding: PaddingValues, interactionSource: MutableInteractionSource?, onClick: PlaybackSpeedState.() -> Unit, content: @Composable PlaybackSpeedState.() -> Unit )` A Material3 `TextButton` that toggles the playback speed of the player. |

## Functions

### PlaybackSpeedToggleButton

Artifact: [androidx.media3:media3-ui-compose-material3](https://developer.android.com/jetpack/androidx/releases/media3.md.txt) [View Source](https://cs.android.com/search?q=file:androidx/media3/ui/compose/material3/buttons/PlaybackSpeedButton.kt+function:PlaybackSpeedToggleButton)

```
@UnstableApi
@Composable
fun PlaybackSpeedToggleButton(
    player: Player?,
    modifier: Modifier = Modifier,
    speedSelection: List<Float> = listOf(0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f),
    shape: Shape = ButtonDefaults.textShape,
    colors: ButtonColors = ButtonDefaults.textButtonColors(),
    elevation: ButtonElevation? = null,
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.TextButtonContentPadding,
    interactionSource: MutableInteractionSource? = null,
    onClick: PlaybackSpeedState.() -> Unit = {
    val nextSpeed = speedSelection.firstOrNull { it > playbackSpeed } ?: speedSelection.first()
    updatePlaybackSpeed(nextSpeed)
  },
    content: @Composable PlaybackSpeedState.() -> Unit = {
    Text(text = stringResource(R.string.playback_speed_format, playbackSpeed))
  }
): Unit
```

A Material3 `TextButton` that toggles the playback speed of the player.

![PlaybackSpeedToggleButton
image](https://developer.android.com/images/reference/androidx/media3/ui/compose/material3/playback-speed-toggle-button.svg)

When clicked, it cycles through the available playback speeds in the order defined by `speedSelection`. If the current playback speed is not among the ones in the list, a click will toggle the speed to the next value that is greater than the current speed. If all speeds in `speedSelection` are smaller than the current speed, it will cycle back to the first speed in the list.

The button's state (e.g., whether it's enabled and the current playback speed) is managed by a `PlaybackSpeedState` instance derived from the provided `player`.

| Parameters |
|---|---|
| `player: Player?` | The `Player` to control. |
| `modifier: Modifier = Modifier` | The `Modifier` to be applied to the button. |
| `speedSelection: List<Float> = listOf(0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f)` | The sequence of speeds to cycle through when the button is clicked. |
| `shape: Shape = ButtonDefaults.textShape` | Defines the shape of this button's container, border (when `border` is not null), and shadow (when using `elevation`). See `ButtonDefaults.textShape`. |
| `colors: ButtonColors = ButtonDefaults.textButtonColors()` | `ButtonColors` that will be used to resolve the colors for this button in different states. See `ButtonDefaults.textButtonColors`. |
| `elevation: ButtonElevation? = null` | `ButtonElevation` used to resolve the elevation for this button in different states. A `TextButton` typically has no elevation. See `ButtonDefaults.buttonElevation`. |
| `border: BorderStroke? = null` | The border to draw around the container of this button. |
| `contentPadding: PaddingValues = ButtonDefaults.TextButtonContentPadding` | The spacing values to apply internally between the container and the content. See `ButtonDefaults.TextButtonContentPadding`. |
| `interactionSource: MutableInteractionSource? = null` | An optional hoisted `MutableInteractionSource` for observing and emitting `Interaction`s for this button. You can use this to change the button's appearance or preview the button in different states. Note that if `null` is provided, interactions will still happen internally. |
| `onClick: PlaybackSpeedState.() -> Unit = { val nextSpeed = speedSelection.firstOrNull { it > playbackSpeed } ?: speedSelection.first() updatePlaybackSpeed(nextSpeed) }` | The action to be performed when the button is clicked. This lambda has `PlaybackSpeedState` as its receiver, providing access to the button's current state (e.g., `PlaybackSpeedState.playbackSpeed` and `PlaybackSpeedState.updatePlaybackSpeed`). The default behavior selects the next speed from `speedSelection` as described above and applies it with `PlaybackSpeedState.updatePlaybackSpeed`. Consumers can customize this behavior: - To apply a different speed, call `this.updatePlaybackSpeed(speed)` with the desired value. - To add custom logic, such as logging, run it in the lambda alongside the call to `this.updatePlaybackSpeed(speed)`. |
| `content: @Composable PlaybackSpeedState.() -> Unit = { Text(text = stringResource(R.string.playback_speed_format, playbackSpeed)) }` | A composable lambda with `PlaybackSpeedState` as its receiver, allowing the content of the button to be customized. |