Media controller not connecting after app is killed and relaunched

73 Views Asked by At

I've been migrating to media3 (version 1.2.0) and I've been using uamp as guideline. There is a class MusicServiceConnection that, as the name suggest, connects the UI with the media browser service equivalent.

In my app I'm providing/injecting a singleton instance using dagger2 of this class in the viewmodels where I need to observe/collect playback state.

Everything works well except, if I kill the app (swipe away from recents) while the audio is playing, then the next app launch MusicServiceConnection is not being recreated (I have a print log in it's init block that's not being called), thus the media browser is not connected and nothing (audio related) works.

I'm getting a warning log from Media Controller:

The controller is not connected. Ignoring setMediaItems()
The controller is not connected. Ignoring prepare()

Killing the app a second time and then relaunching it fixes the issue, but it's a bad UX.

Killing the app while audio has been paused doesn't cause the issue on the second app launch. Not using a singleton also fixes it for some reason, however that causes other issues, so it's not a viable option.

0

There are 0 best solutions below