Sign in Go Pro

Android Architecture Components - A Deep Dive

Observing music playback using a LifecycleObserver

 
Autoplay

Up next

Previous

About

In this video we will create a music player with LifecycleObserver to handle a real-life scenario of playing and pausing the music based upon the state of the activity.

We will make our app a good citizen of Android that means our app will pause the music when user leaves the app and resume the music again when user is back to the app, and lastly stop the music when Activity is destroyed.

Comments

When I rotate Screen.........Music starts again, but it should continue???
How to make this happen

Yes. Make sure you call mediaPlayer.start() after pause, that way the MediaPlayer will resume it and not start it from the beginning. Try it out and let me know if it works and if it doesn't then share the sample with me to test it.

>
You need to go PRO to post comments.

Lessons in Android Architecture Components - A Deep Dive