ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
806 stars 480 forks source link

Media notification can be swiped away while audio is playing #1064

Closed 12people closed 7 months ago

12people commented 8 months ago

Documented behaviour

onNotificationDeleted:

Handle the notification being swiped away (Android).

Actual behaviour

When the media is being played back, the media notification can be swiped away and onNotificationDeleted isn't called. The media keeps playing, even if the foreground activity is gone.

Minimal reproduction project

Official example: main.dart

Reproduction steps

  1. Click play
  2. Swipe away the app in the app overview
  3. Open system notification drawer
  4. Swipe away the media notification

    Output of flutter doctor

    
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 3.19.2, on macOS 14.4 23E214 darwin-arm64, locale en-CZ)
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2023.1)
    [✓] Connected device (3 available)
    [✓] Network resources

• No issues found!



### Devices exhibiting the bug
OS: Android 13
Device: FairPhone 3
ryanheise commented 8 months ago

When the media is being played back, the media notification can be swiped away and onNotificationDeleted isn't called. The media keeps playing, even if the foreground activity is gone.

Well of course it isn't called, because that method doesn't even exist in your purported reproduction project. It's an invalid bug report. Please update your bug report as per the instructions.

12people commented 8 months ago

@ryanheise The example uses BaseAudioHandler, which has this onNotificationDeleted method:

@override
  Future<void> onNotificationDeleted() async {
    await stop();
  }

So stop() should be called, shouldn't it?

Either way, explicitly adding this to AudioPlayerHandler in the example yields the same result:

@override
  Future<void> onNotificationDeleted() async {
    await _player.stop();
  }

If I'm doing something wrong in the bug report, please tell me what it is.

ryanheise commented 8 months ago

Thanks for clarifying, so your steps to reproduce are to observe that after swiping away the notification, the media doesn't stop. This used to work pre Android 12, I suspect that what you're dealing with is that since Android 12, media notifications became persistent. You can't really swipe them away anymore, you can just cycle through the media notifications in the carousel. Even after a complete reboot, all of those media notifications will still be there. If you hide the carousel, it comes back after closing and opening the notification drawer.

12people commented 8 months ago

@ryanheise Oh, now I see what you mean. I swiped away the notification and it seemed to be gone for good, BUT it turns out that there's another notification in the quick settings area (where I didn't even think to look). That's some terrible UX on the part of Android 13, because the second hidden quick settings audio player is not easily discoverable. That's very much related to my other report at https://github.com/ryanheise/audio_service/issues/1065 — could there perhaps be a way of not allowing the media notification in the notification drawer to be swiped away (even though there is a duplicate media player in quick settings)?

12people commented 7 months ago

Closing, as it seems like a limitation on Android's part.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.