VideoView black flash before and after playing

前端 未结 14 2227
谎友^
谎友^ 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条回答
  •  旧巷少年郎
    2020-12-09 04:45

    My variation on the @tommyd theme:

    Set the drawable to a static video frame, then spam the message queue. After some time, clear the drawable so video frames render. Then, before completion, set the static image back.

        mMovieView.setBackgroundDrawable(bg);
        mMovieView.start();
    
        final int kPollTime= 25;
        mMovieView.postDelayed(new Runnable() {
    
            private final int kStartTransitionInThreshold= 50;
            private final int kStartTransitionOutThreshold= 250;
    
            private boolean mTransitioned= false;
            @Override
            public void run() {
                if (mMovieView.isPlaying()) {
                    if (mMovieView.getCurrentPosition() > kStartTransitionInThreshold && !mTransitioned) {
                        mMovieView.setBackgroundDrawable(null); // clear to video
                        mTransitioned= true;
                    }
    
                    if (mMovieView.getDuration() - mMovieView.getCurrentPosition() < kStartTransitionOutThreshold)
                        mMovieView.setBackgroundDrawable(bg);
                }
    
                mMovieView.postDelayed(this, kPollTime); // come back in a bit and try again
            }
        }, kPollTime);
    

提交回复
热议问题