I'm trying to play a stream with ExoPlayer.
I add ExoPlayer to Project by downloading it from Github in order to use FFmpeg Renderer extensions. Previously, I was using it by adding implementations in app/build.gradle
and it was working.
But the stream didn't play the sound. Its codec wasn't supported by Exo. so I have to use FFmpeg extensions. To build and use extensions we have to go through the locally downloading method. But now this time, When I build and run the app it crashes with an error.
MyActivityLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.activities.ExoTest">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
MyActivityCode
class ExoTest : AppCompatActivity() {
private lateinit var mBinding: ActivityExoTestBinding
private lateinit var player: SimpleExoPlayer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = ActivityExoTestBinding.inflate(layoutInflater)
setContentView(mBinding.root)
val streamURL = "http://202.57.43.60:8443/live/5748aabe4c9d661afbd7f4068248f664/99.m3u8"
val defaultRenderersFactory = DefaultRenderersFactory(this).setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
player = SimpleExoPlayer.Builder(this, defaultRenderersFactory).build()
val mediaItem = MediaItem.fromUri(streamURL)
mBinding.videoView.player = player
player.setMediaItem(mediaItem)
player.prepare()
player.playWhenReady = true
player.play()
}
}
This is the error that I get
2021-04-20 09:17:07.561 4385-4385/com.johnrelly.livetv E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.johnrelly.livetv, PID: 4385
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.johnrelly.livetv/com.johnrelly.livetv.view.activities.ExoTest}: java.lang.NullPointerException: No suitable media source factory found for content type: 2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3547)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2080)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:7581)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.lang.NullPointerException: No suitable media source factory found for content type: 2
at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:176)
at com.google.android.exoplayer2.source.DefaultMediaSourceFactory.createMediaSource(DefaultMediaSourceFactory.java:329)
at com.google.android.exoplayer2.ExoPlayerImpl.createMediaSources(ExoPlayerImpl.java:933)
at com.google.android.exoplayer2.ExoPlayerImpl.setMediaItems(ExoPlayerImpl.java:365)
at com.google.android.exoplayer2.BasePlayer.setMediaItems(BasePlayer.java:49)
at com.google.android.exoplayer2.BasePlayer.setMediaItem(BasePlayer.java:34)
at com.google.android.exoplayer2.SimpleExoPlayer.setMediaItem(SimpleExoPlayer.java:1320)
at com.johnrelly.livetv.view.activities.ExoTest.onCreate(ExoTest.kt:43)
at android.app.Activity.performCreate(Activity.java:7805)
at android.app.Activity.performCreate(Activity.java:7794)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3378)
Fixed I was missing this in app/build.gradle
implementation project(':exoplayer-library')
only this error is solved, the sound is still not playing.