androidx.media3.ui.compose

Annotations

SurfaceType

The type of surface used for media playbacks.

Constants summary

Top-level functions summary

Unit
@UnstableApi
@Composable
ContentFrame(
    player: Player?,
    modifier: Modifier,
    surfaceType: @SurfaceType Int,
    contentScale: ContentScale,
    keepContentOnReset: Boolean,
    shutter: @Composable () -> Unit
)

A container for displaying media content from a Player.

Unit
@UnstableApi
@Composable
PlayerSurface(
    player: Player?,
    modifier: Modifier,
    surfaceType: @SurfaceType Int
)

Provides a dedicated drawing android.view.Surface for media playbacks using a Player.

Constants

SURFACE_TYPE_SURFACE_VIEW

@UnstableApi
const val SURFACE_TYPE_SURFACE_VIEW = 1: Int

Surface type to create android.view.SurfaceView.

SURFACE_TYPE_TEXTURE_VIEW

@UnstableApi
const val SURFACE_TYPE_TEXTURE_VIEW = 2: Int

Surface type to create android.view.TextureView.

Top-level functions

@UnstableApi
@Composable
fun ContentFrame(
    player: Player?,
    modifier: Modifier = Modifier,
    surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW,
    contentScale: ContentScale = ContentScale.Fit,
    keepContentOnReset: Boolean = false,
    shutter: @Composable () -> Unit = { Box(Modifier.fillMaxSize().background(Color.Black)) }
): Unit

A container for displaying media content from a Player.

This composable handles the underlying PlayerSurface for video playback, resizing the video based on the provided ContentScale, and displaying a shutter according to the PresentationState based off the Player.

Parameters
player: Player?

The attached Player that provides media to this content frame.

modifier: Modifier = Modifier

The Modifier to be applied to the layout.

surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW

The type of surface to use for video playback. Can be either SURFACE_TYPE_SURFACE_VIEW or SURFACE_TYPE_TEXTURE_VIEW.

contentScale: ContentScale = ContentScale.Fit

The ContentScale strategy for the container.

keepContentOnReset: Boolean = false

If true, the last rendered frame will remain visible when the player is reset. If false, the surface will be cleared.

shutter: @Composable () -> Unit = { Box(Modifier.fillMaxSize().background(Color.Black)) }

A composable that is displayed when the video surface needs to be covered. By default, this is a black background.

@UnstableApi
@Composable
fun PlayerSurface(
    player: Player?,
    modifier: Modifier = Modifier,
    surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW
): Unit

Provides a dedicated drawing android.view.Surface for media playbacks using a Player.

The player's video output is displayed with either a android.view.SurfaceView or a android.view.TextureView.

Player takes care of attaching the rendered output to the android.view.Surface and clearing it, when it is destroyed.

See Choosing a surface type for more information.