Lingviston
Lingviston

Reputation: 5671

How to display progress bar while MediaController loads video (live streaming) and not playing it?

Here's my activity code:

public class VideoActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_video);

        VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri video = Uri
                .parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
    }
}

While video is buffering and not played I want to display progress bar. How can I do it?

Upvotes: 1

Views: 3420

Answers (2)

adboco
adboco

Reputation: 2870

Set an OnPreparedListener and dismiss the dialog there:

Declare the progress dialog in your activity:

private static ProgressDialog progressDialog;

Then in onCreate method:

...
progressDialog = ProgressDialog.show(this, "", "Loading...", true);
videoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer arg0) {
        progressDialog.dismiss();
        videoView.start();
    }
});

Upvotes: 2

Enoobong
Enoobong

Reputation: 1734

Check the new Lines Added should do what you intend.

    public class VideoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_video);

    VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    Uri video = Uri
            .parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
    videoView.setMediaController(mediaController);
    // New Line 
    ProgressDialog pDialog = ProgressDialog.show(this, "", "Loading Video");
    videoView.setVideoURI(video);
    //New Line Added
    pDialog.dismiss
    videoView.start();
}
}

Upvotes: 0

Related Questions