pillarbox-ui

Provides UI Compose components and helpers.

This includes:

  • PlayerSurface, to display a player on a surface, texture, or spherical surface.

  • Compose wrapper for ExoPlayer Views.

  • ProgressTracker to connect the player to a progress bar or slider.

Integration

To use this module, add the following dependency to your module's build.gradle/build.gradle.kts file:

implementation("ch.srgssr.pillarbox:pillarbox-ui:<pillarbox_version>")

Getting started

Display a Player

@Composable
fun SimplePlayer(
player: Player,
modifier: Modifier = Modifier,
) {
PlayerSurface(
player = player,
modifier = modifier,
)
}

Create a Player with controls and subtitles

In this example, we are drawing controls and subtitles on top of the Player. To add controls, you can use ExoPlayerControlView. And for subtitles, you can use ExoPlayerSubtitleView.

@Composable
fun MyPlayer(
player: Player,
modifier: Modifier = Modifier,
) {
Box(
modifier = modifier
.fillMaxWidth()
.wrapContentHeight()
.background(color = Color.Black),
contentAlignment = Alignment.Center,
) {
PlayerSurface(
player = player,
defaultAspectRatio = 1f,
)

ExoPlayerControlView(
player = player,
modifier = Modifier.matchParentSize(),
)

ExoPlayerSubtitleView(
player = player,
modifier = Modifier.matchParentSize(),
)
}
}

The defaultAspectRatio is used while the video is loading or if the Player doesn't play a video.

Scale mode

You can customize how the Player scales in the PlayerSurface, by setting the scaleMode argument.

PlayerSurface(
player = player,
scaleMode = ScaleMode.Fit,
)

Surface type

PlayerSurface lets you set the type of surface used to render its content, using its surfaceType argument.

PlayerSurface(
player = player,
surfaceType = SurfaceType.Surface,
)

Observe Player states

The ch.srgssr.pillarbox.ui.extension package provides a collection of extensions to observe a Player's state through Compose's State instances.

@Composable
fun MyPlayer(player: Player) {
val currentPosition: Long by player.currentPositionAsState()
val duration: Long by player.durationAsState()
val isPlaying: Boolean by player.isPlayingAsState()
}

Packages

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard