Android: Keep Mediaplayer Running During Activity Screen Orientation Update
Solution 1:
Have you looked at using the onConfigurationChanged() callback to handle some of this logic?
Solution 2:
Regarding your question how you can reliably determine whether your Activity is destroyed due to a configuration change, see my answer here: How to save/restore(update) ref to the dialog during screen rotation?(I need ref in onCreate method of activity.)
With this, the answer to your second question should be easy.
Solution 3:
Try running MediaPlayer
in different Thread.
You can add to this thread a more complex API to which you can call from onCreate
/onStop
/on*
Solution 4:
If you are using fragments (and you should :P), then calling setRetainInstance(true)
inside your fragments onCreate() call will make this problem go completely go away.
Solution 5:
Please see the following answer: https://stackoverflow.com/a/31466602/994021
It is a POC I've created for this purpose. Tired of solving this issue over and over again for different projects. I hope it helps.
I really recommend to switch to a third party player like ExoPlayer from google guys: https://github.com/google/ExoPlayer
Post a Comment for "Android: Keep Mediaplayer Running During Activity Screen Orientation Update"