Android 流媒体视频 - 需要宽高比

发布于 2024-11-14 10:35:40 字数 1149 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深空失忆 2024-11-21 10:35:40

尝试在 OnPrepared() 中使用 setLayoutParams()

public void onPrepared(MediaPlayer mp) {
   ...
   mSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(vWidth, vHeight));
   ...
};

try to use setLayoutParams() in OnPrepared()

public void onPrepared(MediaPlayer mp) {
   ...
   mSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(vWidth, vHeight));
   ...
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文