我希望在横向模式下播放具有宽高比的视频。 所以,我写了以下内容。
landscape = true;
// Get the dimensions of the video
int videoWidth = mediaPlayer.getVideoWidth();
int videoHeight = mediaPlayer.getVideoHeight();
float videoProportion = (float) videoWidth / (float) videoHeight;
// Get the width of the screen
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
float screenProportion = (float) screenWidth / (float) screenHeight;
// Get the SurfaceView layout parameters
lp = surfaceView.getLayoutParams();
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
mVideoWidth = lp.width;
mVideoHeight = lp.height;
// Commit the layout parameters
surfaceView.setLayoutParams(lp);
holder.setFixedSize(mVideoWidth, mVideoHeight); '
所以,视频在风景中播放,但位置仍然存在。 我希望那个位置是中心。 如何实施?