Abh*_*k V 7 android kotlin exoplayer exoplayer2.x
当用户更改视频质量时,我使用setMaxBitrate提供DefaultTrackSelector来设置最大比特率。
val parameters = defaultTrackSelector.buildUponParameters()
.setMaxVideoBitrate(bitrate)
.build()
defaultTrackSelector.parameters = parameters
Run Code Online (Sandbox Code Playgroud)
但是一旦调用此函数,当前缓冲区就会被丢弃,并立即显示重新缓冲。有什么方法可以继续使用旧缓冲区播放并像 YouTube 一样使用新的比特率设置加载新缓冲区?
这个问题已经在这里讨论过:https : //github.com/google/ExoPlayer/issues/3522 https://github.com/google/ExoPlayer/issues/2250
但目前似乎还没有任何解决方案。任何有关此问题的帮助将不胜感激。提前致谢。
小智 2
您可以轻松做到这一点。您必须ExoPlayer已经使用并且ExoPlayer提供了一种seekTo()方法。
在此方法中,您应该仅传递您之前停止的玩家当前位置。
步骤:-1
您必须将质量更改为 144p 至 720p。在这个更改时间,您必须ExoPlayer使用以下方法存储当前位置:-
Private int currentPosition=player.getCurrentPosition();
Run Code Online (Sandbox Code Playgroud)
步骤-2 在你必须构建你的 exoplayer 媒体源之后:-
// 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);
Run Code Online (Sandbox Code Playgroud)
第 3 步:- 检查此条件
if (this.currentPosition > 0) {
player.seekTo(this.currentPosition);
this.currentPosition = 0;
player.setPlayWhenReady(true);
} else {
player.setPlayWhenReady(true);
}
Run Code Online (Sandbox Code Playgroud)
效果很好,您必须在剩下的位置观看视频。
步骤 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;
}
Run Code Online (Sandbox Code Playgroud)
根据 wifi 级别或链接速度,您可以决定它是否具有低连接或高连接互联网。
| 归档时间: |
|
| 查看次数: |
1601 次 |
| 最近记录: |