androidx / androidx/media

Error in modified buttons in player notification (Samsung)

Open
#1,038 4 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Feb 1, 2024.

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

Description

Hello, I was able to implement some custom buttons in my player and everything was fine until I tested the player on a Samsung Galaxy S24+, when I put it on the custom buttons do not appear. I leave an image of how it appears in the emulator and on the Samsung. Could anyone tell me why he does this? and if there is a solution?

Samsung
Imagen de WhatsApp 2024-01-27 a las 23 41 37_4a0059c1

Emulator
Screenshot_5

  public static final SessionCommand CUSTOM_COMMAND_SHUFFLE =
        new SessionCommand("ACTION_SHUFFLE", Bundle.EMPTY);
  public static final SessionCommand CUSTOM_COMMAND_SHUFFLE_ON =
        new SessionCommand("ACTION_SHUFFLE_ON", Bundle.EMPTY);
  public static final SessionCommand CUSTOM_COMMAND_CLOSE =
        new SessionCommand("ACTION_CLOSE", Bundle.EMPTY);


    ShuffleButton = new CommandButton.Builder()
            .setDisplayName("Shuffle Off")
            .setIconResId(R.drawable.baseline_shuffle)
            .setSessionCommand(CUSTOM_COMMAND_SHUFFLE)
            .build();

    ShuffleOnButton = new CommandButton.Builder()
            .setDisplayName("Shuffle On")
            .setIconResId(R.drawable.baseline_shuffle_on)
            .setSessionCommand(CUSTOM_COMMAND_SHUFFLE_ON)
            .build();

    CloseButton = new CommandButton.Builder()
            .setDisplayName("Close")
            .setIconResId(R.drawable.ic_close)
            .setSessionCommand(CUSTOM_COMMAND_CLOSE)
            .build();
    String randomId = UUID.randomUUID().toString();


    mediaSession = new MediaSession.Builder(this, player)
            .setSessionActivity(getSingleTopPendingActivity())
            //.setCustomLayout(ImmutableList.of(ShuffleButton, CloseButton))
            .setCallback(new MyCallback())
            .setId(randomId)
            .build();

   private class MyCallback implements MediaSession.Callback {
    @OptIn(markerClass = UnstableApi.class)
    @Override
    public MediaSession.ConnectionResult onConnect(
            MediaSession session, MediaSession.ControllerInfo controller) {
        // Set available player and session commands.
        Log.i("MyCallback", "onConnect");
        return new MediaSession.ConnectionResult.AcceptedResultBuilder(session)
                .setAvailablePlayerCommands(
                        MediaSession.ConnectionResult.DEFAULT_PLAYER_COMMANDS.buildUpon()
                                .build())
                .setAvailableSessionCommands(
                        MediaSession.ConnectionResult.DEFAULT_SESSION_COMMANDS.buildUpon()
                                .add(CUSTOM_COMMAND_SHUFFLE)
                                .add(CUSTOM_COMMAND_SHUFFLE_ON)
                                .add(CUSTOM_COMMAND_CLOSE)
                                .build())
                .setCustomLayout(ImmutableList.of(ShuffleButton, CloseButton))
                .build();
    }

    public ListenableFuture onCustomCommand(
            MediaSession session,
            MediaSession.ControllerInfo controller,
            SessionCommand customCommand,
            Bundle args) {
        Log.i("MyCallback", "onCustomCommand");
        if (customCommand.customAction.equals(CUSTOM_COMMAND_SHUFFLE.customAction)) {
            player.setShuffleModeEnabled(true);
            isShuffleOn = true;
            session.setCustomLayout(ImmutableList.of(ShuffleOnButton, CloseButton));
        } else if (customCommand.customAction.equals(CUSTOM_COMMAND_SHUFFLE_ON.customAction)) {
            player.setShuffleModeEnabled(false);
            isShuffleOn = false;
            session.setCustomLayout(ImmutableList.of(ShuffleButton, CloseButton));
        }
        else if (customCommand.customAction.equals(CUSTOM_COMMAND_CLOSE.customAction)) {
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (notificationManager != null) {
                notificationManager.cancel(154); // Reemplaza 154 con el ID de tu notificación
                player.stop();
            }
            stopForeground(true);
        }
        return MediaSession.Callback.super.onCustomCommand(
                session, controller, customCommand, args);
    }
}

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.