From 77a215f39cb00587844571d6aa38fde0a46ba7e3 Mon Sep 17 00:00:00 2001 From: jbibik Date: Thu, 12 Dec 2024 06:55:09 -0800 Subject: [PATCH] [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 --- .../main/java/androidx/media3/ui/compose/PlayerSurface.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt b/libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt index fa702aa564..51f2154970 100644 --- a/libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt +++ b/libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt @@ -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)