Skip to content

Commit daa4ae5

Browse files
committed
Remove dependency on lib-exoplayer from lib-ui-compose
1 parent 59dd3ba commit daa4ae5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

libraries/ui_compose/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ android {
4949
dependencies {
5050
api project(modulePrefix + 'lib-common')
5151
api project(modulePrefix + 'lib-common-ktx')
52-
api project(modulePrefix + 'lib-exoplayer')
5352

5453
def composeBom = platform('androidx.compose:compose-bom:2024.12.01')
5554
api composeBom
@@ -60,6 +59,7 @@ dependencies {
6059
testImplementation 'androidx.compose.ui:ui-test-android:1.8.2'
6160
testImplementation 'androidx.compose.ui:ui-test'
6261
testImplementation 'androidx.compose.ui:ui-test-junit4'
62+
testImplementation project(modulePrefix + 'lib-exoplayer')
6363
testImplementation project(modulePrefix + 'test-utils')
6464
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
6565
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Proguard rules specific to the UI Compose module.
2+
3+
# Constructor method and classes accessed via reflection in PlayerSurface
4+
-dontnote androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView
5+
-keepclassmembers class androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView {
6+
<init>(android.content.Context);
7+
}

libraries/ui_compose/src/main/java/androidx/media3/ui/compose/PlayerSurface.kt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package androidx.media3.ui.compose
1818

1919
import android.content.Context
20+
import android.opengl.GLSurfaceView
2021
import android.view.SurfaceView
2122
import android.view.TextureView
2223
import android.view.View
@@ -31,16 +32,14 @@ import androidx.compose.ui.Modifier
3132
import androidx.compose.ui.viewinterop.AndroidView
3233
import androidx.media3.common.Player
3334
import androidx.media3.common.util.UnstableApi
34-
import androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView
3535
import kotlinx.coroutines.Dispatchers
3636
import 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

Comments
 (0)