5

I'm using PlayerNotificationManager for displaying playback notifications in my application. Everything is working fine but I want to add my application's logo in the notification with custom fonts.

I changed the play & pause buttons on the notification by adding drawables.xml. But can't find a way to change the font.

So, how can I change the default notification layout and characteristics that Exoplayer provides?

Edit: I have seen this issue on Github which says that we need to extend PlayerNotificationManager in order to use custom layout. But I can't seem to get it working.

Here is my code:

 private void setPlayerNotificationManager(Player player) {


    playerNotificationManager = new PlayerNotificationManager(context, "123", 1234, mediaDescriptionAdapter);
    playerNotificationManager.setUseNavigationActions(false);
    playerNotificationManager.setUsePlayPauseActions(true);
    playerNotificationManager.setRewindIncrementMs(0);
    playerNotificationManager.setFastForwardIncrementMs(0);
    //playerNotificationManager.setColor(Color.GREEN);
    playerNotificationManager.setColorized(true);
    playerNotificationManager.setUseChronometer(false);
    playerNotificationManager.setSmallIcon(R.drawable.logo);
    playerNotificationManager.setPlayer(player);

}
null_override
  • 467
  • 3
  • 10
  • 30
  • I've look around in the exoplayer documentation and source but I haven't found anything you could use directly, you should probably ask directly on the repo – Biscuit Oct 19 '20 at 08:33
  • Yesterday, I have seen an issue on the repo where it is told that, we have to extend `playerNotificationManager` class to use custom layout. But I couldn’t get it working. Any ideas on that? – null_override Oct 19 '20 at 08:37
  • @Biscuit Here is the link to the issue on Github: https://github.com/google/ExoPlayer/issues/7576 – null_override Oct 19 '20 at 08:43

1 Answers1

4

As said on the repo you need to extends the PlayerNotificationManager to do that you need to create this class and copy everything inside your project, and then add the layout you want to use as described in this link

You need to add your layout in the builder here

Biscuit
  • 4,840
  • 4
  • 26
  • 54
  • I copied the whole class & made the changes. It's not working. The default notification layout prevails. Any ideas? – null_override Oct 19 '20 at 12:10
  • 1
    Have you changed the import in the file that contains your function `setPlayerNotificationManager ` ? You need to import `PlayerNotificationManager` from your project and not the one from `Exoplayer` – Biscuit Oct 19 '20 at 12:46
  • Yes, I have changed that. Also registered the Broadcast receiver in my Manifest. It is declared in here: https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java#L1365 – null_override Oct 19 '20 at 12:54
  • Now, my custom layout loads but without any buttons. I don't know how to add that in the layout ( I mean the button id's) – null_override Oct 19 '20 at 12:56
  • 1
    I'm not sure about what you're missing but take a look at that https://developer.android.com/training/notify-user/build-notification#Actions to add button to your layout, basically you need to re-do what `Exoplayer` was doing for you in the background – Biscuit Oct 19 '20 at 13:03
  • 1
    Thanks for your help. I have achieved what I wanted. One thing I want to say that, I have started learning exoplayer for just 10 days. Stack Overflow helped me a lot! – null_override Oct 19 '20 at 20:13
  • 1
    I'm glad you succeed in what you were trying to do – Biscuit Oct 20 '20 at 14:06