8

I have a video player in which I have two features:

  1. If the auto-rotate is disabled and when the user clicks on fullscreen button I force the orientation to go in landscape view using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) and back to portrait view when fullscreen is exited.

  2. I have overridden the onConfigurationChanged to detect the change in orientation when the auto-rotate feature is enabled by user and change the activity view according to the orientation.

Now the problem with this setup is that if user start the activity and goes in fullscreen and setRequestedOrientation get invoked once, later when auto-rotate is enabled, the activity doesn't receive the orientation changes and the onConfigurationChanged doesn't get called.

I read here (https://stackoverflow.com/a/6109206/5167868) that they wont work simultaneously.

I would like to know if there a way of implementing both as I have seen players like MX Player do this in their app.

Community
  • 1
  • 1
Suhas Shelar
  • 963
  • 2
  • 10
  • 23
  • that might be because you force portrait orientation after exitting fullscreen. Try setting not portrait, but automatical orientation: `SCREEN_ORIENTATION_SENSOR` – Vladyslav Matviienko Feb 17 '17 at 12:30
  • But I want it to be in Portrait Orientation if the auto-rotate is disabled. – Suhas Shelar Feb 17 '17 at 12:32
  • Sorry I wasnt clear earlier and I edited the question. I meant after the user enables auto-rotation, the onConfigurationChanged is not called. – Suhas Shelar Feb 17 '17 at 12:39
  • check [http://stackoverflow.com/questions/22848222/toggling-fullscreen-orientation-like-youtube?answertab=active#tab-top](http://stackoverflow.com/questions/22848222/toggling-fullscreen-orientation-like-youtube?answertab=active#tab-top) – bhaskar kurzekar Feb 17 '17 at 12:42
  • @SuhasShelar did you find a solution? – anthony Aug 05 '18 at 17:59

1 Answers1

3

After you fix the orientation of the screen by using setRequestedOrientation(), Auto Rotate feature won't work. So to make it work, you may do something like this:

After you set your orientation using: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)

Call this: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)

This shall make the auto rotate to work again!