我正在尝试创建一个通知栏,用于使用前台服务播放音乐。我想确定在通知中单击了exoplayer的哪个控件,例如播放,暂停,快退,快进等。
下面是我的代码段,
object : PlayerNotificationManager.CustomActionReceiver {
override fun createCustomActions(context: Context?, instanceId: Int): MutableMap<String,
NotificationCompat.Action> {
// return mutableMapOf()
val prevAction = Intent()
prevAction.putExtra("action", actions[0])
val backwordAction = Intent()
backwordAction.putExtra("action", actions[1])
val playAction = Intent()
playAction.putExtra("action", actions[2])
val pauseAction = Intent()
pauseAction.putExtra("action", actions[3])
val forwardAction = Intent()
forwardAction.putExtra("action", actions[4])
val nextAction = Intent()
nextAction.putExtra("action", actions[5])
return mutableMapOf(
Pair(actions[0], NotificationCompat.Action(R.drawable.exo_icon_previous, actions[0],
PendingIntent.getBroadcast(context, 0, Intent(prevAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT))),
Pair(actions[1], NotificationCompat.Action(R.drawable.exo_icon_rewind, actions[1],
PendingIntent.getBroadcast(context, 0, Intent(backwordAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT))),
Pair(actions[2], NotificationCompat.Action(R.drawable.exo_icon_play, actions[2],
PendingIntent.getBroadcast(context, 0, Intent(playAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT))),
Pair(actions[3], NotificationCompat.Action(R.drawable.exo_icon_pause, actions[3],
PendingIntent.getBroadcast(context, 0, Intent(pauseAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT))),
Pair(actions[4], NotificationCompat.Action(R.drawable.exo_icon_fastforward, actions[4],
PendingIntent.getBroadcast(context, 0, Intent(forwardAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT))),
Pair(actions[5], NotificationCompat.Action(R.drawable.exo_icon_next, actions[5],
PendingIntent.getBroadcast(context, 0, Intent(nextAction).setPackage(context?.packageName), PendingIntent.FLAG_CANCEL_CURRENT)))
)
}
override fun getCustomActions(player: Player?): MutableList<String> {
return actions
}
override fun onCustomAction(player: Player?, action: String?, intent: Intent?) {
LogUtils.e(action ?: "")
}
}
现在,图标显示在通知栏上,但是如果按此按钮,它将不执行任何操作,也不会调用“ onCustomAction”。即使我在创建Action实例时传递了endingIntent,它也不会调用“ onCustomAction”。
任何人都可以帮忙吗?