0

I using MediaSessionService from Media3 to play audio in background. I update player notification using setMediaNotificationProvider. but in android 11(API 30) and up, the title, content text, and large icon are not changing and showing default things related to audio file. is this a bug or am I missing some things?

val mediaNotificationProvider = object : MediaNotification.Provider{
    override fun createNotification(
        mediaSession: MediaSession,
        customLayout: ImmutableList<CommandButton>,
        actionFactory: MediaNotification.ActionFactory,
        onNotificationChangedCallback: MediaNotification.Provider.Callback
    ): MediaNotification {
        createMediaNotification(mediaSession)
        return MediaNotification(NOTIFICATION_ID, notificationBuilder.build())
    }

    override fun handleCustomCommand(
        session: MediaSession,
        action: String,
        extras: Bundle
    ): Boolean {
        return false
    }
}

private lateinit var notificationBuilder: NotificationCompat.Builder

fun  createMediaNotification(
    session: MediaSession,
) {
    notificationBuilder = NotificationCompat.Builder(context,
        NOTIFICATION_CHANNEL_ID
    )
        .setSmallIcon(R.drawable.notification)
        .setContentTitle("test title")
        .setContentText("test text")
        .setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_large_icon))
        .setStyle(MediaStyleNotificationHelper.MediaStyle(session))

}
Hadi Ahmadi
  • 1,924
  • 2
  • 17
  • 38

1 Answers1

0

My code was correct and the problem was only a bug in Media3. by downgrading media3 from 1.0.1 to 1.0.0-beta03 my code works now!

Hadi Ahmadi
  • 1,924
  • 2
  • 17
  • 38