开发者

Android Streaming Video - Need Aspect Ratio

开发者 https://www.devze.com 2023-03-10 20:25 出处:网络
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\'

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 voi开发者_Go百科d startVideoPlayback() {
    Log.v(TAG, "startVideoPlayback");
    holder.setFixedSize(mVideoWidth, mVideoHeight);
    mMediaPlayer.start();
}

Thoughts?


try to use setLayoutParams() in OnPrepared()

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

精彩评论

暂无评论...
验证码 换一张
取 消