8

I am playing the MP4 in android phone with the below code:

VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        //  Set video link (mp4 format )
        File file2 = new File("/sdcard/Alone.mp4");
        Uri video = Uri.fromFile(file2);

        videoView.setVideoURI(video);
        videoView.start();

But while i playing this video, before starting of that video i seen one black screen for 0.2 or 0.3 second.

I dont want that black screen to appear.

So for that what should i have to do ? I want is, while i play the video, there should be only screen of the video, no any other black screen should be there before playing it ?

Thanks.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • Possible duplicate of [android-black screen on displaying video by using VideoView](https://stackoverflow.com/questions/28577704/android-black-screen-on-displaying-video-by-using-videoview) – Roger Alien Sep 05 '17 at 21:04

1 Answers1

17

My solution to this problem was this line:

videoView.setZOrderOnTop(true);

This changes the black screen with a momentary transparent video. You can easily fix this other issue by setting an ImageView with the first video frame behind the VideoView.

willy
  • 490
  • 4
  • 11
  • In my case, this property doesn't even display the video. I have to use `setZOrderMediaOverlay`, which overrides any previous call to `setZOrderOnTop`. If i use only `setZOrderOnTop` then the video doesn't show up, you only hear the audio, but it also prevents the black screen from appearing – Rahul Dole Jul 23 '14 at 07:22
  • @willy hey, just wanted to say thank you for your answer, I've been searching it for so long, and the only some what solution most people said was to take a photo over the video, but yours works great, thank you, up voted! – Lidor Eliyahu Shelef Nov 11 '19 at 19:42