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 can I change the color of MediaSessionService's notification when the currently playing MediaItem doesn't have an artwork ? #1795

Open
Deltasims opened this issue Oct 9, 2024 · 1 comment
Assignees
Labels

Comments

@Deltasims
Copy link

Android 14 One UI version 6.1

I am working on a local music player app using a MediaSessionService.

Obviously, most audio files do not possess an artwork. So, what defines MediaSessionService's notification's color palette when the current MediaItem doesn't have an artwork ?

After a quick test, it seems as if the notification's color palette depends on the app's icon. Here's an example with a generic red icon:

Screenshot_20241009_160903_Moody_Music_Player 1

Screenshot_20241009_160944_One_UI_Home 1

However, I would like to set a custom color palette for the notification which doesn't depend on the icon's color. Can it be done and, if so, how?

At first, I thought the solution was to use MediaNotification.Provider as specified in the documentation. However, the documentation also specifies this:

Note: Starting with API 33 the System UI notification is populated from the data in the session. Accordingly, customizations of the MediaNotification.Provider have effect before API 33 only.

Which means that it has basically no effect starting from Android 13.

Also, as a slight deviation from my main question, the two custom buttons' icons (thumbs up and down) are white despite the fact that their vector assets are colored. In fact, using these same drawables in an activity displays the desired colors. Is this working as intended ?

@marcbaechinger
Copy link
Contributor

Thanks for your question.

Yeah, I think regarding the color palette used for the media notification starting from API 33 I don't know about ways to change the colors. Media3 is using the API that System UI gives apps. There probably isn't a better answer or explanation then the one you gave yourself. :)

The docs and config options I know are about Android Media Controls and the change from using notification vs. media session in Android 13 in the OEM docs.

If you really want it you obviously can consider using a single colored bitmap as a fallback. Given old Android versions are out and won't change that behaviour this seems like the way, probably. Or make the fallback even prettier :)

Regarding the coloring of the icon it seems that Media3 is using resource IDs in DefaultMediaNotificationProvide (below API 33 like your screenshot above) as well as for recent API levels in PlayerWrapper where the PlaybackStateCompat is built with custom actions using resIds. This is sent to either the notification manager or read by System UI from the session. These them resolve the ID to an actual drawable and render it as part of their UI. I don't think we technically can tell to pick the vector or bitmap version from Media3 side. Here again and not knowing the exact use case, doing bitmaps with colored icons may help with backward compatibility.

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

3 participants