Customising Jetpack Media3 player notification — Chapter II — Overriding default icons

A Poplawski
3 min readNov 15, 2023

--

Background

I recently got a chance to work on Media3 player notification for my current company. Even though the task seemed easy at first, I found it to be relatively difficult, because:
- There was no official guide on the “go to way” to customize player notification.
- Multiple sources still referencing PlayerNotificationManager. As Media3 documentation says:

The PlayerNotificationManager from ExoPlayer is no longer needed, as Media3’s MediaSessionService and MediaLibraryService automatically handle publishing a media notification as needed.

I will share with you the journey in a form of simple, step-by-step guide on how to customise player notification with Media3.

We will go from this…

Default state for notification player

To this…

Desired state with rewind/forward commands

Steps required:
1. Add rewind/forward custom commands
2. Override play/pause icons
3. Rearrange commands on the notification to achieve [REWIND, PLAY/PAUSE, FORWARD] order

NOTE: Even though notification UI may differ on your device, depending on the brand, model and Android system version, steps mentioned in this guide should still bring us to the desired end result.

Implementation — Chapter II —Override notification icon resource

As you know from chapter I of the article, play/pause is a default action, as opposed to rewind/forward ones, which are provided “from outside” by us. But what if we want to use our own, custom, branded icons?

Luckily, it’s very simple.

As DefaultMediaNotificationProvider documentation says:

The drawables used can be overridden by drawables with the same file names in res/drawables of the application module. Alternatively, you can override the drawable resource ID with a drawable element in a resource file in res/values.

The drawable resource IDs are:
media3_notification_play — The play icon.
media3_notification_pause — The pause icon.
media3_notification_seek_to_previous — The previous icon.
media3_notification_seek_to_next — The next icon.
media3_notification_small_icon — The small icon. A different icon can be set with setSmallIcon(int).

So, let’s do it.

  • Add/import your icons for play/pause
  • Name them media3_notification_play/media3_notification_pause
Notification player with overridden play/pause icon

There we go. We managed to override default notification icons.

In the last part, I’ll cover rearranging the order of notification commands.

Chapter I: https://medium.com/@a.poplawski96/customising-jetpack-media3-player-notification-chapter-i-adding-custom-commands-3cd16256e0e0
Chapter III: https://medium.com/@a.poplawski96/customising-jetpack-media3-player-notification-chapter-iii-rearranging-buttons-order-ea62ede798b0

Thanks for reading my friend! I write more about Android, Kotlin and programming itself, so if you’re interested in this topic, consider following and seeing my other articles.

And also, let’s connect!
https://www.linkedin.com/in/apoplawski96/

--

--

A Poplawski

Creating Android apps since 2019 - Android, Android TV & Kotlin Multiplatform. Trying to share useful information in a digestible manner.