androidx / androidx/media

ordering of action buttons seems strange

Open
#1,317 0 comments 0 reactions 1 assignee View on GitHub

@tianyif is already working on this.

Since Apr 26, 2024.

bug needs triage
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 1.3.1

More version details

No response

Devices that reproduce the issue

Android 9, 14

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

I configured my custom action button in an enum:

enum class NotificationCustomButton(val customAction: String, val commandButton: CommandButton) {
    SKIP(
        customAction = CUSTOM_COMMAND_SKIP_ACTION_ID,
        commandButton = CommandButton.Builder()
            .setDisplayName("Skip")
            .setSessionCommand(SessionCommand(CUSTOM_COMMAND_SKIP_ACTION_ID, Bundle()))
            .setIconResId(R.drawable.ic_notification_skip)
            .build(),
    ),
    REWIND(
        customAction = CUSTOM_COMMAND_REWIND_ACTION_ID,
        commandButton = CommandButton.Builder()
            .setDisplayName("Rewind")
            .setSessionCommand(SessionCommand(CUSTOM_COMMAND_REWIND_ACTION_ID, Bundle()))
            .setIconResId(R.drawable.ic_notification_fast_rewind)
            .build(),
    ),
    FORWARD(
        customAction = CUSTOM_COMMAND_FORWARD_ACTION_ID,
        commandButton = CommandButton.Builder()
            .setDisplayName("Forward")
            .setSessionCommand(SessionCommand(CUSTOM_COMMAND_FORWARD_ACTION_ID, Bundle()))
            .setIconResId(R.drawable.ic_notification_fast_forward)
            .build(),
    ),
}

Then when building the media session, I set the layout:

val notificationCustomButtons = NotificationCustomButton.entries.map { command -> command.commandButton }

mediaSession = MediaSession.Builder(applicationContext, ExoPlayerWrapper.exoPlayer!!)
            .setCallback(MyCallback())
            .setCustomLayout(notificationCustomButtons)
            .build()

Then in addNotificationActions of CustomMediaNotificationProvider, I set:

val defaultPlayPauseButton = mediaButtons.getOrNull(1)
        val defaultRestartButton = mediaButtons.getOrNull(0)
        val notificationMediaButtons = if (defaultPlayPauseButton != null) {
            /* Overriding received mediaButtons list to ensure required buttons order: [rewind15, play/pause, forward15]. */
            ImmutableList.builder<CommandButton>().apply {
                if (defaultRestartButton != null) add(defaultRestartButton)
                add(NotificationCustomButton.REWIND.commandButton)
                add(defaultPlayPauseButton)
                add(NotificationCustomButton.FORWARD.commandButton)
                add(NotificationCustomButton.SKIP.commandButton)
            }.build()
        } else {
            /* Fallback option to handle nullability, in case retrieving default play/pause button fails for some reason (should never happen). */
            mediaButtons
        }

For more detail, check my open-sourced project : Podcini

Expected result

I expect the order to correspond to that in addNotificationActions of CustomMediaNotificationProvider (restart, rewind, play/pause, forward, skip), and/or in the layout enum. It turns out it has a lot to do with the enum but in a strange way. I had to fool around the enum order to get to desired order on screen, so the current is: skip, rewind, forward.

Actual result

what show up on Android 9 is: restart, rewind, play/pause, forward, skip,
and on Android 14: rewind, restart, play/pause, skip, forward.
restart and play/pause are from media3. btw, I don't get skip by default from media3.

Media

Screenshot_20240426_072754

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.