问题
I have a video view to play video by using url which comes from server. I want video to be played once buffering reaches 20% . So i have added listener for setOnBufferingUpdateListener to mediaplayer like below.
Uri video = Uri.parse(videoUrl);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.setOnBufferingUpdateListener(Activity);
progressVideoView.setVisibility(View.GONE);
videoView.start();
}
});
videoView.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.d("Error", "------>error"+what+"/"+extra);
if (extra != 0) {
Utilities.showToast(ViewVlipActivity.this,
"Sorry, This video cannot be played.");
}
return false;
}
});
videoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
My onbuffer listener as follows
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
//seekbar.setSecondaryProgress(percent);
Log.d("Buffer", "------>Buffer"+percent);
}
My problem is i could not get any log in buffer listener until the buffer ends. My video have duration of around 2 minute and it's MP4 video.
来源:https://stackoverflow.com/questions/29029597/how-to-startplay-video-once-buffer-reaches-20-in-android-video-view