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

How to keep the same order of custom media actions #11027

Open
YogeshSinghPathania1 opened this issue Feb 28, 2023 · 13 comments
Open

How to keep the same order of custom media actions #11027

YogeshSinghPathania1 opened this issue Feb 28, 2023 · 13 comments
Assignees
Labels

Comments

@YogeshSinghPathania1
Copy link

YogeshSinghPathania1 commented Feb 28, 2023

I want to use custom next/previous actions instead of the native ones. So I started by removing the native ones by allowing only needed actions: But in some devices

MediaSessionConnector(mediaSession).setCustomActionProviders(object :
               MediaSessionConnector.CustomActionProvider {
               override fun onCustomAction(player: Player, action: String, extras: Bundle?) {}

               override fun getCustomAction(player: Player): PlaybackStateCompat.CustomAction? {
                   return PlaybackStateCompat.CustomAction.Builder(
                       "SKIP_TO_PREVIOUS_ACTION",
                       "previous",
                       if (!isFirst)
                           R.drawable.ic_previous_with_padding
                       else R.drawable.ic_previous_disabled_with_padding
                   ).build()
               }
           },
       object : MediaSessionConnector.CustomActionProvider {
               override fun onCustomAction(player: Player, action: String, extras: Bundle?) {}

               override fun getCustomAction(player: Player): PlaybackStateCompat.CustomAction? {
                   return PlaybackStateCompat.CustomAction.Builder(
                       "SKIP_TO_NEXT_ACTION",
                       "next",
                       if (!isLast)
                           R.drawable.ic_next_with_padding
                       else R.drawable.ic_next_disabled_with_padding
                   ).build()
               }
           }

1
2

As you observed, the buttons in the home section are inverted, how can I keep the same order as in the app? But in some devices its working fine
Any idea how we can resolve this?
@phhusson @xian @canatella @kiall @talklittle @marcbaechinger

@marcbaechinger
Copy link
Contributor

But in some devices its working fine

This may be because these devices have different operating system versions. When you do this with a MediaSessionConnector you have to make sure that this behaves the same on all API levels like for instance before and after Android 13.

From the screenshot and the info above, it looks like this is a notification on a device before Android 13. I may be wrong, but if this is the case, then the custom actions in the session have no impact on the action on the notification.

This includes that you keep the PlayerNotificationManager or your app code that creates the notification for Android 12 and below in sync with what you do with custom actions in the session. Please find this document about how this behaves since Android 13.

@YogeshSinghPathania1
Copy link
Author

YogeshSinghPathania1 commented Feb 28, 2023

@marcbaechinger I have already read the documentation for Android 13 updates. As per documentaion i have integrating the custom buttons through MediaSessionConnector But the thing is, in Android 13, it works fine on some devices but not on others (Samsung S21, for example) . If you want more screen short . However, this should work for all devices.

I did not find any way to resolve this. Could you please explain how we ensure that this behaves consistently across all API levels?I did not find anything in the documentation regarding this issue.
Please share any information or links. How can we control the position of the buttons? 

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Feb 28, 2023

I don't think I have more info than what is documented in the Android 13 changes that you already know: https://developer.android.com/about/versions/13/behavior-changes-13#playback-controls These are the guideline with which we implemented the custom commands of the Media3 session module to support notifications on all API levels (see androidx/media#38).

I will test the Media3 implementation with a Samsung phone with Android 13 as soon as I get my hands on such a device.

From your code you posted this looks like what I would expect is required to do and as you say, it seems to work on some devices. So we can rule out that the MediaSessionConnector is somehow buggy and changes the order of the custom actions (please correct me if you think this is different).

According to the doc linked above, it should work if the actions are in the correct order in the legacy/platform session. You can verify this by looking at what

adb shell dumpsys media_session

outputs for your session.

@marcbaechinger
Copy link
Contributor

Yeah, you are right that Samsung is doing their own thing on Android 13.

Accordingly, what I know is about the same as you. The notification is apparently based on the media session as the custom action is replicated in the notification. However, the layout and the placing of buttons as for rewind/ffwd and custom actions is different from what vanilla Android does.

This is Galaxy S21 with Android 13

samsung_s21_notification_android13

And this is what system UI of Android does without modification of the OEM:

notification_pixel_android13

You can imagine that I am as happy about this as you are. :(

This is obviously different and I do not have information about how Samsung draws the notification.
Sorry I can not provide you with useful information about this as I simply just don't know. You may want to ask Samsung about it.

@Atternatt
Copy link

@marcbaechinger I'm facing the same problem and we made a dirty workaround for samsung devices that inverts the list of custom actions and looks woking but with some exceptions: if there is a single element o if there is a playlist (see attached video without implementing the fix).

It's so weird to see how the drawing mechanism is so inconsistent that even trying to implement a fix doesn't work...
One of my guessings is, can we remove the previous/next icons from the playe? maybe that could make the icons more consistent?

As per the documentation I see that we can set them empty by:

PlaybackState extras include a true boolean value for key SESSION_EXTRAS_KEY_SLOT_RESERVATION_SKIP_TO_PREV.

But I'm not sure how to do that with exoplayer, should be do it though MediaSessionConnector? would it be possible to ask how can we do it?

Thank you!

Look in the video how when there is no "next" icon, the ff/rw icons are reversed but when both next/previous are present they look normal.

Screen_Recording_20230309_123026_Waking.Up.Debug.mp4

@marcbaechinger
Copy link
Contributor

Many thanks for this. Very useful!

PlaybackState extras include a true boolean value for key SESSION_EXTRAS_KEY_SLOT_RESERVATION_SKIP_TO_PREV. But I'm not sure how to do that with exoplayer,

Can you let me know how you produced the notification from above video?

When you use MediaSessionConnector the you have access to the MediaSessionCompat directly and can do this by calling sessionCompat.setExtras(Bundle). With Media3 you can do MediaSession.setExtras(Bundle) and use mediaSession.setCustomLayout(). Media3 takes care for all API levels (with the exception of this open issue with Samsung :(). There is a more detailed description of how you can do custom commands with Media3 here.

I have some question to your screencast: Is this done with Media3? If not, are the custom actions in the media session or are the buttons in the notification the notification actions that you've put into the Notification when using the NotificationCompat.Builder?

would it be possible to ask how can we do it?

I try to find out something.

@Atternatt
Copy link

@marcbaechinger I'm preparing a project with something similar of my implementation so you can take a look on it :)
(I can't share the real project)

will try to do in the next few days.

@marcbaechinger
Copy link
Contributor

(Internal bug-ref sent to Samsung: b/273221499)

@sahilpocketfm
Copy link

Any update on the same from samsung? Can you share the bug report link if available?

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Jun 9, 2023

Unfortunately no response yet.

Can you still repro this with the most recent Media3 version? If you can upload a screenshot and shortly describe this would be helpful. I can nudge again and see whether they give me a response. Until now I have no feedback unfortunately. My situation is not much better than yours to be honest. You may, as an alternative, find ways to file a bug directly on a Samsung site.

@TomasValenta
Copy link

Can you still repro this with the most recent Media3 version?

@marcbaechinger Yes, I have the same or similar issue on Samsung devices running Android 13 and 14.

I just want to add the Seek back and Seek forward buttons as you mentioned here and on the OEM Android 13 it works as I would expect according to the documentation:

OEM Android

(OEM Android 13 - Playlist with action skip to next active)
image

(OEM Android 13 - Playlist with action skip to next inactive (last item or single item playlist))
image

Samsung

(Samsung Android 13,14 - Playlist with action skip to next active, not bad)
image
(compact mode)
image

BUT

(Samsung Android 13,14 - Playlist with action skip to next inactive (last item or single item playlist))
image
(compact mode)
image

Seek back and Seek forward buttons are swapped and compact mode looks weird :/

I tried to customize positions in the DefaultMediaNotificationProvider getMediaButtons() or addNotificationActions(), but without change. I would temporarily be happy with the solution as you mentioned here (hide the action skip and previous and replace them with custom seek buttons), but I need to keep the skip and previous player functionality for in-app controls.

Still no response from Samsung?

@RKaySilverorange
Copy link

I'm having a very similar issue with Android auto and custom media actions. When I am listening to a timeline which only has one media item, ExoPlayer does not render the Skip to next action. In that specific case, it reverses the order of my custom media actions for Fast-Forward and Rewind. Otherwise, the order is correct.

I get this same behaviour on both Samsung and Pixel devices, though I am unfortunately only able to test this via the DHU since I don't actually have a vehicle with Android auto. Also, I am using the latest version of ExoPlayer 2. Unfortunately I cannot yet migrate to 3 until the client wants to make time for that (not that this is anyone else's problem, just providing context).

I understand if this info isn't useful or you can't help, but I wanted to share this as it seemed relevant.
Image

@marcbaechinger
Copy link
Contributor

That's a long shot as this is more for SystemUi than for Auto. Have you tried reserving the seek to next button ('EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT')?

https://developer.android.com/reference/kotlin/androidx/media3/session/MediaConstants#EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT()

@OptIn(UnstableApi::class)
  override fun onConnect(
    session: MediaSession,
    controller: MediaSession.ControllerInfo,
  ): MediaSession.ConnectionResult {
    if (
      session.isMediaNotificationController(controller)
    ) {
      // Select the button to display.
      val sessionExtras = Bundle()
      sessionExtras.putBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, true)
      return MediaSession.ConnectionResult.AcceptedResultBuilder(session)
        .setSessionExtras(sessionExtras)
        .build()
    }
    // Default commands without media button preferences for common controllers.
    return MediaSession.ConnectionResult.AcceptedResultBuilder(session).build()
  }

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

No branches or pull requests

6 participants