Media3 ExoPlayer - DefaultTimeBar cannot be cast to TimeBar

Viewed 30

Im migrating a Video screen from XML to Compose., I need to display Ads with the IMA plugin.

Right now, I'm using this dependencies:

implementation "androidx.media3:media3-ui:1.0.0-beta02"
implementation 'androidx.media3:media3-exoplayer:1.0.0-beta02'
implementation "androidx.media3:media3-exoplayer-ima:1.0.0-beta02"

And im implementing the player as follows:

@Composable
fun VideoPlayer(videoUri: String) {
    val context = LocalContext.current
    val exoPlayer = remember {
        ExoPlayer.Builder(context)
            .build()
            .apply {
                val defaultDataSourceFactory = DefaultDataSource.Factory(context)
                val dataSourceFactory: DataSource.Factory = DefaultDataSource.Factory(
                    context,
                    defaultDataSourceFactory
                )
                val source = ProgressiveMediaSource.Factory(dataSourceFactory)
                    .createMediaSource(MediaItem.fromUri(videoUri))

                setMediaSource(source)
                prepare()
            }
    }

    DisposableEffect(
        AndroidView(factory = {
            PlayerView(context).apply {
                hideController()
                player = exoPlayer
            }
        })
    ) {
        onDispose { exoPlayer.release() }
    }
}

But, when I run my app and navigate to the ExoPlayer screen, I get this error:

java.lang.ClassCastException: com.google.android.exoplayer2.ui.DefaultTimeBar cannot be cast to androidx.media3.ui.TimeBar

I find this odd, but perhaps in ExoPlayer3 you can customize the TimeBar and choose what class to use. Has someone has faced this before?

0 Answers
Related