[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
This commit is contained in:
jbibik 2025-01-08 06:04:20 -08:00 committed by Copybara-Service
parent 48e3eaa623
commit 79d41aac7e

View File

@ -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, _, _ ->