Open keaganhilliard opened 3 years ago
Another way to reproduce
I wasn't able to reproduce the issue on my Pixel 3a (Android 11) using either of those two ways. However, I see a couple of things I can improve in the code which may have an impact on this, so I'll try that and see if it improves the situation for you.
I've just pushed some changes which will hopefully help with the repeated start/stop. Also, @stonega the recent commit to move mediaSession.release
into onDestroy
might have a positive influence on the lingering notification in Android 11
Let me know if either of you notice any improvements.
@ryanheise Thanks for update, I can confirm that this issue still exits after update.
OK, I think I am able to reproduce something for the first time. After hitting stop, swiping the app away from the task manager, opening again and tapping audio player, the audio started but the notification didn't appear.
However, when I hit pause and then play, it did appear. This gives me some idea of where to look...
I've just made another commit which for me solved the problem of the notification not appearing in @stonega 's reproduction steps. I don't know if it's solved all the problems, though.
Let me know how it goes with your own testing.
@ryanheise I think this issue had been fixed by latest commit, good job!
Good to know! I've just released version 0.15.0. Even if the bug is not completely fixed, we can always do a 0.15.1 with further improvements.
Since I wasn't able to reproduce the issue of multiple zombie notifications being left behind, so I'd be interested to know if this fixes that issue, too.
@ryanheise Can you confirm the setting is off on your device?
Yes this setting is off.
Is it possible to completely remove the notification after onStopped is called? Right now its showing the notification with the play button only if I stop the service. (But the play button is not working anyway)
I'm not sure exactly how this behaviour can be controlled in Android 11, but I'm looking into it.
Thank you! I know that the "Youtube Vanced" App has a close button in the notification. If I click that, the notification completely disappears. So I would assume its possible, just dont know how yet :)
I'm able to reproduce the zombie notifications, now.
While testing this, I think I managed to also break or confuse Android 11. I wanted to start from a clean slate by getting rid of all of the notifications by uninstalling the app. However, Android 11 still wanted to keep the notifications there, but had trouble deciding whether it wanted to show them or not. If you gradually swipe down, you'll see them animate into view, but once the animation is complete, they disappear. Restarting the phone seemed to do the trick of giving me a clean slate.
After restarting, I also haven't noticed any new zombie notifications, so it is possible that these were created as a result of the previous bug that I fixed above.
Can others confirm this?
On the other front, I see no way to truly dismiss the media notification from Android 11 since it was explicitly designed to allow media sessions to remain and be accessible. That is, aside from building a custom notification. However, I think going forward, my efforts will be in trying to cooperate with Android 11 rather than fight it, which means providing a way to reactivate the media session if the user clicks on the play button after your app has already stopped the media session.
which means providing a way to reactivate the media session if the user clicks on the play button after your app has already stopped the media session.
My app uses a temporary authentication token to fetch media, which is usually passed via SendPorts to the audio task from the UI. It also plays music from song suggestions given in blocks of four at a time. There's no way to replay an individual song, let alone continuing playback on the whole list - all information is disposed when the service ends.
For my use case, I'd need some way to save that information to be used on resuming - it'd be great if the plugin could provide an API, though I'm not entirely sure how such a thing could be implemented (excluding saving temporary data to persistent storage).
Some more unrelated Android 11 weirdness - sometimes, all the media buttons in the quick settings go transparent. They're clickable, but invisible.
Other times, I've noticed that the media controls are just unresponsive (while visible). My app's UI still works, but the quick settings buttons don't.
I'm trying to debug, but it's difficult because I can't seem to find a reproducible trigger.
On the other front, I see no way to truly dismiss the media notification from Android 11
It turns out there is a way to solve this problem, but I just haven't isolated the code that's responsible yet. If you try Google's Play Music app and Podcast app, and you hit play and pause in both, then swipe both apps away in the task manager, the podcast notification persists, while the music notification disappears completely. So there's some way of switching this behaviour on and off.
Play an item, stop it and play again. Repeat that process a couple of times and eventually, the service won't be able to start at all.
I seem to be able to start the task/service only once before this happens.
It seems the zombie notification is gone in the latest update of Android 11. Can anyone else confirm?
For me, the last Android security update was the 5th of December 2020.
@ryanheise, No. I'm on A11 Dec security patch too but the zombie notification still exists. In fact, I found this issue searching for a solution. Using audio_service0.16.0 and just_audio 0.6.3 if that would help.
On my pixel 3 with December patch it seems gone now, when I stop the audio service!
Maybe it's the vendor? I'm also on a pixel (3a) and the zombie notification is gone.
It seems as though they have silently rolled back this feature as the options page is even gone from the settings to choose whether to disable this option.
Also, the one-isolate branch tried to take advantage of this new zombie notification, which is actually a legitimate feature, and that code is now no longer useful. Quite strange. I guess they just had to roll it back because it had unintended consequences. i.e. it was a feature that was not appropriate for all apps.
If anyone finds an official word from Google, please share it here.
I wanna dismiss notification controls when stop music but its not happening , play button show issue
Hey @ryanheise
In Android 12, I'm still having this problem, but just on Samsung devices.
I've tried different devices, but only Samsung devices have this "zombie notification" problem.
When you stop the audio from a notification, the audio stops, but the notification is still in place with just the play icon.
As I don't have a Samsung device, I will rely on input from the community to find a workaround. However it is also worth keeping in mind that Android introduced this behaviour on the assumption that media sessions should be resumable. If you design your app so that the media session is resumable, then this zombie notification can be made to function the intended way, as a means to resume the media session. This is demonstrated in example_multiple_handlers.dart
.
Which API doesn't behave as documented, and how does it misbehave? Notifications seems to have issues in Android 11. Play an item, stop it and play again. Repeat that process a couple of times and eventually the service won't be able to start at all. Sometimes the audio is playing but none of the notification buttons work and the Flutter UI doesn't see a service running and hitting Audio Player no longer works.
Minimal reproduction project The example
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
Error messages I am not seeing any errors in the console
Expected behavior The notifications should either rehydrate with the new service or disappear.
Screenshots![screen-20200910-100934](https://user-images.githubusercontent.com/27737278/92771361-ae45d700-f34f-11ea-890e-d2cfdf4b2e47.gif)
Runtime Environment (please complete the following information if relevant):
Flutter SDK version
Additional context Seems like it has something to do with the new media resumption stuff introduced in Android 11. Not completely sure though.