My videoview is working fine in portrait mode but in landscape it does not fit in full screen( i do not want to use layout-land). I am trying to change views programmatically but this is not working as expected. I tried to get the resolution of the device using below code:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
WindowManager wm =(WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
height = metrics.heightPixels
width = metrics.widthPixels
Testing on the devices with resolution 1080 * 1920 the value i am getting for height and width is 1080 and 1776 respectively. (For some devices I get correct values and videoview works fine in both orientations)
I am facing the same problem which has been asked in the below link-
video not taking full screen in landscape mode using videoview android
Solved by using this code.
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT
);
private void enterFullScreen(){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mVideoView.setLayoutParams(layoutParams);
}
private void exitFullScreen(){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mVideoView.setSystemUiVisibility(0);
isFullScreen = false;
mFullScreen.setVisibility(View.INVISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
}else {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT,0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,0);
}
mFullScreen.setVisibility(View.VISIBLE);
enter code here`enter code here`
mVideoView.setLayoutParams(layoutParams);
}