0

Videoview is not showing video but is playing sound,It shows Black screen every time. I am running Android 4.0.I am running this on emulator.

This is my xml file.

<VideoView
android:id="@+id/myVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"/>

.java file

VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress ="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";

Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView); 
vidView.setMediaController(vidControl);
vidView.setZOrderOnTop(false); 

vidView.start();

Please help I am stuck on it from one week. Searched a lot but nothing worked.

Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
Momina Nisar
  • 11
  • 1
  • 4

5 Answers5

1

I know this might be a litle old but Iam posting this update just in case someone run with the same issue that I did. This is also an improved answer to the one above.

Anyway, What you have to do is to put the: vidView.setZOrderOnTop(true); statement AFTER the vidView.start(); statement. I was having the same problem with the white/gray screen showing(that you mentioned on the comments) even though the video was playing in the background. I think that is because your setZOrderOnTop was set before you start the video.If you start the video first then set the setZOrderOnTop will fix it for you like it did for me. Hope that helps.

vidView.start();
vidView.setZOrderOnTop(true);
Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
Fidel
  • 1,173
  • 11
  • 21
  • vidView.setZOrderOnTop(true) by itself didn't work me. Moving this line after vidView.start() was the key. Thanks! – user2966445 May 09 '16 at 14:32
1

solution 1:

videoView.setZOrderOnTop(true);

this will set the videoview to the top layer; In other words: block everything under it.

solution 2:

videoView.setBackgroundColor(Color.TRANSPARENT);

solution 3:

sometimes this is related about your apptheme; In my case, I changed the apptheme from "@style/AppTheme" to "@android:style/Theme.NoTitleBar.Fullscreen" fix my problem.

liu zhiyuan
  • 171
  • 1
  • 3
0

change vidView.setZOrderOnTop(false) to true so it will be vidView.setZOrderOnTop(true);

Reference : Video is not showing on VideoView but i can hear its sound `

Community
  • 1
  • 1
0

I had the exact same problem and solved it with the following:

videoView.setBackgroundColor(Color.TRANSPARENT)
Janwilx72
  • 502
  • 4
  • 18
0

Create a custom VideoPlayer by extending VideoView class and use it:

public class VideoPlayer extends VideoView {

public VideoPlayer(Context context) {
    super(context);
    init();
}

@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        TyrooLog.i(TAG, "onMeasure");
        int width = getDefaultSize(videoWidth, widthMeasureSpec);
        int height = getDefaultSize(videoHeight, heightMeasureSpec);
        if (videoWidth > 0 && videoHeight > 0) {
            if (videoWidth * height > width * videoHeight) {
                TyrooLog.i(TAG, "video too tall, correcting");
                height = width * videoHeight / videoWidth;
            } else if (videoWidth * height < width * videoHeight) {
                TyrooLog.i(TAG, "video too wide, correcting");
                width = height * videoWidth / videoHeight;
            } else {
                TyrooLog.i(TAG, "aspect ratio is correct: " + width+"/"+height+"="+mVideoWidth+"/"+mVideoHeight);
            }
        }
        TyrooLog.i(TAG, "setting size: " + width + 'x' + height);
        setMeasuredDimension(width, height);
    }
}