我需要在Android上播放以下视频(作为信息流):http://goo.gl/Dc6tzA
它符合此页面指出的所有要求:http://developer.android.com/guide/appendix/media-formats.html
其编解码器为:H264 - MPEG4 AVC
它的容器是:.mp4
我甚至检查过(用http://atomicparsley.sourceforge.net/)看moov原子是否在mdat原子之前和ftyp原子之后,如上页所示:
“对于3GPP和MPEG-4容器,moov原子必须先于任何mdat原子,但必须接替ftyp原子。”
一切都很好。但视频不播放。它调用MediaPlayes的onPrepared回调,但它没有播放。此外,mediaPlayer.getVideoWidth()和mediaPlayer.getVideoHeight()(在下面的代码中)返回0(即使视频是640x360)。
按照我的onPrepared方法:
@Override
public void onPrepared(MediaPlayer mediaplayer) {
width = mediaPlayer.getVideoWidth();
height = mediaPlayer.getVideoHeight();
//Get the width of the screen
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
//Get the SurfaceView layout parameters
android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams();
//Set the width of the SurfaceView to the width of the screen
lp.width = screenWidth;
//Set the height of the SurfaceView to match the aspect ratio of the video
//be sure to cast these as floats otherwise the calculation will likely be 0
lp.height = (int) (((float)height / (float)width) * (float)screenWidth);
//Commit the layout parameters
surfaceView.setLayoutParams(lp);
playPauseImageButton.setImageResource(R.drawable.ic_media_pause);
//if (width != 0 && height != 0) {
surfaceHolder.setFixedSize(width, height);
seekBar.start();
mediaPlayer.start();
//}
playPauseImageButton.setEnabled(true);
}
我也设置了onError回调,但它永远不会被调用。任何人的想法?