android - ExoPlayer 无法在某些设备上播放声音
问题描述
我正在尝试在 Android 上使用 ExoPlayer 创建一个流媒体应用程序。大多数流工作正常,只有其中一些不能仅在某些设备上播放声音。
这是使用此命令提取的流信息:
ffprobe -v error -show_format -show_streams http://nasaiptv.com:8000/live/qSplUhwfcy/bE43JqZPSt/477.ts
[STREAM]
index=0
codec_name=mpeg2video
codec_long_name=MPEG-2 video
profile=Main
codec_type=video
codec_time_base=1/25
codec_tag_string=[2][0][0][0]
codec_tag=0x0002
width=720
height=576
coded_width=0
coded_height=0
has_b_frames=1
sample_aspect_ratio=16:15
display_aspect_ratio=4:3
pix_fmt=yuv420p
level=8
color_range=tv
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=progressive
timecode=N/A
refs=1
id=0x100
r_frame_rate=25/1
avg_frame_rate=25/1
time_base=1/90000
start_pts=3471311880
start_time=38570.132000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]
[STREAM]
index=1
codec_name=mp2
codec_long_name=MP2 (MPEG audio layer 2)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[3][0][0][0]
codec_tag=0x0003
sample_fmt=fltp
sample_rate=48000
channels=2
channel_layout=stereo
bits_per_sample=0
id=0x101
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/90000
start_pts=3471301664
start_time=38570.018489
duration_ts=N/A
duration=N/A
bit_rate=112000
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]
[FORMAT]
filename=http://nasaiptv.com:8000/live/qSplUhwfcy/AVbqREBSOh/477.ts
nb_streams=2
nb_programs=1
format_name=mpegts
format_long_name=MPEG-TS (MPEG-2 Transport Stream)
start_time=38570.018489
duration=N/A
size=N/A
bit_rate=N/A
probe_score=50
[/FORMAT]
这就是我开始播放流的方式:
private SimpleExoPlayer player;
private PlayerView exoPlayer;
private void initializePlayer() {
exoPlayer = findViewById(R.id.exo_player);
player = ExoPlayerFactory.newSimpleInstance(
new DefaultRenderersFactory(this, EXTENSION_RENDERER_MODE_ON),
new DefaultTrackSelector(),
new DefaultLoadControl());
player.addListener(listener);
exoPlayer.setPlayer(player);
player.setPlayWhenReady(true);
Uri uri = Uri.parse(stream.getStreamUriString());
MediaSource mediaSource = new ExtractorMediaSource.Factory(
new DefaultHttpDataSourceFactory("exoplayer-codelab")).createMediaSource(uri);
player.prepare(mediaSource, true, false);
}
我也试过 withEXTENSION_RENDERER_MODE_OFF
和 with EXTENSION_RENDERER_MODE_PREFER
,没有成功。
这是在将示例项目中的扩展导入我的项目之后。
这是一个ffmpeg
问题吗?如果我必须从头开始构建扩展,是否可以在 Windows 中进行?在我的 PC 上安装 Linux 有点问题。根据我的流信息,是否有任何教程可以正确地做到这一点?
ExoPlayer 是一个很棒的媒体播放器,但它确实缺乏文档(或者很难找到)。
解决方案
您可以尝试通过将 附加ExoPlayer.EventListner
到您的SimpleExoPlayer
实例并覆盖来获取一些详细的错误信息onPlayerError
。
@Override
public void onPlayerError(ExoPlaybackException error) {
switch (error.type) {
case ExoPlaybackException.TYPE_SOURCE:
Log.e(TAG, "TYPE_SOURCE: " + error.getSourceException().getMessage());
break;
case ExoPlaybackException.TYPE_RENDERER:
Log.e(TAG, "TYPE_RENDERER: " + error.getRendererException().getMessage());
break;
case ExoPlaybackException.TYPE_UNEXPECTED:
Log.e(TAG, "TYPE_UNEXPECTED: " + error.getUnexpectedException().getMessage());
break;
}
}
收到错误消息后,请更新您的问题
推荐阅读
- webclient - FeignCleint 与 WebClient 的优缺点
- mongodb - 在ubuntu上重新安装mongodb服务后失败
- python - 将matlab中的单元格数据转换为python中的数据框的最佳方法
- python - 无法将 datetime.datetime 与 django 中的 datetime.date 进行比较
- c++ - 将函数传递给类中的函数时数据类型不匹配
- amazon-web-services - 用户无权执行:SNS:在资源上发布
- visual-studio - 让视觉工作室检查编码惯例并自动报告/纠正它们
- c++ - 从字符串中删除单词并打印它们的地址
- python - 格式化列表以显示为坐标
- node.js - nodejs createWriteStream - 错误:ENOENT:没有这样的文件或目录