Skip to content

Media notification dismisses only on second swipe #2302

Closed

Description

@SandisPutnis

Version

Media3 main branch

More version details

1.6.0

Devices that reproduce the issue

Samsung S22 Ultra running Android 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

  1. Run session demo app
  2. Select "Album folder"
  3. Select "Youtube Audio Library Rock"
  4. Select "Drop and Roll" (playback starts)
  5. Swipe down from viewport to so you can see Media Notification
  6. Press pause on it
  7. Swipe notification away - instead of disappearing, it gets immediately recreated, and only now swiping away this recreated one it will be properly dismissed.

Expected result

Swiping away the media notification should not recreate it. It should be gone.

Actual result

The swiped notification gets recreated the first time it is swiped away.

Media

Mentioned in reproduction steps.

Bug Report

Activity

  1. tianyif commented on Apr 3, 2025

    @tianyif
    Contributor

    Hi @SandisPutnis,

    This might be a Samsung specific issue as I couldn't repro this on Pixel, then we can hardly help on this I'm afraid.

  2. self-assigned this
    on Apr 3, 2025
  3. SandisPutnis commented on Apr 4, 2025

    @SandisPutnis
    Author

    Note - the issue is only in 1.6.0. The 1.5.1 version works as intended.

  4. assigned and unassigned on Apr 4, 2025
  5. adelinolobao commented on Apr 4, 2025

    @adelinolobao

    I can confirm that the issue occurs on more Samsung devices, including the Samsung S24 (Android 14) and Samsung A52 (Android 14).

    Regarding the reported behavior, I also noticed that if you are playing media content and close the application (removing it from the background), the notification remains on the device. Previously, this did not happen because the MediaLibraryService was completely stopped.

  6. tonihei commented on Apr 4, 2025

    @tonihei
    Collaborator

    This is likely related to the release intent of the notification that doesn't fully remove the notification. Need to try out on a Samsung device still, but I can reproduce a similar effect on an older emulator.

    close the application (removing it from the background)

    What did you do exactly for this scenario? That feels like a different question unrelated to the ability to swipe away notifications.

  7. tonihei commented on Apr 4, 2025

    @tonihei
    Collaborator

    A likely workaround is to convert the stop key event that is currently sent when the notification is dismissed to clear the playlist instead (or release the player) in your MediaSession.Callback:

    override fun onMediaButtonEvent(
        session: MediaSession,
        controllerInfo: MediaSession.ControllerInfo,
        intent: Intent
      ): Boolean {
          intent.getExtras()?.getParcelable<KeyEvent>(Intent.EXTRA_KEY_EVENT)?.let {
            if (it.keyCode == KeyEvent.KEYCODE_MEDIA_STOP) {
              session.player.clearMediaItems()
              return true
            }
          }
          return false
      }
    
  8. SandisPutnis commented on Apr 4, 2025

    @SandisPutnis
    Author

    I can confirm that the workaround works (if I return true).

    However, is it possible to use it if app is written in Java?
    A slight side-question, but still on the topic.

    When I implement an override:

    @Override
    public boolean onMediaButtonEvent(@NonNull MediaSession session, @NonNull MediaSession.ControllerInfo controllerInfo, @NonNull Intent intent) {
        ...
        return MediaSession.Callback.super.onMediaButtonEvent(session, controllerInfo, intent);
    }
    

    .. the compiler throws an error in line return return MediaSession.Callback.super.onMediaButtonEvent(session, controllerInfo, intent):

    'androidx. media3.session. MediaSession. Callback' is not an enclosing class

    When other button events come in, I need to pass them further down the line to library, so I wouldn't have to handle them.

  9. tonihei commented on Apr 4, 2025

    @tonihei
    Collaborator

    Yes, sorry, you can simply return false. Updated my snippet above.

  10. SandisPutnis commented on Apr 4, 2025

    @SandisPutnis
    Author

    Ah yes, the override description explains it:

    Return true to stop propagating the event any further. When false is returned, Media3 handles the event and calls the session player accordingly.
    

    Thanks!

  11. SandisPutnis commented on Apr 4, 2025

    @SandisPutnis
    Author

    Just for full disclosure - if your app has, let's say a custom mini player with play/pause buttons, and if you didn't have this workaround and after double swipe you go back to your app, you could press play on your custom mini player and the playback would start.

    However, if you have implemented this workaround, then after swiping, going back to your app and pressing play on your custom mini player - nothing would happen, because now there is no playlist on the player. You have to emit some event, so your custom players would know "ah, have empty playlist in player, got to make myself hidden or something".

  12. adelinolobao commented on Apr 7, 2025

    @adelinolobao

    close the application (removing it from the background)

    What did you do exactly for this scenario? That feels like a different question unrelated to the ability to swipe away notifications.

    Forget the comment, another dev changed the code and I didn’t noticed

  13. tonihei commented on Apr 10, 2025

    @tonihei
    Collaborator

    The commit above fixes this issue. We'll include it in the next bugfix release.

  14. added a commit that references this issue on Apr 14, 2025
  15. locked and limited conversation to collaborators on Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions