开发者

Video playback gives black screen but with sound

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 开发者_JAVA百科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);
mSurfaceView.requestFocus();
mSurfaceView.setZOrderOnTop(true);
mSurfaceView.getHolder().addCallback(player);
mSurfaceView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mLayout.addView(mSurfaceView, lp);

mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(assetDescriptor.getFileDescriptor(), assetDescriptor.getStartOffset(), assetDescriptor.getLength());
mMediaPlayer.setOnErrorListener(player);
mMediaPlayer.setOnPreparedListener(player);
mMediaPlayer.prepare();                    

and here are my callbacks:

public void onPrepared(MediaPlayer mp)
{
    mMediaPlayer.start();
}


public void surfaceCreated (SurfaceHolder holder)
{
    mMediaPlayer.setDisplay(holder);
}

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜