android - Exoplayer 无法捕获错误 - 输入不以 #EXTM3U 标头开头
问题描述
像上面的标题一样,我无法捕捉到错误Input does not start with the #EXTM3U header.
我试图以这种方式捕捉错误:
exoPlayer.addListener(new ExoPlayer.EventListener() {
@Override
public void onPlayerError(ExoPlaybackException error) {
Toast.makeText(Act_Details.this, "SOURCE ERROR1", Toast.LENGTH_SHORT).show(); //Didn't work or didn't get here
Log.e("EXO-ERROR", error.getCause().getMessage()); //Didn't work or didn't get here
switch (error.type) {
case ExoPlaybackException.TYPE_SOURCE:
Toast.makeText(Act_Details.this, "SOURCE ERROR1", Toast.LENGTH_SHORT).show(); //Didn't work or didn't get here
Log.e("EXO-ERROR-SOURCE", error.getCause().getMessage()); //Didn't work or didn't get here
...
...
并尝试这样:
try {
PlayerMode = "HLS Mode";
HlsMediaSource hlsMediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
exoPlayer = new SimpleExoPlayer.Builder(context).setTrackSelector(trackSelector).build();
exoPlayer.prepare(hlsMediaSource);
} catch (Exception e) {
Log.d("Set_Media_Player", e.getMessage()); //Didn't work or didn't get here
return null;
}
错误 :
E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: Input does not start with the #EXTM3U header.
at com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser.parse(HlsPlaylistParser.java:199)
at com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser.parse(HlsPlaylistParser.java:62)
at com.google.android.exoplayer2.upstream.ParsingLoadable.load(ParsingLoadable.java:172)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
我尝试播放的 url 是 .m3u8 类型的,结果如上,然后我尝试使用 Progressive 模式,它可以工作。
我怎样才能捕捉到错误,所以我可以尝试下一个模式?
解决方案
您需要使用.addAnalyticsListener(...)
而不是.addListener
.
推荐阅读
- python - 检查是否已发送电子邮件并打开 .exe 的 Python 脚本
- crash - 致命错误:找不到“breakpad-main/src/client/linux/handler/minidump_descriptor.h”文件
- visual-studio-code - 使用 VS 代码命令行界面 (CLI) 打开 Raspberry Pi 网络附加存储 (NAS) 上的文件夹时权限被拒绝
- r - 使用 Rvest 搜索 Google 新闻获取关键字
- python - 对于 REST API,我可以使用 flask-login 提供的身份验证机制,还是必须明确使用基于令牌的身份验证,如 JWT?
- python - NoneType 对象不可调用(制作词法分析器)
- javascript - 有没有办法为我的命令添加全局冷却时间,这样当一个用户使用该命令时,所有用户都必须等待特定时间?
- ios - 测试飞行中的 IOS 应用程序崩溃(delphi10.4)
- c++ - C++ 升压系统::error_code 语言
- php - 无法使用 PHP 重命名文件