androidx / androidx/media

Prevent MediaSessionService from posting notification immediately after setting mediaItem

Open
#2,585 7 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jul 4, 2025.

question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

I'm using MediaSessionService with a MediaController, and I've noticed that as soon as I call setMediaItem(), the service automatically posts a notification — even before playback starts.

However, in my use case, I want to delay the notification until the user explicitly starts playback. For example:

I call setMediaItem() just to prepare the UI — to show duration, title, and a play button.

Only when the user taps "Play" should playback begin and the notification be shown.

If the user closes the player before hitting Play, I don’t want the notification to appear at all.

Similarly, on Pause or Close, I may want to temporarily hide the notification.

Is there a recommended way to suppress or delay the notification from being posted automatically when a media item is set?

Would appreciate any guidance or recommended patterns to achieve this. Thanks!
Cc @marcbaechinger

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.