media icon indicating copy to clipboard operation
media copied to clipboard

How to disable track timeline on notification using last version of media3

Open GitlabUser1337 opened this issue 2 years ago • 2 comments

I am using my implementation of MediaNotification.Provider for notification config, please advise how to hide rewind bar

override fun createNotification(
        session: MediaSession,
        customLayout: ImmutableList<CommandButton>,
        actionFactory: MediaNotification.ActionFactory,
        onNotificationChangedCallback: MediaNotification.Provider.Callback
): MediaNotification {

    val playPauseAction = actionFactory.createMediaAction(
            session,
            IconCompat.createWithResource(context, R.drawable.media3_notification_play),
            "Play",
            Player.COMMAND_PLAY_PAUSE
    )
  
    val mediaStyle = MediaStyleNotificationHelper.MediaStyle(session)
            .setShowCancelButton(false)
            .setShowActionsInCompactView(0)

    if (player.isCommandAvailable(Player.COMMAND_STOP) || Util.SDK_INT < 21) {
        mediaStyle.setCancelButtonIntent(
                actionFactory.createMediaActionPendingIntent(session, Player.COMMAND_STOP.toLong()))
    }


    val notificationBuilder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID).apply {
        addAction(playPauseAction)
        setStyle(mediaStyle)
        setShowWhen(false)
        setUsesChronometer(false)
        setContentIntent(session.sessionActivity)
        setDeleteIntent(actionFactory.createMediaActionPendingIntent(session, Player.COMMAND_STOP.toLong()))
        setSmallIcon(R.drawable.media3_notification_small_icon)
        setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
        setOngoing(false)
        setContentTitle("TITLE")
        setContentText("TEXT")
    }

    return MediaNotification(NOTIFICATION_ID, notificationBuilder.build())
}

333

GitlabUser1337 avatar Aug 26 '22 07:08 GitlabUser1337

A general note: API levels from and above 31 create the notification from the information available in the media session rather than in the notification. Below 31 until 29(?) a mixture from notification/media session information is used. So please make sure to test your custom MediaNotificaition.Provider with all the relevant API levels that produce different notifications (probably something like the following API buckets: API 16 - 21, API 21 - 28, API 29 - 30, API 31 - 32).

For the specific ask regarding disable the seek bar there are two options. The first is not yet implemented I'm afraid and you may want to wait until this is done. We are currently working on this (marking as bug for this reason to track this):

1. Making ACTION_SEEK_TO unavailable in the legacy media session

The notification will only allow seeking when ACTION_SEEK_TO is available. The actions available in the legacy session need to be mapped from player.getAvailableCommands(). This mapping is currently not implemented. Once it is implemented, making the SEEK+* commands unavailable will create a notification that indicates the seek bar with the current duration, but no handle is available the user could use to seek:

media_notification_2

2. Make player.getDuration() return C.TIME_UNSET

The seek bar in the notification is only shown when the metadata in the legacy/platform media session has the duration set. So you can use a ForwardinPlayer that overrides getDuration and always returns C.TIME_UNSET.

That gives you a notification without a handle for seeking and, because the duration is not known, also doesn't show the current duration. That's not a nice solution but it is what you can do right now:

media_notification

marcbaechinger avatar Aug 30 '22 16:08 marcbaechinger

The second option really works, but I'd better wait for the official implementation

GitlabUser1337 avatar Aug 30 '22 18:08 GitlabUser1337

Closing and marking as duplicate of #140. We will update the other issue as soon as we have pushed the commit that maps the available commands to the legacy playback state.

marcbaechinger avatar Sep 30 '22 18:09 marcbaechinger