Exoplayer的渲染器的解码器不遵循所选曲目的格式

时间:2018-11-07 04:32:58

标签: android streaming exoplayer

我正在测试一种具有四种格式的HLS源:720p,360p,180p和仅音频。

我当前对Exoplayer的实现如下:

DefaultBandwidthMeter bandwidthMeter;

//In onViewCreated()
bandwidthMeter = new DefaultBandwidthMeter.Builder()
                        .setInitialBitrateEstimate(2000000)
                        .setEventListener(getHandler(), (elapsedMs, bytes, bitrate) -> {
                            try {
                                Trace.i("GameSourceSpecs : " + elapsedMs + " " + bytes + " " + bitrate);
                            } catch (Exception e) {
                                Trace.w(e);
                            }
                        })
                        .build();

private MediaSource buildHLSMediaSource(Uri uri) {
    DefaultDataSourceFactory dsf = new DefaultDataSourceFactory(getActivity(), "ua", bandwidthMeter);
    DefaultHlsDataSourceFactory dsfHls = new DefaultHlsDataSourceFactory(dsf);
    return new HlsMediaSource.Factory(dsfHls).createMediaSource(uri);
}

TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
((DefaultTrackSelector) trackSelector).setParameters(new DefaultTrackSelector.ParametersBuilder().build());

mMediaSource360 = buildHLSMediaSource(Uri.parse("http://35.187.250.251:8880/live/playlist.m3u8"));
mMediaSource360.addEventListener(getHandler(), new MSourceDebuggerListener("GameMediaSource360"));

//noinspection deprecation
mPlayer = ExoPlayerFactory.newSimpleInstance(mActivity, trackSelector, new DefaultLoadControl(
        new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
        1000,  // min buffer
        2000, // max buffer
        1000, // playback
        1000,   //playback after rebuffer
        DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES,
        true
));

mPlayer.prepare(source, true, true);
mPlayer.setPlayWhenReady(true);

我一直尝试播放的HLS文件如下:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=544100,RESOLUTION=360x640
chunklist_w2108226616_b544100_sleng.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=294100,RESOLUTION=180x320
chunklist_w2108226616_b294100_sleng.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=48000
chunklist_w2108226616_b48000_ao_sleng.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1044100,RESOLUTION=720x1280
chunklist_w2108226616_b1044100_sleng.m3u8

我可以使用getCurrentMappedTrackInfo()在Exoplayer中看到可用的曲目,列出了所有可用的视频曲目分辨率。但是,当我尝试使用以下方法将最大视频大小设置为720p时:

dts.setParameters(new DefaultTrackSelector.ParametersBuilder() .setMaxVideoSize(720, 1280) .setMaxVideoBitrate(Integer.MAX_VALUE) .build());

视频轨道当然已更改为720p,但解码器保持360p。如何使解码器匹配所选的轨道格式?

编辑:

我知道720p的比特率是1044100,并且上次我检查流何时仍在打开时,我的带宽估计值远高于此值(约1900000左右)。

1 个答案:

答案 0 :(得分:0)

这是一个错误的警报,对不起。事实证明,该720p流确实是贴错标签的360p流,这引起了我的困惑。

整个过程都按预期进行。