[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
This commit is contained in:
jbibik 2025-02-26 06:34:29 -08:00 committed by Copybara-Service
parent ac1cf206c8
commit afea6962c2

View File

@ -17,8 +17,6 @@
package androidx.media3.ui.compose package androidx.media3.ui.compose
import android.view.Surface import android.view.Surface
import android.view.SurfaceView
import android.view.TextureView
import androidx.annotation.IntDef import androidx.annotation.IntDef
import androidx.compose.foundation.AndroidEmbeddedExternalSurface import androidx.compose.foundation.AndroidEmbeddedExternalSurface
import androidx.compose.foundation.AndroidExternalSurface 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]. * 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 * The player's video output is displayed with either a
* [TextureView]/[AndroidEmbeddedExternalSurface]. * [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 * [Player] takes care of attaching the rendered output to the [Surface] and clearing it, when it is
* destroyed. * destroyed.
@ -45,7 +44,11 @@ import androidx.media3.common.util.UnstableApi
*/ */
@UnstableApi @UnstableApi
@Composable @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, // Player might change between compositions,
// we need long-lived surface-related lambdas to always use the latest value // we need long-lived surface-related lambdas to always use the latest value
val currentPlayer by rememberUpdatedState(player) 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) @IntDef(SURFACE_TYPE_SURFACE_VIEW, SURFACE_TYPE_TEXTURE_VIEW)
annotation class SurfaceType annotation class SurfaceType
/** Surface type equivalent to [SurfaceView] . */ /** Surface type equivalent to [android.view.SurfaceView]. */
@UnstableApi const val SURFACE_TYPE_SURFACE_VIEW = 1 @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 @UnstableApi const val SURFACE_TYPE_TEXTURE_VIEW = 2