Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable or hide seekbar in MediaStyle notifications

Trying to build a live stream media playback app, the media style notifications in 28 and below sdk looks good without any seekbar, but when running same application in Android 10 (SDK 29) the notification is showing additional seekbar which i don't want since the stream is live and i am using default exoplayer (exo vers. 2.10.8) behavior to cache.

How do i disable or hide the seekbar?

tried setting below in notification builder:

.setProgress(0,0,true)

Snippet of notification below :

    Notification notification = new Notification.Builder(this,Constant.CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_logo)
            .setContentTitle(title)
            .setContentText(message)
            .setLargeIcon(artwork)
            .addAction(new Notification.Action.Builder(
                    Icon.createWithResource(getApplicationContext(),playPauseResourceId),
                    "Play/Pause",
                    playPausePendingIntent).build())
            .addAction(new Notification.Action.Builder(
                    Icon.createWithResource(getApplicationContext(),R.drawable.exo_icon_stop),
                    "Play/Pause",
                    stopPendingIntent).build())
            .setStyle(new Notification.MediaStyle().setShowActionsInCompactView(0).setMediaSession(mediaSession.getSessionToken()))
            .setSubText(subText)
            .setContentIntent(pendingActivityIntent)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setProgress(0,0,true)
            .build();

Screeshot :

enter image description here

like image 225
MantiCore Avatar asked Dec 22 '19 09:12

MantiCore


People also ask

How do I hide Seekbar in Exoplayer?

You can do it simply by creating a layout named: exo_playback_control_view. xml and override the regular XML. On this one below is the standard XML, You can add android:visiblite="invisible" for DefaultTimeBar which is what I think you're trying to hide, if not feel free change it as you want.


1 Answers

I also encountered this problem, but I am using NotificationCompat instead of exoplayer.
I followed Squti's answer and found the solution to hide the seek bar for NotificationCompat.

val mediaSession = MediaSessionCompat(context, "your tag")

//These two lines work
val mediaMetadata = MediaMetadata.Builder().putLong(MediaMetadata.METADATA_KEY_DURATION, -1L).build()
mediaSession.setMetadata(MediaMetadataCompat.fromMediaMetadata(mediaMetadata))

val token = mediaSession.sessionToken

val mBuilder = NotificationCompat.Builder(context, channelId)
    .setStyle(androidx.media.app.NotificationCompat.MediaStyle()
            .setMediaSession(token))
like image 117
GreatC Avatar answered Nov 10 '22 23:11

GreatC