PlayPauseButton

Functions summary

Unit
@UnstableApi
@Composable
PlayPauseButton(
    player: Player?,
    modifier: Modifier,
    displayMode: @DisplayMode Int,
    imageVector: PlayPauseButtonState.() -> ImageVector,
    iconSize: Dp,
    contentDescription: @Composable PlayPauseButtonState.() -> String,
    colors: IconButtonColors,
    tint: Color,
    onClick: PlayPauseButtonState.() -> Unit
)

A Material3 IconButton that plays or pauses the current media item.

Unit
@UnstableApi
@Composable
PlayPauseButton(
    player: Player?,
    modifier: Modifier,
    displayMode: @DisplayMode Int,
    painter: @Composable PlayPauseButtonState.() -> Painter,
    iconSize: Dp,
    contentDescription: @Composable PlayPauseButtonState.() -> String,
    colors: IconButtonColors,
    tint: Color,
    onClick: PlayPauseButtonState.() -> Unit
)

A Material3 IconButton that plays or pauses the current media item.

Functions

@UnstableApi
@Composable
fun PlayPauseButton(
    player: Player?,
    modifier: Modifier = Modifier,
    displayMode: @DisplayMode Int = SHOW_BUFFERING_ALWAYS or SHOW_REPLAY_ON_ENDED or SHOW_RETRY_ON_ERROR,
    imageVector: PlayPauseButtonState.() -> ImageVector,
    iconSize: Dp = PlayerTokens.MediumIconSize,
    contentDescription: @Composable PlayPauseButtonState.() -> String = defaultPlayPauseContentDescription,
    colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
    tint: Color = Color.Unspecified,
    onClick: PlayPauseButtonState.() -> Unit = PlayPauseButtonState::onClick
): Unit

A Material3 IconButton that plays or pauses the current media item.

When clicked, it will pause the player if it's currently playing, or play it otherwise. The button's state (e.g., whether it's enabled and the current play/pause icon) is managed by a PlayPauseButtonState instance derived from the provided player.

Parameters
player: Player?

The Player to control.

modifier: Modifier = Modifier

The Modifier to be applied to the button container.

displayMode: @DisplayMode Int = SHOW_BUFFERING_ALWAYS or SHOW_REPLAY_ON_ENDED or SHOW_RETRY_ON_ERROR

The DisplayMode determining under which conditions buffering, replay, or retry indicators should be shown. Defaults to SHOW_BUFFERING_ALWAYS combined with SHOW_REPLAY_ON_ENDED and SHOW_RETRY_ON_ERROR.

imageVector: PlayPauseButtonState.() -> ImageVector

The supplier for ImageVector used for the icon displayed on the button. This is a composable lambda with PlayPauseButtonState as its receiver, allowing the icon to be updated based on the button's current state (e.g., PlayPauseButtonState.showPlay).

iconSize: Dp = PlayerTokens.MediumIconSize

The size of the icon.

contentDescription: @Composable PlayPauseButtonState.() -> String = defaultPlayPauseContentDescription

The content description for accessibility purposes.

colors: IconButtonColors = IconButtonDefaults.iconButtonColors()

IconButtonColors that will be used to resolve the colors used for this icon button and buffering indicator. See IconButtonDefaults.iconButtonColors.

tint: Color = Color.Unspecified

Tint to be applied to imageVector. If Color.Unspecified is provided, then no tint is applied.

onClick: PlayPauseButtonState.() -> Unit = PlayPauseButtonState::onClick

The action to be performed when the button is clicked. This lambda has PlayPauseButtonState as its receiver, providing access to the button's current state (e.g., PlayPauseButtonState.isEnabled). The default behavior is to call PlayPauseButtonState.onClick, which toggles the player's play/pause state. Consumers can customize this behavior:

  • To add custom logic while still performing the default action, call this.onClick() within your lambda.

  • To completely override the default behavior, implement your custom logic without calling this.onClick().

@UnstableApi
@Composable
fun PlayPauseButton(
    player: Player?,
    modifier: Modifier = Modifier,
    displayMode: @DisplayMode Int = SHOW_BUFFERING_ALWAYS or SHOW_REPLAY_ON_ENDED or SHOW_RETRY_ON_ERROR,
    painter: @Composable PlayPauseButtonState.() -> Painter = defaultPlayPausePainterIcon,
    iconSize: Dp = PlayerTokens.MediumIconSize,
    contentDescription: @Composable PlayPauseButtonState.() -> String = defaultPlayPauseContentDescription,
    colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
    tint: Color = Color.Unspecified,
    onClick: PlayPauseButtonState.() -> Unit = PlayPauseButtonState::onClick
): Unit

A Material3 IconButton that plays or pauses the current media item.

When clicked, it will pause the player if it's currently playing, or play it otherwise. The button's state (e.g., whether it's enabled and the current play/pause icon) is managed by a PlayPauseButtonState instance derived from the provided player.

Parameters
player: Player?

The Player to control.

modifier: Modifier = Modifier

The Modifier to be applied to the button container.

displayMode: @DisplayMode Int = SHOW_BUFFERING_ALWAYS or SHOW_REPLAY_ON_ENDED or SHOW_RETRY_ON_ERROR

The DisplayMode determining under which conditions buffering, replay, or retry indicators should be shown. Defaults to SHOW_BUFFERING_ALWAYS combined with SHOW_REPLAY_ON_ENDED and SHOW_RETRY_ON_ERROR.

painter: @Composable PlayPauseButtonState.() -> Painter = defaultPlayPausePainterIcon

The supplier for Painter used for the icon displayed on the button. This is a composable lambda with PlayPauseButtonState as its receiver, allowing the icon to be updated based on the button's current state (e.g., PlayPauseButtonState.showPlay).

iconSize: Dp = PlayerTokens.MediumIconSize

The size of the icon.

contentDescription: @Composable PlayPauseButtonState.() -> String = defaultPlayPauseContentDescription

The content description for accessibility purposes.

colors: IconButtonColors = IconButtonDefaults.iconButtonColors()

IconButtonColors that will be used to resolve the colors used for this icon button and buffering indicator. See IconButtonDefaults.iconButtonColors.

tint: Color = Color.Unspecified

Tint to be applied to painter. If Color.Unspecified is provided, then no tint is applied.

onClick: PlayPauseButtonState.() -> Unit = PlayPauseButtonState::onClick

The action to be performed when the button is clicked. This lambda has PlayPauseButtonState as its receiver, providing access to the button's current state (e.g., PlayPauseButtonState.isEnabled). The default behavior is to call PlayPauseButtonState.onClick, which toggles the player's play/pause state. Consumers can customize this behavior:

  • To add custom logic while still performing the default action, call this.onClick() within your lambda.

  • To completely override the default behavior, implement your custom logic without calling this.onClick().