media icon indicating copy to clipboard operation
media copied to clipboard

Media3 1.6.0 messes up custom media buttons on android auto / media notification

Open denizdemirciglobal opened this issue 7 months ago • 7 comments

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

Pixel 8 Pro API 35

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. Remove following buttons from available player commands:
connectionResult.availablePlayerCommands.buildUpon()
                .remove(COMMAND_SEEK_TO_NEXT)
                .remove(COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)
                .remove(COMMAND_SEEK_TO_PREVIOUS)
                .remove(COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)
  1. Add your custom buttons under the availableSessionCommands.
  2. Observe media notification on mobile or android auto now playing screen.

Expected result

2nd and 3rd slots should not be empty and be filled with custom buttons.

Actual result

2nd and 3rd slots are empty. The custom buttons show on overflow menu.

Media

here is the display of the buttons with version 1.6.0

Image

here is how it was before on version 1.5.1

Image

Bug Report

  • [ ] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

denizdemirciglobal avatar Apr 01 '25 11:04 denizdemirciglobal

This is still an issue with versions 1.7.1 and 1.8.0-alpha01

denizdemirciglobal avatar Jun 12 '25 10:06 denizdemirciglobal

Hi @denizdemirciglobal,

Sorry for the late reply! You may want to set the media button preferences https://developer.android.com/media/media3/session/control-playback#commands for your MediaSession.

According to the table in https://developer.android.com/media/implement/surfaces/mobile, slot 2 and 3 will be empty if neither a custom button nor one of the commands (COMMAND_SEEK_TO_NEXT / COMMAND_SEEK_TO_NEXT_MEDIA_ITEM or COMMAND_SEEK_TO_PREVIOUS / COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM ) is available.

tianyif avatar Jun 12 '25 14:06 tianyif

For me the play button disappears all together and is replaced with another seek button

Image

This is on a one plus 11 5g using OxygenOS 15.0

On my pixel 5 and Samsung A047F it works as expected.


 @OptIn(UnstableApi::class)
    override fun onConnect(
        session: MediaSession,
        controller: MediaSession.ControllerInfo
    ): MediaSession.ConnectionResult {
        val connectionResult = super.onConnect(session, controller)
        val availableSessionCommands = connectionResult.availableSessionCommands.buildUpon()

        //  Registering custom player command buttons for player notification
        CustomPlayerLockscreenControls.entries.forEach { control ->
            availableSessionCommands.add(SessionCommand(control.actionId, Bundle()))
        }
        // Define player commands while removing unwanted ones - DO NOT remove commands here that you still want to use with headset
        val playerCommands = MediaSession.ConnectionResult.DEFAULT_PLAYER_COMMANDS.buildUpon()
            .build()

        return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
            .setAvailablePlayerCommands(playerCommands)
            .setAvailableSessionCommands(availableSessionCommands.build())
            .build()
    }

...
return object : ForwardingPlayer(player) {
            override fun getAvailableCommands(): Player.Commands { 
 return super.getAvailableCommands()
                    .buildUpon()
                    .remove(Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM)
                    .remove(Player.COMMAND_SEEK_TO_NEXT)
                    .remove(Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM)
                    .remove(Player.COMMAND_SEEK_TO_PREVIOUS)
                    .build()
}


...

enum class CustomPlayerLockscreenControls(
    val actionId: String,
    private val displayName: String,
    private val iconResId: Int
) {
    REWIND("REWIND", "Rewind", R.drawable.rewind),
    FORWARD("FAST_FWD", "Forward", R.drawable.forward),

    /// `toCommandButton` - creates command button
    @OptIn(UnstableApi::class)
    fun toCommandButton(): CommandButton {
        return CommandButton.Builder()
            .setDisplayName(displayName)
            .setSessionCommand(SessionCommand(actionId, Bundle()))
            .setSlots(if (actionId == "REWIND") CommandButton.SLOT_BACK else CommandButton.SLOT_FORWARD)
            .setIconResId(iconResId)
            .build()
    }

    companion object {
        fun getPodcastControls(): List<CommandButton> = listOf(REWIND, FORWARD).map { it.toCommandButton() }
    }
}


Any help would be greatly received

Tr736 avatar Jun 16 '25 12:06 Tr736

Hi @Tr736,

I'm not seeing anything wrong with your code, also the code working on Pixel and Samsung gives me an impression that this is a device specific (or OS) issue, as OxygenOS is a customized version of the Android and may behave differently.

tianyif avatar Jun 18 '25 09:06 tianyif

@tianyif i found the issue. it seems some android os/ devices do not flush the notification buttons when you update. so it ends up adding duplicated ones. the fix is for me was to only add custom button if they dont already exist in the command button array

Tr736 avatar Jun 18 '25 10:06 Tr736

@Tr736 When you say "some android os/ devices", could you help us by specifying which combinations you tested explicitly? That sounds quite broken in terms of behavior to me and maybe there is a chance we can get this fixed (or find a workaround if needed that could be added to Media3).

tonihei avatar Jun 18 '25 12:06 tonihei

Devices on browser stack :- All of OnePlus (Device / OS)

Image

Google pixel 5 running Android 12

I didnt test any others

Tr736 avatar Jun 18 '25 12:06 Tr736

I tried this setup on a OnePlus CPH2449 (=OnePlus 11 5G), running OxygenOS15, but everything seems to work as expected.

I've never managed to reach a screen similar to the one in https://github.com/androidx/media/issues/2292#issuecomment-2976316228 though.

The screens I got to looked like this (correctly showing the REWIND and FAST_FWD button I configured with your code snippet in the session demo app in the larger media controls view).

Image Image

Some clarifying questions:

  • How did you reach the screen in your screenshot of https://github.com/androidx/media/issues/2292#issuecomment-2976316228? Sounds like you used the exact same device and OS version.
  • How did you set up the media button preferences? I used AcceptedResultBuilder.setMediaButtonPreferences(CustomPlayerLockscreenControls.getPodcastControls()) in the demo app
  • It may not make a difference here, but your ForwardingPlayer is not quite consistent as it doesn't filter the callback for onAvailableCommandsChanged. It's likely better to use a ForwardingSimpleBasePlayer, see https://developer.android.com/media/media3/exoplayer/customization#player-operations.

tonihei avatar Jul 08 '25 14:07 tonihei

Hey @denizdemirciglobal. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jul 28 '25 18:07 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@denizdemirciglobal if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Aug 06 '25 18:08 google-oss-bot

An update for the people coming here with the same problem: The issue is resolved on our side by changing custom icon size from 40dp to 24dp. Apparently there has been some restrictions in order to support icons on wearable devices.

denizdemirciglobal avatar Sep 23 '25 12:09 denizdemirciglobal