Search code examples
androidsurfaceviewvisual-artifacts

SurfaceView artifacts


My layout.xml consists of a FrameLayout with a few TextViews and Buttons, that I use like a MediaController, and it also contains a SurfaceView. In the code I create a MediaPlayer and sets the SurfaceView's SurfaceHolder as the Display like this :

surfaceView = (SurfaceView) findViewById(R.id.video_surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
mediaPlayer.setDisplay(surfaceHolder);

This works great for displaying video but when I try to call the :

overLayTextView.setVisibility(View.Gone);

The overLayTextView is still visible. Ive tried to retrieve the view state of the overLayTextView and it is set to Gone. I think the SurfaceView doesn't update its drawing state until when it feels like (usually happens after 20+ seconds). So my question is if there is anything I can call on the SurfaceView or SurfaceHolder to notify them that they should "redraw" some of their content? (obviously not the video).


Solution

  • I just realized the thread updating the overlays with video info still called :

    overLayTextView.setText(mediaPlayer.getDuration());
    

    In "none-surface" layouts this doesn't matter since the View is hidden but in SurfaceView this is apparantly not the case (at least on some devices, strangely enough).

    Hope this helps, cheers.