Android 流媒体视频 - 需要宽高比
我正在使用 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();
}
想法?
I am using the Android MediaPlayer demo for Video. I have streaming video 640x480. I simply want the video to be as large as it can be (in whatever device orientation) while keeping aspect ratio. I can't get it to do this. It simply stretches across the entire screen. My SurfaceView in the layout doesn't maintain aspect ratio in either "fill_parent" or "wrap_content". When I check (and change the surface size in code, it seems to ignore any changes. And what is weird is I am told in this code that my video size is : 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();
}
}
This is where I try and change the size:
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在 OnPrepared() 中使用 setLayoutParams()
try to use setLayoutParams() in OnPrepared()