Skip to content

How to avoid seeking to next item when pressing multiple times on the PLAY_PAUSE button in the media notification? #233

Closed

Description

@aureliendrouet

Hello,
I'm using media3 version 1.0.0-beta03. I observed the following behavior in the demo-session which uses the DefaultMediaNotificationProvider.

If you press quickly on the PLAY_PAUSE button in the media notification, it will automatically seek to the next item.

Is it a bug or an expected behavior? Is there a way to disable the "seek to next" behavior?

Currently, I overrided the onPlayerCommandRequest in the MediaLibrarySession.Callback to fix the issue but it does not work. It seems that the player command SEEK_TO_NEXT is sent when double tapping on the button PLAY_PAUSE.

override fun onPlayerCommandRequest(session: MediaSession, controller: MediaSession.ControllerInfo, playerCommand: Int): Int {
    return when (playerCommand) {
        Player.COMMAND_PLAY_PAUSE -> {
            if (player.playWhenReady) {
                player.pause()
            } else {
                player.play()
            }
            SessionResult.RESULT_INFO_SKIPPED
        }
        else -> super.onPlayerCommandRequest(session, controller, playerCommand)
    }
}

Also, if I set the player command SEEK_TO_NEXT_MEDIA_ITEM in the media notification provider, it will be received as the player command SEEK_TO_NEXT in the method onPlayerCommandRequest...

Activity

  1. self-assigned this
    on Dec 21, 2022
  2. tianyif commented on Dec 21, 2022

    @tianyif
    Contributor

    Hi @aureliendrouet,

    Thanks for reporting! This is reproducible from our end. It looks like this problem is due to https://github.com/androidx/media/blob/1.0.0-beta03/libraries/session/src/main/java/androidx/media3/session/MediaSessionLegacyStub.java#L226, which was a case ignored when the usage of MediaSession extended to the media notification. We will provide a fix soon!

  3. aureliendrouet commented on Dec 22, 2022

    @aureliendrouet
    Author

    Thank you. I am looking forward for the fix.

    Also, if I set the player command SEEK_TO_NEXT_MEDIA_ITEM in the media notification provider, it will be received as the player command SEEK_TO_NEXT in the method onPlayerCommandRequest...

    Do you have any idea about this?

  4. tianyif commented on Dec 22, 2022

    @tianyif
    Contributor

    The DefaultActionFactory maps both COMMAND_SEEK_TO_NEXT_MEDIA_ITEM and COMMAND_SEEK_TO_NEXT to keyCode KEYCODE_MEDIA_NEXT, which will be mapped back to COMMAND_SEEK_TO_NEXT when the session handles the media button event.

    This mapping is probably not ideal, and we're considering the enhancement around it.

  5. added a commit that references this issue on Jun 22, 2023
  6. locked and limited conversation to collaborators on Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions