Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView black screen

I have been looking for a way to get rid of the nasty black initial screen on a VideoView before the start() method is run.

I have tried with background image on the widget but it doesn't work as expected at all. I have also tried putting an image of the first frame in the video on top of the VideoView and hiding it after the start() method. Adding an onPrepared listener to start the video and then hide the image. This works but there is a horrible flicker in the transition and I don't know how to get rid of it.


Adding the MediaController had no effect at all. The problem persists (I still see the black flicker) and I don't want to have the video controls visible at all. My code looks like this:

    VideoView vSurface= (VideoView) findViewById(R.id.surfaceView1);     vSurface.setVideoURI(Uri.parse("android.resource://com.mypackage/" + R.raw.video1));     vSurface.setVisibility(View.VISIBLE);     vSurface.setOnPreparedListener(this);     vSurface.setDrawingCacheEnabled(true);     vSurface.setOnErrorListener(this); 
like image 593
SergioM Avatar asked Mar 19 '12 05:03

SergioM


1 Answers

I meet the same problem, and solve it with the accepted solution above plus this:

  @Override   public void onPrepared(MediaPlayer mp) {     mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {       @Override       public boolean onInfo(MediaPlayer mp, int what, int extra) {         Log.d(TAG, "onInfo, what = " + what);         if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {           // video started; hide the placeholder.           placeholder.setVisibility(View.GONE);           return true;         }         return false;       }     }); 

I think onPrepared just means the video is ready to play, but not means video started playing. If hide placeholder in onPrepared, the screen still show a black screen.

On my Note3 and Nexus, this solution works well.

like image 146
wizardlee Avatar answered Oct 14 '22 03:10

wizardlee