当用户改变视频质量时,我使用setMaxBitrate提供的DefaultTrackSelector来设置最大比特率。
val parameters = defaultTrackSelector.buildUponParameters()
.setMaxVideoBitrate(bitrate)
.build()
defaultTrackSelector.parameters = parameters但是,一旦调用该函数,就会丢弃当前缓冲区&立即显示重新缓冲。是否有任何方法可以继续使用旧缓冲区进行播放&只需像YouTube那样使用新的比特率设置加载新缓冲区?
这个问题已经在这里讨论过:https://github.com/google/ExoPlayer/issues/3522 https://github.com/google/ExoPlayer/issues/2250
但似乎还没有任何解决办法。如能就这一问题提供任何帮助,将不胜感激。提前谢谢。
发布于 2020-01-23 11:53:36
您可以轻松地完成it.You,必须已经使用了ExoPlayer,而ExoPlayer则提供了一个seekTo()方法。
在此方法中,您应该只传递玩家当前的位置,在此之前停止。
步骤:-1你必须改变你的质量像144 P到720 p。在此更改时间上,您必须存储当前的ExoPlayer当前位置,使用以下方法:-
Private int currentPosition=player.getCurrentPosition();步骤-2在你必须建立你的系外玩家媒体来源:-
// Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), bandwidthMeter);
// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource("Pass Your Video Url");
// Prepare the player with the source.
player.prepare(videoSource);步骤3:-检查此条件
if (this.currentPosition > 0) {
player.seekTo(this.currentPosition);
this.currentPosition = 0;
player.setPlayWhenReady(true);
} else {
player.setPlayWhenReady(true);
}这是很好的工作,你必须看你的视频在哪里,你还剩下。
步骤4:-如果你的质量不好的话,那时候用的是方法。
public int getWifiLevel()
{
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(linkSpeed, 5);
return level;
}基于wifi级别或链接速度,您可以决定它是低连接还是高连接互联网。
https://stackoverflow.com/questions/59819959
复制相似问题