How to start (play) a video once when the buffer reaches 20% in Android view mode

I have a video view to play the video using the URL that comes from the server. I want the video to play as soon as buffering reaches 20%. So I added a listener for setOnBufferingUpdateListener to the media player, as shown 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 that I could not get any log in the listener buffer until the buffer runs out. My video lasts about 2 minutes, and the video is MP4.

+4
source share

Source: https://habr.com/ru/post/1432445/


All Articles