Embedding VideoViews in your UI: Caution!

August 3, 2011 Ryan Richard

Using a VideoView to play streaming videos is quite easy on Android, and the class provides handy callbacks to manage your UI too. For example:

    // set the Uri of the video
    videoView.setVideoURI(Uri.parse(videoUriString));
    // start streaming/playing the video
    videoView.start();

    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            // about to start playing
        }
    });

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            // reached the end of the video
        }
    });

VideoViews can be embedded into your layouts and sized any way that you’d like. However, there is one serious limitation.

According to Romain Guy, SurfaceViews (such as VideoView, etc.) inside ScrollViews (or ListView, etc.) are not supported by Android.

For example, playing a video using a VideoView inside of a row of a ListView seems to work at first, until the user tries to scroll the list. As soon as the list starts to scroll, the video turns black. It keeps playing in the background but you can’t see it anymore because it renders the rest of the video as a black box.

As another example, when the VideoView is scrolled so that it is partially off-screen at the time that the video starts playing, the VideoView does not render the video in the correct location on screen, causing the video to appear mostly black.

So be careful where you decide to put your VideoViews. At first it seems that they can go anywhere, but they cannot.

About the Author

Biography

More Content by Ryan Richard
Previous
Installing Rails development stack on OS X Lion
Installing Rails development stack on OS X Lion

I recently started working with OS X Lion at home and started researching the best way to get a Ruby on Rai...

Next
YouBeauty is seeking a talented Rails developer
YouBeauty is seeking a talented Rails developer

At Pivotal Labs, one of the services we provide our clients is helping them interview and hire. Pivotal Lab...