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

ordering of action buttons seems strange #1317

Open
1 task
XilinJia opened this issue Apr 26, 2024 · 0 comments
Open
1 task

ordering of action buttons seems strange #1317

XilinJia opened this issue Apr 26, 2024 · 0 comments
Assignees

Comments

@XilinJia
Copy link

XilinJia commented Apr 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants