[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
(cherry picked from commit afea6962c254b6621eee2b8f075d6fdb5283602a)
This commit is contained in:
jbibik 2025-02-26 06:34:29 -08:00 committed by oceanjules
parent 4d3f71a0c6
commit f7479347c0

View File

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