Home » Android » android – Video playback gives black screen but with sound

android – Video playback gives black screen but with sound

Posted by: admin June 15, 2020 Leave a comment


I’m stumped.

I’m trying to play video with the Media Player but while the audio plays, all I get is a black window.

I’ve seen other posts about this problem but I haven’t been to find a solution. I have tried to follow their suggestions.

The mediaplayer is prepared before playback. The surface holder was created and set to the media player’s display before playback.

Tested on a Samsung Galaxy Tab and a Samsung Galaxy S.

I’m compiling against API level 7.

The video itself can be played in device’s video application from the sdcard, so it should be compatible.

The surface view is not the same size as the video. So that might be an issue. Do I need to do something about that or is stretching handled automatically?

Here’s what I have in my initialization:

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, height);
lp.leftMargin = x;
lp.topMargin = y;
mSurfaceView = new SurfaceView(mActivity);
mLayout.addView(mSurfaceView, lp);

mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(assetDescriptor.getFileDescriptor(), assetDescriptor.getStartOffset(), assetDescriptor.getLength());

and here are my callbacks:

public void onPrepared(MediaPlayer mp)

public void surfaceCreated (SurfaceHolder holder)

What’s frustrating is that a version of the code was working properly a while ago, but now it’s not.

How to&Answers:

I had a similar problem, and was related to the video format (codec MP4, WMV, AVI, etc).

Try running the video on default player of the Android, see if that works. If not works, then it may be problem in video codec.

Do not try to run the video on players like VLC or Player MX, they have embedded codec.