【发布时间】:2020-12-03 10:01:35
【问题描述】:
我在使用 exoplayer 的 PlayerNotificationManager 显示玩家通知时遇到了一个非常奇怪的问题。我正在使用以下代码在前台显示通知:
class AudioPlayerService : LifecycleService() {
private val notificationListener = object : PlayerNotificationManager.NotificationListener {
override fun onNotificationPosted(
notificationId: Int,
notification: Notification,
ongoing: Boolean
) {
super.onNotificationPosted(notificationId, notification, ongoing)
if (ongoing)
startForeground(notificationId, notification)
else
stopForeground(false)
}
}
override fun onCreate() {
super.onCreate()
playerNotificationManager = PlayerNotificationManager(
this,
CHANNEL_ID,
NOTIFICATION_ID,
descriptionAdapter,
notificationListener
).apply {
setFastForwardIncrementMs(0)
setRewindIncrementMs(0)
setUseNextAction(false)
setUsePreviousAction(false)
setUseStopAction(false)
setUseChronometer(false)
}
//...
}
override fun onDestroy() {
releasePlayer()
super.onDestroy()
}
//...
}
当正在播放音乐并且应用程序被终止(最近清除)、通知持续并且音乐继续播放时,它按预期工作。
但是如果暂停音乐并清除通知(应将其清除为音乐未播放),然后杀死应用程序,它会显示带有暂停按钮的不可关闭通知(不应显示)但暂停按钮不起作用并且音频也没有播放。
当应用被杀死且播放器处于暂停状态时,如何防止显示通知?
【问题讨论】:
标签: android exoplayer exoplayer2.x