-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After the ~2 minute timeout for background services, the notification is removed #672
Comments
It's a design decision to take the service off the foreground when the player is paused. When in this state and the user does not resume playback within a given duration of time, the system will stop the idle service. This is working as intended and helps the system be in a healthy state instead having several services running silently in the background.
Your app can implement playback resumption. Then the system places a notification that allows the user to press the play button on that notification to restart your service and get back to the app. WIth playback resumption a user can also use the BT headset to resume. This is how Android designs this for not having various idle services running and giving the user a way to resume playback after an app has terminated.
You can override |
Couldn't it post the notification without keeping the service alive at all? As you said we could override MediaSessionService.updateNotification(), but I feel like keeping the notification would be what most media playing apps would want by default. At least, that's what most of the apps I use do, and mine did before changing to Media3 |
Only when the library knows that the app supports restarting without crashing, which is the case when an app ops-in to playback resumption. Generally when not running, it's unclear what to do with controls like next/previous, seek and the like when the service is not running. Because, when the service gets started when not running, it needs to be started in the foreground which requires the service to start playback. That's only the case for the play button. So from the library point of view, an app can implement playback resumption to get exactly that, a notification with just a play button. That's the system way and it has been designed like this for a reason. With Media3 it's two simple steps:
That's for the reason that the library knows that playback resumption is supported by the app. If that's not the case and some actor tries to do playback resumption, you land on #167. No one wants to be there. Media3 doesn't post such a notification at the end because there is an API for this that removes uncertainties. Media3 offers the System UI playback resumption with a
And, an app like yours is ultimately free to ignore all I've said here and what the library intents to do. An app can post it's own notification at any time. You can for instance do this in |
Not sure if this is intended, but this notification doesn't show with the two steps completed with my |
@DimitarStoyanoff Thanks for your comment! That's correct. System UI uses I will make this clear in the documentation. |
I updated the docs and added a note in the 'Playback resumption' section of the DAC page about 'Background playback with a MediaSessionService'. The note says that the playback resumption notification is only available for a 'MediaLibraryService`. |
Thank you, @marcbaechinger, for your quick responses and for all the work you put into this project. |
Thanks for your report!
As mentioned in a comment above, the notification is removed when the system destroys the service after about 2 minutes of not being in the foreground which is when the player is paused. This is working as intended.
Under the hood, From your report I assume that you are advertising your
I just noticed that the demo app is doing this as well. While this apparently works, I think it confusing to do so in the demo app. I'll send a CL to change this from Regarding your question, I guess that you are having a service that extends from I think you kind of discovered a loop-hole in the implementation or, in a more positive way, you discovered the feature that we actually can offer a resumption notification for a Lemme explain: System UI picks the While this is unexpected and confusing, I think we should keep this behaviour because it can easily be removed from a So for this purpose, I think you can either remove
Guess the first part is explained above. I'm not sure why it doesn`t work on 34 without further information. Can you repro this with the demo app? I think since API 33 there is need for some additional permission regarding notifications that may have an impact. I assume you got this already as else you would possibly see some warnings from the system. The demo app has this here in the manifest and here in the If you can repro that the notification is not shown with the notification permission in place, can you please make a bug report from your app that is made just after you started playback (aka when the first playback notification is displayed by System UI). You can also filter logcat for
or
|
The `PlaybackService` of the demo app is declared as `androidx.media3.session.MediaSessionService` instead of `androidx.media3.session.MediaLibraryService`. While this technically works, its confusing to do that in the demo app. Generally, apps that declare the legacy `android.media.browse.MediaBrowserService` should also declare `androidx.media3.session.MediaLibraryService` and the demo app should reflect this common case. Issue: #672 PiperOrigin-RevId: 595320994
General way to replicate with demo-session:
After that, the user has no way to resume playback besides going back into the app, the notification is removed and app no longer responds to play command from bluetooth headset.
Seeing how other apps like YouTube Music persist the notification and continue to respond to media buttons, is there a general recommended way to mimic this behavior with Media3?
The text was updated successfully, but these errors were encountered: