VideoView black flash before and after playing

前端 未结 14 2250
谎友^
谎友^ 2020-12-09 04:04

I have a VideoView which I want to use to play a movieclip. I use it like this to play it and it works.

VideoView vv = new VideoView(this);
vv.setVideoURI(Ur         


        
14条回答
  •  猫巷女王i
    2020-12-09 04:20

    My workaround for this diabolical bug utilised a blank View with the background colour of choice over the top of the VideoView.

    
    

    then in my code I did this:

            video = (VideoView) findViewById(R.id.video);
            // set the video URI, passing the vSourse as a URI
            video.setVideoURI(Uri.parse(vSource));
            video.setZOrderOnTop(false);
    
            SurfaceHolder sh = video.getHolder();
            sh.setFormat(PixelFormat.TRANSPARENT);
    
            ctlr = new BCDMediaController(this);
            ctlr.setMediaPlayer(video);
            video.setMediaController(ctlr);
            video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {              
                @Override
                public void onCompletion(MediaPlayer mp) {
                    closeActivity();
                }
            });
    
            blankView = findViewById(R.id.blankView);
    
            video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {    
                    blankView.postDelayed(new Runnable() {
                            public void run()
                            {
                                blankView.setVisibility(View.GONE);
                            }
                        }, 500);                    
                }
            });
    
            video.start();
            video.requestFocus();
    

    That got rid of the beginning black flash for me. Then for the end black flash, I did this:

    private void closeActivity() {  
    blankView.setVisibility(View.VISIBLE);        
        blankView.postDelayed(new Runnable() {
            public void run()
            {
                video.setOnCompletionListener(null);
                video.stopPlayback();
                video.suspend();
                VideoPlayerViewController.this.finish();
            }
        }, 1);    
    }
    

提交回复
热议问题