如何在 Android 11+ 的 Media3 中更改播放器通知标题和大图标?

问题描述 投票:0回答:0

我使用

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))

}
android android-notifications android-mediasession android-media3
© www.soinside.com 2019 - 2024. All rights reserved.