ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
796 stars 477 forks source link

Custom Android notification colors (per MediaItem) #520

Open hacker1024 opened 3 years ago

hacker1024 commented 3 years ago

Is your feature request related to a problem? Please describe. Currently, the plugin allows configuring the Android notification color via the androidNotificationColor argument in AudioService.start. A color specified here will be applied to the notification throughout the task's lifetime.

Alternatively, if no notification color is specified, on Oreo and above, the notification will be colorized using colors generated by the Palette algorithm.

My backend provides colors manually chosen by real people, which are significantly better than the generated colors. I'd like to use these in the notification, but this is not currently possible.

Describe the solution you'd like Android provides APIs to manually set the notification color. When supplying a MediaItem to the service with AudioServiceBackground.setMediaItem, perhaps a color argument can be included, which would be used to set the notification color?

Describe alternatives you've considered There are none.

Additional context

ryanheise commented 3 years ago

I like it. Sounds like a good idea to me.

I suspect there is a similar capability on iOS, so I also don't think the name needs an android prefix.

hacker1024 commented 3 years ago

I've started implementing this (on the Android side), but the setColor method doesn't seem to be doing anything. I suspect Android 11 doesn't let you use a custom color - I'm launching an Android 10 VM to test.

hacker1024 commented 3 years ago

Not only does Android 11 block the use of custom colors, but versions from Oreo onwards only allow setting the forground colors, and not the background colors. It looks like this idea's a bust.

The current behaviour, however, also only works under those conditions, so perhaps allowing per-item custom colors on older devices is still a worthwile change, especially if it can be done on modern versions of iOS.