[ui-compose] Check Player commands in PlayerSurface actions

Setting and destroying the Surface should only happen if the `Player` has the required command

PiperOrigin-RevId: 705488781
This commit is contained in:
jbibik 2024-12-12 06:55:09 -08:00 committed by Copybara-Service
parent 4997ea82fa
commit 77a215f39c

View File

@ -44,8 +44,12 @@ import androidx.media3.common.util.UnstableApi
@UnstableApi
@Composable
fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modifier = Modifier) {
val onSurfaceCreated: (Surface) -> Unit = { surface -> player.setVideoSurface(surface) }
val onSurfaceDestroyed: () -> Unit = { player.setVideoSurface(null) }
val onSurfaceCreated: (Surface) -> Unit = { surface ->
if (player.isCommandAvailable(Player.COMMAND_SET_VIDEO_SURFACE)) player.setVideoSurface(surface)
}
val onSurfaceDestroyed: () -> Unit = {
if (player.isCommandAvailable(Player.COMMAND_SET_VIDEO_SURFACE)) player.clearVideoSurface()
}
val onSurfaceInitialized: AndroidExternalSurfaceScope.() -> Unit = {
onSurface { surface, _, _ ->
onSurfaceCreated(surface)