Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android loading animation before VideoView start

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.

like image 240
magiccyril Avatar asked May 02 '11 16:05

magiccyril


3 Answers

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();
            }
        });
    }
}
like image 197
Mehmet Emre Avatar answered Nov 01 '22 15:11

Mehmet Emre


Finally I found the method setOnPreparedListener() on VideoView.

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

like image 42
magiccyril Avatar answered Nov 01 '22 15:11

magiccyril


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
         }
       }
     });
   }
});
like image 7
Atiatul Maula Avatar answered Nov 01 '22 14:11

Atiatul Maula