Using setProgress in notification builder not working with Media Style Notification

1k Views Asked by At

I'm trying to use .setProgress() on a NotificationBuilder but it seems the pogressBar won't appear if I use MediaStyle:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this,CHANNEL);

builder
  .setSmallIcon(R.drawable.logo)
  // more configuration
  .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
               .setShowActionsInCompactView(1)
               // more config
               .setMediaSession(mediaSession.getSessionToken()))

if(isBuffering){
  builder.setProgres(0,0, true);
}

If I remove the .setStyle the progress bar appears as supposed but with MediaStyle it won't.

Does anyone know if there is a way to make both compatible?

Thanks

1

There are 1 best solutions below

0
On

Same question, now I can set max duration in the seekbar

    mMediaPlayer?.setOnBufferingUpdateListener { mp, percent ->
        if (percent == 100){
            val mediaMetadata = MediaMetadata.Builder().putLong(MediaMetadata.METADATA_KEY_DURATION, mp.duration.toLong()).build()
            mediaSession.setMetadata(MediaMetadataCompat.fromMediaMetadata(mediaMetadata))
            return@setOnBufferingUpdateListener
        }
    }

but It will appear after buffering is done, quite lame