google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.71k stars 6.02k forks source link

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

Open YogeshSinghPathania1 opened 1 year ago

YogeshSinghPathania1 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 https://github.com/androidx/media/issues/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 commented 1 year ago

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 commented 1 year ago

@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](https://developer.android.com/reference/android/media/session/PlaybackState#getExtras()) 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.

https://user-images.githubusercontent.com/2378636/224095538-e8f6f0cd-ac4c-4ed6-aac2-80a8427fbfdf.mp4

marcbaechinger commented 1 year ago

Many thanks for this. Very useful!

PlaybackState [extras](https://developer.android.com/reference/android/media/session/PlaybackState#getExtras()) 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 commented 1 year ago

@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 commented 1 year ago

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

sahilpocketfm commented 1 year ago

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

marcbaechinger commented 1 year ago

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 commented 11 months ago

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?