我对exoplayer没什么问题.当我尝试从hls流播放视频时几乎一切正常. hls流包含3组不同的组块列表,每组用于不同的带宽.
但是自适应流媒体不起作用,播放器只能使用一个块表,并且网络连接速度慢,这个解决方案无法使用.
源代码:
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才会按预期进行自适应流式传输.
原文链接:/android/430190.html只有在这些更改之后,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,httpDataSourceFactory);