-
Notifications
You must be signed in to change notification settings - Fork 337
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
How to stop the service and remove the notification when connected with MediaController? #73
Comments
As long as you are bound to the service with a connected controller in your activity, you can't easily stop the service. If you for some reason want to stop the service from the activity, I think it should work if you first release the controller and then stop the service in Because the service can only be stopped when no controller is bound to it, I think you can always stop the service on the service side when you call
This disconnects (unbinds) all controllers and then stops the service. If I understand your requirement correctly, overriding The stack trace above is a bug that I think is actually unrelated. I filled #74 for this, so we can keep this as a question for future readers. Thanks for reporting! |
Thank you for your answer, marcbaechinger I did what you said regarding But this solution only covers the case when a user swipes the app from the recents. Is there a way to somehow send a termination signal from activity to a service (by a button click for example)? One usually does it by All I am trying to achieve is to ensure that if user wants to remove the notification and stop the player, he does it easily. |
You need to release the player in any case. It's documented in the class level JavaDoc of But it still sounds odd that it keeps playing. I would assume you do release the player in |
have same problem with MediaSessionService i'm trying to remove the app from recent when music playing and I get the following results:
|
What if you use the lines from my comment above?
|
Specifically mention that releasing the session does not release the player and the app needs to take care to release the player. Issue: #73 PiperOrigin-RevId: 448454338
The stack trace from the initial post was caused by #74 and is fixed. The question of this issues looks like answered to me with the post above, so I close this issue for now. Please re-open or open a new issue if you think something on the library side is wrong. For future readers and further reading this DAC article about |
I mean, release the MediaSession, stop the MediaSessionService and remove the notification.
The problem is that just calling stopService(intent) and releasing the MediaController from the activity does not work. I suspect it's because the service keeps being used by the MediaSession.
I know that I should release the mediasession, but the mediasession belongs to the sevice, which I can't control from Activity.
I can't even get into the service's onDestroy callback to release the mediasession.
So my current workaround is to release the MediaController in activity's onDestroy(), so the process stops by a fatal crash:
It does the job, but I believe there should be a better way for such a simple task.
The text was updated successfully, but these errors were encountered: