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

spe*_*tak 5 android video-streaming media-player

我正在使用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();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试更改大小的地方:

private void startVideoPlayback() {
    Log.v(TAG, "startVideoPlayback");
    holder.setFixedSize(mVideoWidth, mVideoHeight);
    mMediaPlayer.start();
}
Run Code Online (Sandbox Code Playgroud)

思考?

cls*_*ung 0

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

public void onPrepared(MediaPlayer mp) {
   ...
   mSurfaceView.setLayoutParams(new LinearLayout.LayoutParams(vWidth, vHeight));
   ...
};
Run Code Online (Sandbox Code Playgroud)