问题描述
我的代码如下:
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 topercent 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 的缓冲百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!