该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public void setVideoParams(MediaPlayer mediaPlayer, boolean isLand) {
//获取surfaceView父布局的参数
ViewGroup.LayoutParams rl_paramters = mRlVideo.getLayoutParams();
//获取SurfaceView的参数
ViewGroup.LayoutParams sv_paramters = mSvVideo.getLayoutParams();
//设置宽高比为16/9
float screen_widthPixels = getResources().getDisplayMetrics().widthPixels;
float screen_heightPixels = getResources().getDisplayMetrics().widthPixels * 9f / 16f;
//取消全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (isLand) {
screen_heightPixels = getResources().getDisplayMetrics().heightPixels;
//设置全屏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
rl_paramters.width = (int) screen_widthPixels;
rl_paramters.height = (int) screen_heightPixels;
//获取MediaPlayer的宽高
int videoWidth = mediaPlayer.getVideoWidth();
int videoHeight = mediaPlayer.getVideoHeight();
float video_por = videoWidth / videoHeight;
float screen_por = screen_widthPixels / screen_heightPixels;
//16:9 16:12
if (screen_por > video_por) {
sv_paramters.height = (int) screen_heightPixels;
sv_paramters.width = (int) (screen_heightPixels * screen_por);
} else {
//16:9 19:9
sv_paramters.width = (int) screen_widthPixels;
sv_paramters.height = (int) (screen_widthPixels / screen_por);
}
mRlVideo.setLayoutParams(rl_paramters);
mSvVideo.setLayoutParams(sv_paramters);
}