0

In my app, I'm displaying local videos using a SurfaceView. However, I noticed a strange (rare) bug when switching between videos: they both overlap.

Screenshot: Screenshot

Sometimes the old video (top black video) stays still and sometimes it still continues playing. (with no audio)

How do I fix this? I was previously using a VideoView and still had this issue. My VideoFragment is recreated everytime I open a new video. I tried releasing the video in the onPause() of the fragment but still no luck.

@Override
public void onPause()
{
    super.onPause();

    if (player != null && Video.getDownloaded())
    {
        if(player.isPlaying())
            player.stop();

        controller.hide();
        player.release();
    }
}

Thanks in Advance,

~Pkmmte Xeleon

Pkmmte
  • 2,822
  • 1
  • 31
  • 41
  • How are you switching between the videos? Do you have only one `SurfaceView` (right answer) or are you trying to have more than one `SurfaceView` (wrong answer)? – CommonsWare Sep 06 '13 at 00:15
  • I initialize a new Fragment to replace the current one. I only have one SurfaceView. – Pkmmte Sep 06 '13 at 00:16
  • Since only one `SurfaceView` cannot overlap itself, clearly you must have more than one. Are you swapping fragments, each of which having a `SurfaceView`? – CommonsWare Sep 06 '13 at 00:17
  • Yes, I'm swapping fragments with each having a SurfaceView. – Pkmmte Sep 06 '13 at 00:19

2 Answers2

2

Simply put, a SurfaceView is a weird "widget". Treat them carefully.

Try reorganizing your UI to have a single SurfaceView (or VideoView if you roll back to that). For example, that could be fixed below your action bar tabs, with the rest of your content inside a fragment beneath it. On a tab change, update the video and replace the main fragment.

Or, if you are only supporting API Level 14+, try TextureView instead.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, your first suggestion seems to have worked! However, I'd like to give TextureView a try. I haven't heard of it until now but I can't find an equivalent for mMediaPlayer.setSurface(). =/ (I have a SurfaceTexture now rather than a Surface or SurfaceHolder) – Pkmmte Sep 06 '13 at 01:48
  • @Pkmmte: http://stackoverflow.com/questions/10736517/playing-video-on-textureview https://gist.github.com/kswlee/5627632 http://pastebin.com/NDkCdh5t – CommonsWare Sep 06 '13 at 10:48
  • @CommonsWare hello, In my case I am playing Video as an Live Wallpaper, and over that in app playing Video in Fragment...so here before to appear video fragment it show BG(live wallpaper) for a moment then it start video...any suggestion here. – CoDe Oct 29 '13 at 13:49
0

I use a surfaceView as the surface for video or draw something on the surface. And when I switch the Activity very quickly, e.g. switch to Activity B and switch back very quickly, there are two surface overlap.

dumpsys SurfaceFlinger,there are two surfaceview in the output.

I try to modify the surfaceflinger, when the destroy surface called, evenif it is detached from layerbase, also destroy it.

And this issue dispeared.

Jacky
  • 1