Closed HHQuraishi closed 9 months ago
What if we consider using the following code snippet?
Auto Rotate
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
// Portrait orientation
// Add your code here to handle portrait mode
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// Landscape orientation
// Add your code here to handle landscape mode
}
}
Rotate Based on click
// Assuming you have a button with the ID "toggleOrientationButton"
Button toggleOrientationButton = findViewById(R.id.toggleOrientationButton);
toggleOrientationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int currentOrientation = getResources().getConfiguration().orientation;
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
});
Yes we can try
@HHQuraishi I'd like to discuss whether to create a separate class for orientation handling or include it directly where needed. Your insights on the approach would be appreciated. Factors include reusability, maintainability, code complexity, and project architecture.
Thank you for your guidance.
The videos play only in portrait mode. Even if the auto rotate is turned on the orientation does not change.
The videos play either in device orientation or in the best suited orientation for the current video. I can play landscape videos in landscape as well as portrait videos in landscape with device orientation and auto rotation turned on. If you still have issues, please post more detailed steps to reproduce such issue.
@HHQuraishi I'd like to discuss whether to create a separate class for orientation handling or include it directly where needed. Your insights on the approach would be appreciated. Factors include reusability, maintainability, code complexity, and project architecture.
Thank you for your guidance. I think you should make a separate class. (PS: I am a student and still learning)
I am a student and still learning
The videos play only in portrait mode. Even if the auto rotate is turned on the orientation does not change.