No suitable media source factory found for content type: 2 (type 2 is M3U8)

285 Views Asked by At

I'm getting this error when using exoplayer even though i'm specifying the mimo type so don't understand why this crash is happening. The version i'm using is 2.18.7:

   videoUrl?.let {
                if (it.endsWith(".m3u8")) {
                    val mediaItem = MediaItem.Builder()
                        .setUri(it)
                        .setMimeType(MimeTypes.APPLICATION_M3U8)
                        .build()
                    exoPlayer?.setMediaItem(mediaItem)
                } else {
                    exoPlayer?.setMediaItem(MediaItem.fromUri(it))
                }
            }

I was expecting for the video to play normally

1

There are 1 best solutions below

4
Gabriel Silva Hernandes On

To play HLS streams (or DASH, Smooth Streaming), you need to add the HLS dependency to your build.gradle file.

For Media3 ExoPlayer, that is:

androidx.media3:media3-exoplayer-hls

So, add:

implementation "androidx.media3:media3-exoplayer-hls:1.1.1"

(Replace the version number with the most recent one.)

And for ExoPlayer 2.x, it is:

com.google.android.exoplayer:exoplayer-hls