Android VideoView black screen

前端 未结 22 1803
清歌不尽
清歌不尽 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:23

    Modifying @emmgfx's answer worked for me:

    videoView.setBackgroundColor(Color.WHITE)
    videoView.start()
    Timer().schedule(100){
      videoView?.setBackgroundColor(Color.TRANSPARENT)
    }
    

    Trick is to delay the video view untill video loads. PS : It's kotlin.

    0 讨论(0)
  • 2020-11-27 13:24

    I 've got same problem I just used videov.setBackgroundColor(Color.WHITE) and then onprepare i used Color.TRANSPARENT) white is still better than black for me

    0 讨论(0)
  • 2020-11-27 13:24

    I had the same issue. I found that the main reason for that was the use of FrameLayout as the parent layout. Use RelativeLayout as the parent layout of the VideoView

    0 讨论(0)
  • 2020-11-27 13:25

    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.

    0 讨论(0)
  • 2020-11-27 13:26

    This worked for me:

    videoView.setBackgroundColor(Color.WHITE); // Your color.
    videoView.start();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            videoView.setBackgroundColor(Color.TRANSPARENT);
        }
    });
    

    At least two years later, but I hope that was helpful.

    0 讨论(0)
  • 2020-11-27 13:26

    To avoid annoying flickering and black screen issues I wrote FrameVideoView.

    It takes benefits from 'placeholder solution' and (if your device is running API level 14 or higher) from TextureView, which is much more efficient than VideoView.

    I wrote article on our blog to cover what it actually does.

    It's simple to use:

    Add FrameVideoView to layout:

    <mateuszklimek.framevideoview.FrameVideoView
        android:id="@+id/frame_video_view"
        android:layout_width="@dimen/video_width"
        android:layout_height="@dimen/video_height"
      />
    

    find its instance in Activity and call corresponding methods in onResume and onPause:

    public class SampleActivity extends Activity {
    
      private FrameVideoView videoView;
    
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple);
    
        String uriString = "android.resource://" + getPackageName() + "/" + R.raw.movie;
        videoView = (FrameVideoView) findViewById(R.id.frame_video_view);
        videoView.setup(Uri.parse(uriString), Color.GREEN);
      }
    
        @Override
        protected void onResume() {
          super.onResume();
          videoView.onResume();
        }
    
        @Override
        protected void onPause() {
          videoView.onPause();
          super.onPause();
        }
      }
    
    0 讨论(0)
提交回复
热议问题