Skip to content

fix(android): only the active player may stop the shared MediaPlaybackService - #919

Open
tvanlaerhoven wants to merge 1 commit into
developfrom
devin/1789828780-android-inactive-player-service-stop
Open

tvanlaerhoven wants to merge 1 commit into
developfrom
devin/1789828780-android-inactive-player-service-stop

Conversation

@tvanlaerhoven

@tvanlaerhoven tvanlaerhoven commented Sep 19, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #918. Split out from the review discussion on #917 (#917 (comment)); not part of the 11.7.0 release.

All player contexts with background audio bind to one shared MediaPlaybackService. destroy() already gates the media session connector teardown on ownsMediaSession(), but the service stop one line above it was unconditional. Destroying an inactive player therefore removed the foreground notification and stopped the service of the player that was still active. applyBackgroundPlaybackConfig() (disabling background audio at runtime) had the same unconditional call.

// destroy()
if (BuildConfig.USE_PLAYBACK_SERVICE) {
-  binder?.stopForegroundService()
+  if (ownedMediaSession) {
+    binder?.stopForegroundService()
+  }
   unbindMediaPlaybackService()
}

// applyBackgroundPlaybackConfig(), disabling branch
-  binder?.stopForegroundService()
+  if (ownsMediaSession()) {
+    binder?.stopForegroundService()
+  }
   unbindMediaPlaybackService()

Unbinding stays unconditional: when the last client unbinds, Android destroys the service and onDestroy() cleans up the session. ownsMediaSession() returns true when binder == null, so single-player behaviour is unchanged.

Not done here (optional hardening from the issue): making MediaPlaybackBinder.stopForegroundService() take the calling context and ignore non-owners.

Link to Devin session: https://dolby.devinenterprise.com/sessions/56f1f4577f7044829520dd18f54efc76
Open in Devin Desktop: https://dolby.devinenterprise.com/desktop/session/56f1f4577f7044829520dd18f54efc76?variant=devin
Requested by: @tvanlaerhoven


Devin Review

…kService

Destroying an inactive player context, or disabling its background audio,
unconditionally called stopForegroundService() on the shared service. This
removed the foreground notification of the player that was still active.
Gate the service stop on ownsMediaSession(); always unbind.

Fixes #918

Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android: destroying an inactive player stops the shared MediaPlaybackService of the active player

1 participant