UAMP version: Latest, Kotlin version
Android version: Tested on Oreo (API 26+), may also be reproduced on earlier versions.
Issue description
When connecting to UAMP with the Media Controller Test app, I can control the media session and start playback as expected.
However, while playback is not stopped when I close the Media Controller Test app, the notification is cleared and I'm unable to control playback anymore. Also, re-establishing a new connection doesn't help regaining control over it.
I think the root cause is that the MusicService is not started, only bound to MediaBrowser clients. When starting playback via UAMP's UI then quitting the application, playback continues because MediaSessionConnection never calls MediaBrowserCompat.disconnect() when the Activity is destroyed, resulting in MusicService not being destroyed (because it still has a bound client).
On the other hand, the Media Controller Test app calls MediaBrowserCompat.disconnect() when finishing the MediaAppControllerActivity, which causes the following side-effects:
- The last client unbinds from
MusicService, triggering MusicService.onDestroy().
- As a result from calling
MusicService.onDestroy(), the MediaSession is released, preventing further interactions with it.
- The notification is cleared, preventing from controlling the MediaSession.
- The
ExoPlayer instance is neither stopped nor released, thus keeping it playing and leaking valuable resources.
Steps to reproduce
- Install UAMP and Media Controller Tester if not installed already.
- Open Media Controller Tester and tap "Control" button at the UAMP line.
- Click the "Play" button to start playback. Music should now be playing and the notification is displayed.
- Tap the device's back button, finishing the current Activity. The notification should clear itself at this moment.
Suggestions
Earlier versions of the UAMP were starting the service when it is put to the foreground. This was coupled with the DelayedStopHandler class that automatically stopped the service after a given delay without being playing. I think this feature should be brought back to this rewritten sample.
In addition, I suggest stopping and releasing the player instance before destroying MusicService. A good place to do that might be in MediaControllerCallback.onSessionDestroyed() as the MediaSession is released in onDestroy(), triggering this callback.
Also, shouldn't MediaBrowserCompat.disconnect() be called when finishing UAMP's MainActivity ?
I'd like to thank the whole team behind this sample for making it way simpler and readable than its Java older version. Keep going !
UAMP version: Latest, Kotlin version
Android version: Tested on Oreo (API 26+), may also be reproduced on earlier versions.
Issue description
When connecting to UAMP with the Media Controller Test app, I can control the media session and start playback as expected.
However, while playback is not stopped when I close the Media Controller Test app, the notification is cleared and I'm unable to control playback anymore. Also, re-establishing a new connection doesn't help regaining control over it.
I think the root cause is that the
MusicServiceis not started, only bound toMediaBrowserclients. When starting playback via UAMP's UI then quitting the application, playback continues becauseMediaSessionConnectionnever callsMediaBrowserCompat.disconnect()when the Activity is destroyed, resulting inMusicServicenot being destroyed (because it still has a bound client).On the other hand, the Media Controller Test app calls
MediaBrowserCompat.disconnect()when finishing theMediaAppControllerActivity, which causes the following side-effects:MusicService, triggeringMusicService.onDestroy().MusicService.onDestroy(), theMediaSessionis released, preventing further interactions with it.ExoPlayerinstance is neither stopped nor released, thus keeping it playing and leaking valuable resources.Steps to reproduce
Suggestions
Earlier versions of the UAMP were starting the service when it is put to the foreground. This was coupled with the
DelayedStopHandlerclass that automatically stopped the service after a given delay without being playing. I think this feature should be brought back to this rewritten sample.In addition, I suggest stopping and releasing the player instance before destroying
MusicService. A good place to do that might be inMediaControllerCallback.onSessionDestroyed()as theMediaSessionis released inonDestroy(), triggering this callback.Also, shouldn't
MediaBrowserCompat.disconnect()be called when finishing UAMP's MainActivity ?I'd like to thank the whole team behind this sample for making it way simpler and readable than its Java older version. Keep going !