16

i am working on an application where i need to play video from a remote server as live stream.

which is done by me successfully. i managed every thing in my app.

but when video is loading i need to show a progress dialog over VideoView.

i tried using OnPreparedListener as "how to show the progress bar before playing the video"

@Override
public void onPrepared(MediaPlayer mp) {
    progressbar.setVisibility(View.GONE);
    mp.start();

}

but video play after 5-7 Sec of progressbar gone. i searched a lot on Google but not found any solution for it.

Could anyone help me.

Thanks in Advance.

Community
  • 1
  • 1
  • and also my video view is transparent until video is playing. –  Apr 12 '13 at 13:10
  • i have observed that 'onPrepared' Listener called immediately when i click on button but video play after 5-6 sec. why this time interval? –  Apr 13 '13 at 05:01

2 Answers2

40

have a look this one solved my problem hope help you also..

http://www.quicktips.in/how-to-show-progressbar-while-loading-a-video-in-android-videoview/

 progressbar.setVisibility(View.VISIBLE);

 videoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {



                mp.start();

                mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {

                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int arg1, int arg2) {
                        // TODO Auto-generated method stub
                        Log.e(TAG, "Changed");
                        progressbar.setVisibility(View.GONE);
                        mp.start();
                    }
                });


            }
        });

:)

Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
  • great dude.. solved my problem.. but could you please explain this code piece.. i want to know what is the exact process behind this code.. –  Aug 29 '13 at 04:40
  • 1
    @DevelopSmart sure, as per documents OnPreparedListener() is interface definition for a callback to be invoked when the media source is ready for playback. just check the start moment of video view using OnVideoSizeChangedListener() and hide your progress bar.. – Deepak Swami Sep 03 '13 at 19:58
  • how we know if the video start to render again and i need to show the loader every time if the video is rendering...is there any other state of video play in this code? – Jayesh M Jul 30 '18 at 04:15
2

Unforgettably there is no OnStart Listener expose by Android. After Prepared State, the MediaPlayer goes into Started State once playback started.

But in Prepared State only you should have sufficient buffer to play. Can you use setOnBufferingUpdateListener (MediaPlayer.OnBufferingUpdateListener listener) and print percentage of buffer. So that way you can see, if in Prepared State you have enough buffer or not.

Munish Katoch
  • 517
  • 3
  • 6