我使用
MediaSessionService
的Media3
在后台播放音频。
我使用 setMediaNotificationProvider
更新玩家通知。但在 android 11(API 30)及更高版本中,标题、内容文本和大图标没有改变,并显示与音频文件相关的默认内容。这是一个错误还是我遗漏了一些东西?
val mediaNotificationProvider = object : MediaNotification.Provider{
override fun createNotification(
mediaSession: MediaSession,
customLayout: ImmutableList<CommandButton>,
actionFactory: MediaNotification.ActionFactory,
onNotificationChangedCallback: MediaNotification.Provider.Callback
): MediaNotification {
createMediaNotification(mediaSession)
return MediaNotification(NOTIFICATION_ID, notificationBuilder.build())
}
override fun handleCustomCommand(
session: MediaSession,
action: String,
extras: Bundle
): Boolean {
return false
}
}
private lateinit var notificationBuilder: NotificationCompat.Builder
fun createMediaNotification(
session: MediaSession,
) {
notificationBuilder = NotificationCompat.Builder(context,
NOTIFICATION_CHANNEL_ID
)
.setSmallIcon(R.drawable.notification)
.setContentTitle("test title")
.setContentText("test text")
.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_large_icon))
.setStyle(MediaStyleNotificationHelper.MediaStyle(session))
}