Material3 Compose

media3-ui-compose-material3 库在内部处理状态管理和 Material3 样式设置。如需详细了解应使用哪个库,请参阅 Media3 Compose 概览

// The library provides styled UI components
Row {
  SeekBackButton(player)
  PlayPauseButton(player)
  SeekForwardButton(player)
}

自定义 Material3 组件

虽然 media3-ui-compose-material3 提供的组件遵循 Material 3 设计,但您仍然可以完全控制主题设置。您可以通过将播放器界面封装在 MaterialTheme 中来自定义颜色、排版和形状。

例如,如需更改 PlayPauseButton 的颜色,您可以提供自定义 colorScheme

MaterialTheme(
  colorScheme =
    lightColorScheme(
      primary = Color.Red, // Change the primary color for the button
      onPrimary = Color.White,
    )
) {
  // The PlayPauseButton will now use the custom colors
  PlayPauseButton(player)
}

可用的 Material3 组件

media3-ui-compose-material3 库提供了一组预构建的可组合项,用于实现常见的播放器控件。以下是一些可以直接在应用中使用的组件:

组件 说明
PlayPauseButton 可在播放和暂停之间切换的按钮。
SeekBackButton 用于按定义的增量向后搜索的按钮。
SeekForwardButton 用于按定义的增量快进的按钮。
NextButton 用于跳转到下一个媒体内容的按钮。
PreviousButton 用于跳转到上一个媒体内容的按钮。
RepeatButton 用于循环切换重复播放模式的按钮。
ShuffleButton 用于切换随机播放模式的按钮。
MuteButton 用于将播放器静音和取消静音的按钮。
PositionAndDurationText 一种用于显示当前位置和总时长的文本可组合项。
PositionText 用于显示当前位置的文本可组合项。
DurationText 用于显示总时长的文本可组合项。
RemainingDurationText 用于显示剩余时长的文本可组合项。

此列表并不详尽。如需查看所有可用组件,请参阅库的 API 参考文档。

您可能需要的另外两个预构建的可组合项与界面管理相关,它们位于 media3-ui-compose 模块中,因为它们不具备 Material 主题。

组件 说明
ContentFrame 用于显示媒体内容的 Surface,可处理宽高比管理、调整大小和快门
PlayerSurface AndroidView 中封装 SurfaceViewTextureView 的原始界面