Player

Functions summary

Unit
@UnstableApi
@Composable
Player(player: Player?, modifier: Modifier)

A composable that provides a basic player UI layout with a shutter and hidden default controls.

Unit
@ExperimentalApi
@Composable
Player(
    player: Player?,
    modifier: Modifier,
    surfaceType: @SurfaceType Int,
    contentScale: ContentScale,
    alignment: Alignment,
    keepContentOnReset: Boolean,
    subtitles: @Composable () -> Unit,
    shutter: @Composable () -> Unit,
    artwork: (@Composable () -> Unit)?,
    showControls: Boolean,
    topControls: (@Composable BoxScope.() -> Unit)?,
    centerControls: (@Composable BoxScope.() -> Unit)?,
    bottomControls: (@Composable BoxScope.() -> Unit)?,
    errorOverlay: (@Composable BoxScope.() -> Unit)?
)

A composable that provides a basic player UI layout, combining a ContentFrame for displaying player content with customizable controls and a shutter.

Functions

@UnstableApi
@Composable
fun Player(player: Player?, modifier: Modifier = Modifier): Unit

A composable that provides a basic player UI layout with a shutter and hidden default controls.

This composable consists of a ContentFrame that handles the rendering of the player's video, overlaid with a shutter and the standard Material3 layouts provided by PlayerDefaults. This includes PlayerDefaults.TopControls, PlayerDefaults.CenterControls, and PlayerDefaults.BottomControls.

The controls are always hidden, because showing them permanently would occlude the video. To show and hide them, for example when the user taps the player, use the overload that accepts showControls. That overload also allows customizing the UI components.

Parameters
player: Player?

The Player instance whose content is displayed.

modifier: Modifier = Modifier

The Modifier to be applied to the outer Box.

@ExperimentalApi
@Composable
fun Player(
    player: Player?,
    modifier: Modifier = Modifier,
    surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW,
    contentScale: ContentScale = ContentScale.Fit,
    alignment: Alignment = Alignment.Center,
    keepContentOnReset: Boolean = false,
    subtitles: @Composable () -> Unit = { Subtitles(player) },
    shutter: @Composable () -> Unit = PlayerDefaults::Shutter,
    artwork: (@Composable () -> Unit)? = { Artwork( player, modifier = Modifier.fillMaxSize(), alignment = alignment, contentScale = contentScale, ) },
    showControls: Boolean = false,
    topControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.TopControls(player, showControls, Modifier.fillMaxWidth()) },
    centerControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.CenterControls(player, showControls, Modifier.fillMaxWidth()) },
    bottomControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.BottomControls(player, showControls) },
    errorOverlay: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.ErrorOverlay(player) }
): Unit

A composable that provides a basic player UI layout, combining a ContentFrame for displaying player content with customizable controls and a shutter.

This composable is designed to be a flexible container for building player interfaces. It consists of a ContentFrame that handles the rendering of the player's video, overlaid with optional controls and a shutter.

By default, this component uses the standard Material3 layouts provided by PlayerDefaults. This includes PlayerDefaults.TopControls, PlayerDefaults.CenterControls, and PlayerDefaults.BottomControls. You can deeply customize the player UI by providing your own composables to the slots of this composable, or by utilizing the PlayerDefaults layouts and overriding only specific slots within them.

The Player natively manages keyboard focus traversal between its control slots. Each provided control slot (topControls, centerControls, and bottomControls) is wrapped in a focus group. 1-dimensional focus traversal (e.g., using the Tab key) is configured to move sequentially from the top controls, to the center controls, and down to the bottom controls. Backward traversal moves in the reverse order.

Parameters
player: Player?

The Player instance to be controlled and whose content is displayed.

modifier: Modifier = Modifier

The Modifier to be applied to the outer Box.

surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW

The type of surface to use for video rendering. See SurfaceType.

contentScale: ContentScale = ContentScale.Fit

The scaling mode to apply to the content within the ContentFrame.

alignment: Alignment = Alignment.Center

The alignment of the scaled content within the ContentFrame. If the scaled content overflows the ContentFrame, for example with ContentScale.Crop, the alignment determines which part of the content is visible.

keepContentOnReset: Boolean = false

Whether to keep the content visible when the player is reset.

subtitles: @Composable () -> Unit = { Subtitles(player) }

A composable for rendering subtitles, drawn on top of the shutter and the artwork. Note that the default implementation does not currently support android.text.Spanned styling or android.view.accessibility.CaptioningManager.CaptionStyle properties (such as text backgrounds or edge types).

shutter: @Composable () -> Unit = PlayerDefaults::Shutter

A composable to be displayed as a shutter over the content. The default shutter is a black Box.

artwork: (@Composable () -> Unit)? = { Artwork( player, modifier = Modifier.fillMaxSize(), alignment = alignment, contentScale = contentScale, ) }

Optional composable slot to render artwork for the current media item.

showControls: Boolean = false

Whether the default controls should be visible. False by default, so that the video isn't occluded. Toggle it, for example, when the user taps the player. Custom control slots should manage their own visibility.

topControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.TopControls(player, showControls, Modifier.fillMaxWidth()) }

A composable aligned with Alignment.TopCenter.

centerControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.CenterControls(player, showControls, Modifier.fillMaxWidth()) }

A composable aligned with Alignment.Center.

bottomControls: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.BottomControls(player, showControls) }

A composable aligned with Alignment.BottomCenter.

errorOverlay: (@Composable BoxScope.() -> Unit)? = { PlayerDefaults.ErrorOverlay(player) }

Slot for the error message overlay. Defaults to PlayerDefaults.ErrorOverlay.