2011-06-07 63 views
5

我正在使用適用於視頻的Android MediaPlayer演示。我有流式視頻640x480。我只是希望視頻儘可能大(無論在哪個設備方向),同時保持寬高比。我無法做到這一點。它只是延伸到整個屏幕。佈局中的我的SurfaceView不會保持「fill_parent」或「wrap_content」中的寬高比。當我檢查(並更改代碼的表面尺寸,它似乎忽略任何更改,是什麼奇怪的是,我在此代碼,我的視頻大小是說:176×144Android流媒體視頻 - 需要的屏幕比例

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(); 
} 

思考

回答

0

嘗試使用setLayoutParams()在OnPrepared()

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