我正在使用Android MediaPlayer演示视频。我有流媒体视频640x480。我只是希望视频尽可能大(在任何设备方向),同时保持纵横比。我无法做到这一点。它只是延伸到整个屏幕。布局中的SurfaceView不会在“fill_parent”或“wrap_content”中保持纵横比。当我检查(并在代码中更改表面大小时,它似乎忽略了任何更改。而在这段代码中,我被告知我的视频大小为:176 x 144.这是奇怪的。
public void onVideoSizeChanged(MediaPlayer mp, int width, int height)
{
Log.v(TAG, "onVideoSizeChanged called");
Log.v(TAG, "Surface Width: " + width + " Surface Height: " + height);
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
Log.v(TAG, "Surface Width: " + mVideoWidth + " Surface Height: " + mVideoHeight);
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
这是我尝试更改大小的地方:
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
思想?
答案 0 :(得分:0)
尝试在OnPrepared()
中使用setLayoutParams()public void onPrepared(MediaPlayer mp) {
...
mSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(vWidth, vHeight));
...
};