1717package androidx.media3.ui.compose
1818
1919import android.content.Context
20+ import android.opengl.GLSurfaceView
2021import android.view.SurfaceView
2122import android.view.TextureView
2223import android.view.View
@@ -31,16 +32,14 @@ import androidx.compose.ui.Modifier
3132import androidx.compose.ui.viewinterop.AndroidView
3233import androidx.media3.common.Player
3334import androidx.media3.common.util.UnstableApi
34- import androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView
3535import kotlinx.coroutines.Dispatchers
3636import kotlinx.coroutines.withContext
3737
3838/* *
3939 * Provides a dedicated drawing [android.view.Surface] for media playbacks using a [Player].
4040 *
4141 * The player's video output is displayed with either a [android.view.SurfaceView], a
42- * [android.view.TextureView], or a
43- * [androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView].
42+ * [android.view.TextureView], or a `SphericalGLSurfaceView`.
4443 *
4544 * [Player] takes care of attaching the rendered output to the [android.view.Surface] and clearing
4645 * it, when it is destroyed.
@@ -77,11 +76,26 @@ fun PlayerSurface(
7776 PlayerSurfaceInternal (
7877 player,
7978 modifier,
80- createView = ::SphericalGLSurfaceView ,
79+ createView = {
80+ try {
81+ // LINT.IfChange
82+ val surfaceViewClassName =
83+ " androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView"
84+ val surfaceViewClass = Class .forName(surfaceViewClassName)
85+
86+ surfaceViewClass.getConstructor(Context ::class .java).newInstance(it) as GLSurfaceView
87+ // LINT.ThenChange(../../../../../../../proguard-rules.txt)
88+ } catch (exception: ClassNotFoundException ) {
89+ throw IllegalStateException (
90+ " SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW requires an ExoPlayer dependency" ,
91+ exception
92+ )
93+ }
94+ },
8195 setVideoView = { setVideoSurfaceView(it) },
8296 clearVideoView = { setVideoSurfaceView(null ) },
83- onReset = SphericalGLSurfaceView ::onPause,
84- onUpdate = SphericalGLSurfaceView ::onResume,
97+ onReset = GLSurfaceView ::onPause,
98+ onUpdate = GLSurfaceView ::onResume,
8599 )
86100 else -> throw IllegalArgumentException (" Unrecognized surface type: $surfaceType " )
87101 }
@@ -160,5 +174,5 @@ annotation class SurfaceType
160174@UnstableApi const val SURFACE_TYPE_SURFACE_VIEW = 1
161175/* * Surface type to create [android.view.TextureView]. */
162176@UnstableApi const val SURFACE_TYPE_TEXTURE_VIEW = 2
163- /* * Surface type to create [androidx.media3.exoplayer.video.spherical. SphericalGLSurfaceView] . */
177+ /* * Surface type to create ` SphericalGLSurfaceView` . */
164178@UnstableApi const val SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW = 3
0 commit comments