0

我正在使用最新版本的 Exoplayer (2.16.1)。我使用下面的代码创建前台服务通知,但它带有通知声音。我怎样才能防止这种声音?

 override fun onCreate() {
    super.onCreate()

    playerNotificationManager = PlayerNotificationManager
        .Builder(this, 9998, NOTIFICATION_CHANNEL_ID)
        .setMediaDescriptionAdapter(PlayerNotificationAdapter())
        .setChannelImportance(IMPORTANCE_HIGH)
        .setNotificationListener(object : PlayerNotificationManager.NotificationListener {
            override fun onNotificationPosted(
                notificationId: Int,
                notification: Notification,
                ongoing: Boolean
            ) {
                super.onNotificationPosted(notificationId, notification, ongoing)
                if (ongoing) {
                    startForeground(notificationId, notification)
                }
            }

            override fun onNotificationCancelled(
                notificationId: Int,
                dismissedByUser: Boolean
            ) {
                super.onNotificationCancelled(notificationId, dismissedByUser)
                stopSelf()
                stopForeground(false)
            }
        })
        .setChannelNameResourceId(R.string.NotificationChannelName)
        .setChannelDescriptionResourceId(R.string.NotificationChannelDescription)
        .build()

    playerNotificationManager.setSmallIcon(R.drawable.ic_play)
    playerNotificationManager.setPriority(PRIORITY_MAX)
    playerNotificationManager.setPlayer(musicPlayerManager.exoPlayer)

    mediaSessionCompat = MediaSessionCompat(this, MEDIA_SESSION_TAG)
    mediaSessionCompat.isActive = true
    playerNotificationManager.setMediaSessionToken(mediaSessionCompat.sessionToken)

    mediaSessionConnector = MediaSessionConnector(mediaSessionCompat)

    val timelineQueueNavigator = object : TimelineQueueNavigator(mediaSessionCompat) {
        override fun getMediaDescription(
            player: Player,
            windowIndex: Int
        ): MediaDescriptionCompat {
            return MediaDescriptionCompat.Builder().build()
        }
    }
    mediaSessionConnector.setQueueNavigator(timelineQueueNavigator)
    mediaSessionConnector.setPlayer(musicPlayerManager.exoPlayer)
}

请注意,我想使用 Exoplayer 的 PlayerNotificationManager 来创建通知。

4

1 回答 1

0

您可以设置: playerNotificationManager.setPriority(PRIORITY_DEFAULT) 在这种情况下发出静默通知

于 2022-01-06T18:12:04.687 回答