Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Unstoppable playback after disconnecting from MediaBrowser #250

@thibseisel

Description

@thibseisel

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:

  1. The last client unbinds from MusicService, triggering MusicService.onDestroy().
  2. As a result from calling MusicService.onDestroy(), the MediaSession is released, preventing further interactions with it.
  3. The notification is cleared, preventing from controlling the MediaSession.
  4. The ExoPlayer instance is neither stopped nor released, thus keeping it playing and leaking valuable resources.

Steps to reproduce

  1. Install UAMP and Media Controller Tester if not installed already.
  2. Open Media Controller Tester and tap "Control" button at the UAMP line.
  3. Click the "Play" button to start playback. Music should now be playing and the notification is displayed.
  4. 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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions