Android VideoView black screen

前端 未结 22 2141
清歌不尽
清歌不尽 2020-11-27 12:55

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

22条回答
  •  孤街浪徒
    2020-11-27 13:31

    This one works for me :

    In XML : VideoView hide behind a Relative layout with white Background

        
        
        
    

    and in Activity : onCreate

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acceuil);
        myVideo = (VideoView)  findViewById(R.id.myVideo);
        mask = (RelativeLayout)  findViewById(R.id.mask);
        String path = "android.resource://" 
          + getPackageName() + "/" + R.raw.anim_normal;
        myVideo.setVideoURI(Uri.parse(path));
        myVideo.start();
    }
    

    onStart :

     public void onStart() { 
        final long time = System.currentTimeMillis();
        super.onStart();
        new CountDownTimer(5000, 100) { 
        @Override
            public void onTick(long l) {
    
                long time2 = System.currentTimeMillis();
                if((time2 - time) > 500) {
                    mask.setVisibility(View.GONE);
                }
            }
    
    }.start();
    

    Hope this helps.

提交回复
热议问题