-
Notifications
You must be signed in to change notification settings - Fork 413
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
(Documentation & demo bug) removing task in STATE_ENDED causes dead notification #1219
Comments
Thanks for your report! The intended behavior in the case of I think this would be the desired behavior when the user removes the app from recents as well, but as you report this is not the case. We will look into this and update this issue if we have some news.
Agreed this is a workaround that fixed the behavior. I'd keep this as a last resort in the case the above scenario isn't working. |
Thanks again for your report.
After investigating a bit more, I think this is indeed the correct fix. When doing the repro steps above, I end up dismissing the app from the recents when the player is paused and with this, the player is not in the foreground. This means that the service needs to be stopped. Playback can then be resumed for instance with the playback resumption notification. I think that behaves as it should. When in
So the proper fix is indeed to check for override fun onTaskRemoved(rootIntent: Intent?) {
val player = mediaLibrarySession.player
if (!player.playWhenReady || player.mediaItemCount == 0 || player.playbackState == STATE_ENDED) {
stopSelf()
}
} However, this check becomes a bit cumbersome and I think we should create an API that an app can use. |
I agree, this is basically inversing the check here: media/libraries/session/src/main/java/androidx/media3/session/MediaNotificationManager.java Lines 188 to 195 in d13a0f4
|
This API additions help an app to implement the lifecycle of a MediaSessionService properly and in consistency with the `MediaSessionService` being in the foreground or not. Not properly implementing `onTaskRemoved` is the main reason for crashes and confusion. This change provides `MediaSessionService` with a default implementation that avoids crashes of the service. This default implementation uses the new API provided with this change just as an app can do. Issue: #1219 PiperOrigin-RevId: 621874838
We fixed the documentation here, so that it works with the current version. For the next version we have included API support to make this a bit easier for app. There are two options an app is having:
For this we have added a default implementation of @Override
public void onTaskRemoved(@Nullable Intent rootIntent) {
if (!isPlaybackOngoing()) {
// The service needs to be stopped when playback is not ongoing and the service is not in the
// foreground.
stopSelf();
}
} The default implementation makes sure that we don't see crashes of the service in case an app doesn't implement
The default from above can be overriden as follows by using the new convenience method: override fun onTaskRemoved(rootIntent: Intent?) {
// Stop the service event when playback is ongoing.
pauseAllPlayersAndStopSelf()
} the method The whole change in I'm closing this issue. Please file a new issue if required. |
Thank you! |
Version
Media3 1.3.0
More version details
No response
Devices that reproduce the issue
Devices that do not reproduce the issue
N/A
Reproducible in the demo app?
Yes
Reproduction steps
Example:
Expected result
No stale notification (like if you pause instead of waiting for ended)
Actual result
Stale notification
This is caused by
media/demos/session_service/src/main/java/androidx/media3/demo/session/DemoPlaybackService.kt
Lines 93 to 96 in d13a0f4
player.playbackState == Player.STATE_ENDED ||
to the condition has helped fix this in my app.I believe https://developer.android.com/media/media3/session/background-playback should be updated as well.
Thank you.
Media
N/A
Bug Report
adb bugreport
to android-media-github@google.com after filing this issue.The text was updated successfully, but these errors were encountered: