【发布时间】:2011-09-10 04:55:40
【问题描述】:
我正在使用 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();
}
想法?
【问题讨论】:
标签: android video-streaming media-player