How to show ProgressBar while loading a video in Android VideoView

Author: | Posted in Android, Quick Tips 1 Comment

Tutorial for how to play video in Android VideoView and how to show ProgressBar while loading a video in VideoView.

Android provides a widget VideoView to play video files.

Here is the link for supported video formats for Android.

In this tutorial we will learn how to play video using android VideoView.
We can play video from our app resource folder, or we can play video from phone memory/sd card, or we can play video which is on server(live stream also) and how to show ProgressBar untill video play in VideoView.

Create a new Android project see here for insturction.
After that add VideoView and ProgressBar in layout(activity_main.xml) as shown below.

<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >
        android:layout_centerVertical="true" />
        android:visibility="gone" />

and in your activity file( use/define this VideoView, ProgressBar like this

public class MainActivity extends Activity {
    ProgressBar progressBar = null;
    VideoView videoView = null;
    String videoUrl = "video path here";
    Context context = null;
    public void onCreate(Bundle iclic) {
        context = null;
        videoView = (VideoView) findViewById(;
        progressBar = (ProgressBar) findViewById(;
        Uri videoUri = Uri.parse(videoUrl);
        videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
                    public void onVideoSizeChanged(MediaPlayer mp, int arg1,
                            int arg2) {
                        // TODO Auto-generated method stub

Set video uri in VideoView and start playing video in VideoView using start(); method, and set ProgressBar to visible so it look like that VideoView is loading.

VideoView takes some time to play video then set a OnPreparedListener() for VideoView so we can know when VideoView is being prepared.
The key-trick is place a OnVideoSizeChangedListener() in OnPreparedListener() to check the start moment of VideoView and hide your ProgressBar.

(Visited 7,160 times, 3 visits today)