From afea6962c254b6621eee2b8f075d6fdb5283602a Mon Sep 17 00:00:00 2001 From: jbibik Date: Wed, 26 Feb 2025 06:34:29 -0800 Subject: [PATCH] [ui-compose] Add default value to `PlayerSurface`'s surfaceType PlayerView's default surface type was also SURFACE_VIEW. This allows for a simple `PlayerSurface(player)` usage by most developers. The order of the arguments needs to be changed, because `modifier` should be the first default argument (https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md#parameter) PiperOrigin-RevId: 731294658 --- .../androidx/media3/ui/compose/PlayerSurface.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 e02309a697..02246b11d7 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 @@ -17,8 +17,6 @@ package androidx.media3.ui.compose import android.view.Surface -import android.view.SurfaceView -import android.view.TextureView import androidx.annotation.IntDef import androidx.compose.foundation.AndroidEmbeddedExternalSurface import androidx.compose.foundation.AndroidExternalSurface @@ -33,8 +31,9 @@ import androidx.media3.common.util.UnstableApi /** * Provides a dedicated drawing [Surface] for media playbacks using a [Player]. * - * The player's video output is displayed with either a [SurfaceView]/[AndroidExternalSurface] or a - * [TextureView]/[AndroidEmbeddedExternalSurface]. + * The player's video output is displayed with either a + * [android.view.SurfaceView]/[AndroidExternalSurface] or a + * [android.view.TextureView]/[AndroidEmbeddedExternalSurface]. * * [Player] takes care of attaching the rendered output to the [Surface] and clearing it, when it is * destroyed. @@ -45,7 +44,11 @@ import androidx.media3.common.util.UnstableApi */ @UnstableApi @Composable -fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modifier = Modifier) { +fun PlayerSurface( + player: Player, + modifier: Modifier = Modifier, + surfaceType: @SurfaceType Int = SURFACE_TYPE_SURFACE_VIEW, +) { // Player might change between compositions, // we need long-lived surface-related lambdas to always use the latest value val currentPlayer by rememberUpdatedState(player) @@ -83,7 +86,7 @@ fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modif @IntDef(SURFACE_TYPE_SURFACE_VIEW, SURFACE_TYPE_TEXTURE_VIEW) annotation class SurfaceType -/** Surface type equivalent to [SurfaceView] . */ +/** Surface type equivalent to [android.view.SurfaceView]. */ @UnstableApi const val SURFACE_TYPE_SURFACE_VIEW = 1 -/** Surface type equivalent to [TextureView]. */ +/** Surface type equivalent to [android.view.TextureView]. */ @UnstableApi const val SURFACE_TYPE_TEXTURE_VIEW = 2