exoplayer- 自动更改质量不起作用 (hls)

exoplayer- automatic change of quality is not working (hls)

我对 exoplayer 没有什么问题。当我尝试从 hls 流播放视频时,几乎一切正常。 hls 流包含 3 组不同的块列表,每组用于不同的带宽。

但是 hls 自适应流式传输不起作用,播放器只能与一个块列表一起工作,并且互联网连接速度较慢,此解决方案无法使用。

源代码:

 BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
 TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
 TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
 this.simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector);
 this.videoPlayer.setPlayer(this.simpleExoPlayer);

 DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this.getActivity(), Util.getUserAgent(this.getActivity(), "appName"));
 MediaSource mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(hlsUrl));
 this.simpleExoPlayer.prepare(mediaSource);
 this.simpleExoPlayer.setPlayWhenReady(true);

我也尝试实现 MediaSourceEventListener 并且 onDownstreamFormatChanged 在播放器初始化时只被调用一次。

感谢任何建议

这里的关键是您需要将传递给 AdaptiveTrackSelection.Factory 的 "bandwidthMeter" 也传递给 dataSourceFactory。 只有在这些更改之后,Exoplayer 才会按预期进行自适应流式传输。

String userAgent = "XYZPLAYER";
DefaultHttpDataSourceFactory httpDataSourceFactory = new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true);
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, bandwidthMeter, httpDataSourceFactory);