找不到适合内容类型的媒体源工厂:2 (Exo Player)
No suitable media source factory found for content type: 2 (Exo Player)
我正在尝试使用 ExoPlayer 播放流。
我通过从 Github 下载 ExoPlayer 添加到项目中,以便使用 FFmpeg 渲染器扩展。以前,我通过在 app/build.gradle
中添加实现来使用它并且它正在运行。
但是流没有播放声音。 Exo 不支持其编解码器。所以我必须使用 FFmpeg 扩展。要构建和使用扩展,我们必须通过本地下载方法。但现在这一次,当我构建并 运行 应用程序时,它因错误而崩溃。
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>
我的活动代码
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()
}
}
这是我得到的错误
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)
已修复我在 app/build 中遗漏的问题。gradle
implementation project(':exoplayer-library')
只解决了这个错误,还是没有声音
我正在尝试使用 ExoPlayer 播放流。
我通过从 Github 下载 ExoPlayer 添加到项目中,以便使用 FFmpeg 渲染器扩展。以前,我通过在 app/build.gradle
中添加实现来使用它并且它正在运行。
但是流没有播放声音。 Exo 不支持其编解码器。所以我必须使用 FFmpeg 扩展。要构建和使用扩展,我们必须通过本地下载方法。但现在这一次,当我构建并 运行 应用程序时,它因错误而崩溃。
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>
我的活动代码
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()
}
}
这是我得到的错误
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)
已修复我在 app/build 中遗漏的问题。gradle
implementation project(':exoplayer-library')
只解决了这个错误,还是没有声音