From 79d41aac7e43e95c9b0cce1c8f57c5c29335d3bc Mon Sep 17 00:00:00 2001 From: jbibik Date: Wed, 8 Jan 2025 06:04:20 -0800 Subject: [PATCH] [ui-compose] Fix PlayerSurface's use of Player The new `currentPlayer` was only used to check the available command. It should also be used for setting and clearing the Surface. The PlayerSurface was still behaving correctly, perhaps due to the lambda being reevaluated with the new player (since `currentPlayer` is of type MutableState). Which meant it was also using the latest `player` that `PlayerSurface` was recomposed with (in the argument), rather than holding onto the original object. PiperOrigin-RevId: 713264041 --- .../src/main/java/androidx/media3/ui/compose/PlayerSurface.kt | 4 ++-- 1 file changed, 2 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 f681d28025..e02309a697 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 @@ -51,11 +51,11 @@ fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modif val currentPlayer by rememberUpdatedState(player) val onSurfaceCreated: (Surface) -> Unit = { surface -> if (currentPlayer.isCommandAvailable(Player.COMMAND_SET_VIDEO_SURFACE)) - player.setVideoSurface(surface) + currentPlayer.setVideoSurface(surface) } val onSurfaceDestroyed: () -> Unit = { if (currentPlayer.isCommandAvailable(Player.COMMAND_SET_VIDEO_SURFACE)) - player.clearVideoSurface() + currentPlayer.clearVideoSurface() } val onSurfaceInitialized: AndroidExternalSurfaceScope.() -> Unit = { onSurface { surface, _, _ ->