0

Am building an music player app. I want to implement media controller in notification bar. I have tried one method http://www.binpress.com/tutorial/using-android-media-style-notifications-with-media-session-controls/165. But it only supports lollipop version of android. Does anyone have idea to build media controller in notification bar ?

Bincy Baby
  • 3,941
  • 5
  • 36
  • 62

1 Answers1

1

You have to use NotificationCompat with MediaStyle: https://developer.android.com/reference/android/support/v7/app/NotificationCompat.MediaStyle.html

Notification noti = new NotificationCompat.Builder()
 .setSmallIcon(R.drawable.ic_stat_player)
 .setContentTitle("Track title")
 .setContentText("Artist - Album")
 .setLargeIcon(albumArtBitmap))
 .setStyle(new NotificationCompat.MediaStyle()
     .setMediaSession(mySession))
 .build();

A full example of implementing mediaSessionCompat with NotificationCompat can be found here: https://bitbucket.org/nonameden/android-universalmusicplayer-compat/src/412465d6605fee26f197cc5615f7da15cc859d4a/mobile/src/main/java/com/example/android/uamp/MediaNotificationManager.java?at=master

Martijn00
  • 3,569
  • 3
  • 22
  • 39
  • i checked the link you share but unable to understand the code so if it is possible so can you please share detailed code i know how to set notification but stuck in another problem like change the lock screen background and control buttons on lock screen check this https://stackoverflow.com/questions/54595575/how-to-set-this-type-of-view-for-a-notification – Vipul Chauhan Feb 11 '19 at 07:20