I am trying to make a video player. My problem is when the orientation was change, The videoView does not fit to the entire screen and my action bar doesn't hide...
here is my code.
RowClick.java
public class RowClick extends AppCompatActivity {
VideoView videoView;
MediaController mediaController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
getSupportActionBar().show();
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().hide();
}
}
};
if (orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}
setContentView(R.layout.activity_row_click);
videoView = findViewById(R.id.video);
mediaController = new MediaController(this);
StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("video/-L8Vf_Xa6PBhyqbEzlif");
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
videoView.setVideoURI(uri);
videoView.requestFocus();
}
});
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
}
}
activity_row_click.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout"
tools:context="com.mgb.sdakaraoke.RowClick">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/video"
/>
</RelativeLayout>
AndroidManifest.xml
<activity
android:name=".RowClick"
android:configChanges="orientation|screenSize">
</activity>
My goal is when the orientation equals to landscape the action bar must be hide and the videoview must be set to full screen.
please help me on how to achieve that goal.
Here is the screenshot of Lanscape mode that need to be change correctly according to my goal.
add this in your styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
apply it to your activity in manifest :
<activity
android:name=".RowClick"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize">
</activity>
this will translucent your status bar too.
you can also try below in your java file code.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getActionBar().hide();
} else {
getActionBar().show();
}
}
or
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}