我对 exoplayer 没有什么问题。当我尝试从 hls 流播放视频时,几乎一切正常。 hls 流包含 3 组不同的 block 列表,每组用于不同的带宽。
但 hls 自适应流式传输不起作用,播放器只能使用一个 block 列表,并且互联网连接速度较慢,因此该解决方案无法使用。
源代码:
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);
关于android - exoplayer- 自动更改质量不起作用 (hls),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48489858/