17

I don't find any solution to show a loading animation (or just an imageView) before a VideoView start to play : during the video is buffering.

Does anyone have a clue ?

Thanks.

magiccyril
  • 657
  • 1
  • 6
  • 14
  • 1
    Hard to understand you, but I think what you want is an indeterminate progress bar. – user432209 May 02 '11 at 16:31
  • Sorry if I'm not clear. My VideoView play a video in streaming. So when I the activity start I only see a black screen while the video is buffering. If you look to YouTube app by instance, there's an animation explaining that the video is loading, and I don't think that it's an inderterminate progress bar. How could I detect that the video is buffering ? Thanks – magiccyril May 02 '11 at 16:47

3 Answers3

45

Or you can just use Progress Dialog;

public class VideoEkrani extends Activity {

    VideoView ekran;
    String kaynakYolu = "http://commonsware.com/misc/test2.3gp";
    ProgressDialog progDailog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sayfa_video_goruntule);


        ekran = (VideoView) findViewById(R.id.videoViewESPU);
        ekran.setMediaController(new MediaController(this));
        ekran.setVideoURI(Uri.parse(kaynakYolu));
        ekran.requestFocus();
        ekran.start();

        progDailog = ProgressDialog.show(this, "Please wait ...", "Retrieving data ...", true);

        ekran.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                progDailog.dismiss();
            }
        });
    }
}
Mehmet Emre Portakal
  • 1,774
  • 21
  • 37
  • 3
    You have saved my life!! Thanks a million-trillion times @Amourreux. I know its kind of inappropriate to thank people on stack-overflow, but its also insufficient to let it go without telling people, that if they are facing trouble in VideoView, this one is the solution.! :) – Prachi May 12 '14 at 11:39
  • what if the user seek video, how can you put a progressBar until it stream again ?? – Mr.G Oct 27 '14 at 11:45
  • @Mr.G i'm not sure but i thing that event is managed by MediaController. again i am not sure. if i understand your question correctly. if not, it might be good and new question post. – Mehmet Emre Portakal Oct 27 '14 at 12:14
  • thanks , ill check it , if not ill put a new quesiton – Mr.G Oct 28 '14 at 04:30
7

You cant detect the video buffer using OnBufferingUpdateListener on MediaPlayer. If you use VideView set that listener inside OnPreparedListener.

videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
   public void onPrepared(MediaPlayer mp) {
     mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
       @Override
       public void onBufferingUpdate(MediaPlayer mp, int percent) {
         if(percent == 100){
           //video have completed buffering
         }
       }
     });
   }
});
Atiatul Maula
  • 144
  • 1
  • 3
7

Finally I found the method setOnPreparedListener() on VideoView.

I added a ProgressBar inside my layout, and hide it with the OnPreparedListener

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
magiccyril
  • 657
  • 1
  • 6
  • 14