我正在使用exoplayer
构建音频播放器。当我的音频播放器启动时,我会附上一个通知。当使用通知暂停按钮暂停/停止播放器时,通知背景颜色会发生变化。这是测试代码。
playerNotificationManger
我尝试在被调用时再次设置通知颜色,stopForeground(false)
但没有帮助。
if (it == StreamState.STOPPED) {
this.stopForeground(false)
}
else if (it == StreamState.STARTED) {
val channelId = "media_playback_channel"
exoNotificationListener = ExoNotificationListener(onNotificationPosted, onNotificationCancelled)
playerNotificationManager = playerNotificationManager ?: PlayerNotificationManager.createWithNotificationChannel(
application.applicationContext,
channelId,
R.string.media_playback_notification,
R.string.media_playback_notification_id,
mcNotificationManager,
exoNotificationListener
)
playerNotificationManager?.setFastForwardIncrementMs(0)
playerNotificationManager?.setRewindIncrementMs(0)
playerNotificationManager?.setUseNavigationActions(false)
// Here I am setting the color which works fine when content is playing.
playerNotificationManager?.setColor(notificationColor)
bindPlayer(playerNotificationManager)
}
当我再次开始播放时,通知颜色又回来了。当 stopForeground 发生时,我不希望通知颜色发生变化。你能建议我做错什么吗?