How to show progress bar until video play in live stream Android?

16,146

Solution 1

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();
                    }
                });


            }
        });

:)

Solution 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.

Share:
16,146
Admin
Author by

Admin

Updated on June 06, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • Admin
    Admin over 10 years
    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..
  • Deepak Swami
    Deepak Swami over 10 years
    @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..
  • Jayesh M
    Jayesh M almost 6 years
    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?