Move PlayerSurface from demo-compose to media3-ui-compose

The new `media3-ui-compose` module does not have any Material library dependencies, but will rely on androidx.compose + foundation/runtime/ui and other non-theming/opinionated libraries. Surface handling is one such usecase.

PiperOrigin-RevId: 689004504
This commit is contained in:
jbibik 2024-10-23 09:57:01 -07:00 committed by Copybara-Service
parent 21526588be
commit 7da71f792b
5 changed files with 13 additions and 4 deletions

View File

@ -34,6 +34,7 @@
* Muxers:
* IMA extension:
* UI:
* Add `PlayerSurface` Composable to `media3-ui-compose` module.
* Downloads:
* OkHttp Extension:
* Cronet Extension:

View File

@ -76,6 +76,7 @@ dependencies {
implementation 'com.google.android.material:material:' + androidxMaterialVersion
implementation project(modulePrefix + 'lib-exoplayer')
implementation project(modulePrefix + 'lib-ui-compose')
// For detecting and debugging leaks only. LeakCanary is not needed for demo app to work.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:' + leakCanaryVersion

View File

@ -30,6 +30,8 @@ import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.demo.compose.data.videos
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.compose.PlayerSurface
import androidx.media3.ui.compose.SURFACE_TYPE_SURFACE_VIEW
class MainActivity : ComponentActivity() {

View File

@ -52,6 +52,9 @@ dependencies {
def composeBom = platform('androidx.compose:compose-bom:2024.01.00')
implementation composeBom
implementation 'androidx.compose.foundation:foundation'
implementation 'androidx.core:core:' + androidxCoreVersion
}
ext {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package androidx.media3.demo.compose
package androidx.media3.ui.compose
import android.view.Surface
import android.view.SurfaceView
@ -26,6 +26,7 @@ import androidx.compose.foundation.AndroidExternalSurfaceScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
/**
* Provides a dedicated drawing [Surface] for media playbacks using a [Player].
@ -40,6 +41,7 @@ import androidx.media3.common.Player
* [Choosing a surface type](https://developer.android.com/media/media3/ui/playerview#surfacetype)
* for more information.
*/
@UnstableApi
@Composable
fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modifier = Modifier) {
val onSurfaceCreated: (Surface) -> Unit = { surface -> player.setVideoSurface(surface) }
@ -64,13 +66,13 @@ fun PlayerSurface(player: Player, surfaceType: @SurfaceType Int, modifier: Modif
* The type of surface view used for media playbacks. One of [SURFACE_TYPE_SURFACE_VIEW] or
* [SURFACE_TYPE_TEXTURE_VIEW].
*/
@MustBeDocumented
@UnstableApi
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER)
@IntDef(SURFACE_TYPE_SURFACE_VIEW, SURFACE_TYPE_TEXTURE_VIEW)
annotation class SurfaceType
/** Surface type equivalent to [SurfaceView] . */
const val SURFACE_TYPE_SURFACE_VIEW = 1
@UnstableApi const val SURFACE_TYPE_SURFACE_VIEW = 1
/** Surface type equivalent to [TextureView]. */
const val SURFACE_TYPE_TEXTURE_VIEW = 2
@UnstableApi const val SURFACE_TYPE_TEXTURE_VIEW = 2