17
17
package androidx.media3.ui.compose
18
18
19
19
import android.content.Context
20
+ import android.opengl.GLSurfaceView
20
21
import android.view.SurfaceView
21
22
import android.view.TextureView
22
23
import android.view.View
@@ -31,16 +32,14 @@ import androidx.compose.ui.Modifier
31
32
import androidx.compose.ui.viewinterop.AndroidView
32
33
import androidx.media3.common.Player
33
34
import androidx.media3.common.util.UnstableApi
34
- import androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView
35
35
import kotlinx.coroutines.Dispatchers
36
36
import kotlinx.coroutines.withContext
37
37
38
38
/* *
39
39
* Provides a dedicated drawing [android.view.Surface] for media playbacks using a [Player].
40
40
*
41
41
* 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`.
44
43
*
45
44
* [Player] takes care of attaching the rendered output to the [android.view.Surface] and clearing
46
45
* it, when it is destroyed.
@@ -77,11 +76,26 @@ fun PlayerSurface(
77
76
PlayerSurfaceInternal (
78
77
player,
79
78
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
+ },
81
95
setVideoView = { setVideoSurfaceView(it) },
82
96
clearVideoView = { setVideoSurfaceView(null ) },
83
- onReset = SphericalGLSurfaceView ::onPause,
84
- onUpdate = SphericalGLSurfaceView ::onResume,
97
+ onReset = GLSurfaceView ::onPause,
98
+ onUpdate = GLSurfaceView ::onResume,
85
99
)
86
100
else -> throw IllegalArgumentException (" Unrecognized surface type: $surfaceType " )
87
101
}
@@ -160,5 +174,5 @@ annotation class SurfaceType
160
174
@UnstableApi const val SURFACE_TYPE_SURFACE_VIEW = 1
161
175
/* * Surface type to create [android.view.TextureView]. */
162
176
@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` . */
164
178
@UnstableApi const val SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW = 3
0 commit comments