Change MediaController position on rotation Change MediaController position on rotation android android

Change MediaController position on rotation


Since you're overriding onConfigurationChanged, I assume that means the activity is not allowing Android to manage its orientation changes and instead choosing to do everything itself. This is normally not a great idea, and you're currently facing the pain of that decision. :-(

If I may make a recommendation: let Android manage the lifecycle of your activity, and use different layouts (e.g. layout-land/views.xml and layout-port/views.xml). This will allow you to express your layouts naturally in the XML without having to make crazy code changes.

You probably about to say: But I want my ExoPlayer not to have to stop, prepare and restart on every orientation change. The good news is that there is a way to work around this.

Just create a single ExoPlayer, prepare it at first load, and keep using that one instance (stored in a static or some other singleton) with each new activity instance. You can detach the old activity from it and reattach a new one when it's ready.

If ExoPlayer works similarly to MediaPlayer, then this should all work OK.