首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止ExoPlayer中改变最大比特率的再缓冲

防止ExoPlayer中改变最大比特率的再缓冲
EN

Stack Overflow用户
提问于 2020-01-20 09:07:43
回答 1查看 2.3K关注 0票数 7

当用户改变视频质量时,我使用setMaxBitrate提供的DefaultTrackSelector来设置最大比特率。

代码语言:javascript
复制
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

但似乎还没有任何解决办法。如能就这一问题提供任何帮助,将不胜感激。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-01-23 11:53:36

您可以轻松地完成it.You,必须已经使用了ExoPlayer,而ExoPlayer则提供了一个seekTo()方法。

在此方法中,您应该只传递玩家当前的位置,在此之前停止。

步骤:-1你必须改变你的质量像144 P到720 p。在此更改时间上,您必须存储当前的ExoPlayer当前位置,使用以下方法:-

代码语言:javascript
复制
Private int currentPosition=player.getCurrentPosition();

步骤-2在你必须建立你的系外玩家媒体来源:-

代码语言:javascript
复制
// 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:-检查此条件

代码语言:javascript
复制
if (this.currentPosition > 0) {
        player.seekTo(this.currentPosition);
        this.currentPosition = 0;
        player.setPlayWhenReady(true);
    } else {
        player.setPlayWhenReady(true);
    }

这是很好的工作,你必须看你的视频在哪里,你还剩下。

步骤4:-如果你的质量不好的话,那时候用的是方法。

代码语言:javascript
复制
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级别或链接速度,您可以决定它是低连接还是高连接互联网。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59819959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档