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
    // start streaming/playing the video

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

    videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        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


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

New Tech Talk: Metrics, Metrics Everywhere
New Tech Talk: Metrics, Metrics Everywhere

If you don’t measure it, you can’t optimize it. Coda Hale, Infrastructure Architect at Yammer, talks about ...

SpringOne 2021

Register Now