Skip to content
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

Add seekNext and seekPrev commandbuttons to the Android 12 "Compact" notification by default #410

Closed
tzugen opened this issue May 20, 2023 · 2 comments
Assignees

Comments

@tzugen
Copy link

tzugen commented May 20, 2023

Currently the "compact" notification in Android 12 using the DefaultMediaNotificationProvider shows only the Play/Pause button.

Our users frequently requested it contains the seek buttons as well, so we added them by assigning a COMMAND_KEY_COMPACT_VIEW_INDEX to them.

I would propose that the seek buttons get this flag by default as it seems to be most common that the basic buttons of a media player are prev, play/pause, and next.

For reference our custom class:

class CustomNotificationProvider(ctx: Context) :
    DefaultMediaNotificationProvider(ctx),
    KoinComponent {

    // By default the skip buttons are not shown in compact view. 
    // We add the COMMAND_KEY_COMPACT_VIEW_INDEX to show them
    override fun getMediaButtons(
        session: MediaSession,
        playerCommands: Player.Commands,
        customLayout: ImmutableList<CommandButton>,
        playWhenReady: Boolean
    ): ImmutableList<CommandButton> {
        val commands = super.getMediaButtons(session, playerCommands, customLayout, playWhenReady)

        commands.forEachIndexed { index, command ->
            command.extras.putInt(COMMAND_KEY_COMPACT_VIEW_INDEX, index)
        }

        return commands
    }
}
@tonihei
Copy link
Collaborator

tonihei commented May 24, 2023

@tianyif Could you take a look and see if this is something we want to enable by default?

@tianyif
Copy link
Contributor

tianyif commented Jun 1, 2023

I'm making a change to address this, which should be available in main branch next week.

tof-tof pushed a commit that referenced this issue Jun 9, 2023
This change is for Android 12 and below, where the buttons are derived from the actions added with the notification. From Android 13 (https://developer.android.com/about/versions/13/behavior-changes-13#playback-controls), the system derives media controls from `PlaybackState` actions.

When adding the actions onto the notification, the logic will iterate all the command buttons. The `COMMAND_KEY_CONPACT_VIEW_INDEX` extra will be checked for each button. If that extra is set for the three buttons on the compact view, then the customized buttons and their order will be used. Otherwise, the compact view will be "seekPrev" (if any), "play/pause" (if any), "seekNext" (if any) buttons (in such order).

Issue: #410
PiperOrigin-RevId: 538797874
@tianyif tianyif closed this as completed Jun 12, 2023
tof-tof pushed a commit that referenced this issue Jun 12, 2023
This change is for Android 12 and below, where the buttons are derived from the actions added with the notification. From Android 13 (https://developer.android.com/about/versions/13/behavior-changes-13#playback-controls), the system derives media controls from `PlaybackState` actions.

When adding the actions onto the notification, the logic will iterate all the command buttons. The `COMMAND_KEY_CONPACT_VIEW_INDEX` extra will be checked for each button. If that extra is set for the three buttons on the compact view, then the customized buttons and their order will be used. Otherwise, the compact view will be "seekPrev" (if any), "play/pause" (if any), "seekNext" (if any) buttons (in such order).

Issue: #410
PiperOrigin-RevId: 538797874
(cherry picked from commit 2e2f193)
@androidx androidx locked and limited conversation to collaborators Aug 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants