我想在横向模式下播放具有纵横比的视频。所以,我写了以下。
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); '
因此,视频以横向播放,但位置仍然存在。我希望那个位置是中心。如何实施?