【问题标题】:ExoPlayer not playing sound on some devicesExoPlayer 无法在某些设备上播放声音
【发布时间】:2018-11-20 22:47:47
【问题描述】:

我正在尝试在 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);
   }

我也试过EXTENSION_RENDERER_MODE_OFFEXTENSION_RENDERER_MODE_PREFER,没有成功。

这是在将the sample project 中的扩展导入我的项目之后。

这是ffmpeg 的问题吗?如果我必须从头开始构建扩展,是否可以在 Windows 中进行?在我的 PC 上安装 Linux 有点问题。根据我的流信息,是否有任何教程可以正确地做到这一点?

ExoPlayer 是一款出色的媒体播放器,但它确实缺乏文档(或者很难找到)。

【问题讨论】:

  • 请提供一些有关您使用的流协议类型的详细信息(UDP、DASH 等)。还请提及您用于使用 ffmpeg 获取流信息的命令和参数
  • 我真的不知道如何找到协议,但我用使用的命令和流的 url 更新了我的问题(顶部代码)
  • 我同意,除了 Exoplayer 库的表面,它根本没有很好的文档记录。您是否通过覆盖 onPlayerError 收到任何错误消息?
  • @PrashanD 我正在等待报告进来,因为它在离我很远的设备上,我正在我的网络服务器上使用 ACRA 来存储报告

标签: android exoplayer android-ffmpeg


【解决方案1】:

您可以尝试通过将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;
        }
    }

收到错误消息后,请更新您的问题

【讨论】:

  • 很抱歉我的回复太晚了,但这个回调从未被调用过。
  • 似乎没有从 Exoplayer 框架生成的与声音未播放有关的明确错误。由于已经快两年了..您可以使用更新版本的 Exoplayer 进行检查。如果错误仍然存​​在,您可以为此打开一个 github 问题。
【解决方案2】:

总结一下:ExoPlayer 没有内置音频或视频编解码器。它使用运行它的设备的本机编解码器。意味着如果设备缺少流的音频编解码器,您将没有声音。您可以通过使用 ffmpeg 扩展来避免这种情况。但正如您已经指出的,您需要先自己构建它。

https://exoplayer.dev/supported-formats.htmlhttps://developer.android.com/guide/topics/media/media-formats#core

此外,您可以使用 ffmepg 转码您的流,使用不同的音频编解码器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2012-09-26
    • 1970-01-01
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多