如何在 Android 上获得 VideoView 的缓冲百分比 [英] How to get buffering percent of VideoView on Android

查看:33
本文介绍了如何在 Android 上获得 VideoView 的缓冲百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下:

Uri uri = Uri.parse(URL);
video.setVideoURI(uri);
video.start();

我使用 VideoView 播放流视频.
该视频是一个 VideoView.
我想在 MediaPlayer 中获得像 setOnBufferingUpdateListener 这样的缓冲百分比.

I use VideoView to play a stream video.
The video is a VideoView.
And I want to get the buffering percent like setOnBufferingUpdateListener in MediaPlayer.

MediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        //buffering is percent
    }
});

我该怎么做?

推荐答案

为你的 VideoView 实现这个方法:

Implement this method for your VideoView:

public abstract void onBufferingUpdate (MediaPlayer mp, int percent)

mp 是更新涉及的 MediaPlayer百分比是到目前为止已缓冲或播放的内容的百分比 (0-100).

mp is the MediaPlayer the update pertains to percent is the percentage (0-100) of the content that has been buffered or played thus far.

来源

您可以在开始加载视频之前添加一个进度条,然后在此方法中不断更新它.一旦缓冲完成(在 onPreparedListener 中),只需关闭进度条.

You can add a progressbar before u start loading the Video, and then keep updating it inside this method. And once the buffering is complete (in onPreparedListener), just dismiss the progressbar.

这篇关于如何在 Android 上获得 VideoView 的缓冲百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆