gpt4 book ai didi

android - 如何修复此 PlayerNotificationManager.createWithNotificationChannel 错误

转载 作者:行者123 更新时间:2023-12-04 23:55:57 26 4
gpt4 key购买 nike

enter image description here
我正在开发一个音乐应用程序,但我遇到了错误,谁能告诉我如何解决这个问题PlayerNotificationManager.createWithNotificationChannel ?.createWithNotificationChannel无法识别

class MusicNotificationManager(
private val context: Context,
sessionToken: MediaSessionCompat.Token,
notificationListener: PlayerNotificationManager.NotificationListener,
private val newSongCallback: () -> Unit
) {
//creating notification for music player
private val notificationManager: PlayerNotificationManager

init {
val mediaController = MediaControllerCompat(context, sessionToken)
notificationManager = PlayerNotificationManager.createWithNotificationChannel(
context,
NOTIFICATION_CHANNEL_ID,
R.string.notification_channel_name,
R.string.notification_channel_description,
NOTIFICATION_ID,
DescriptionAdapter(mediaController),
notificationListener
).apply{
setSmallIcon(R.drawable.ic_music)
setMediaSessionToken(sessionToken)
}
}

fun showNotification(player: Player){
notificationManager.setPlayer(player)
}
//get current playing song
private inner class DescriptionAdapter(
private val mediaController: MediaControllerCompat
): PlayerNotificationManager.MediaDescriptionAdapter {
override fun getCurrentContentTitle(player: Player): CharSequence {
newSongCallback()
return mediaController.metadata.description.title.toString()

}

override fun createCurrentContentIntent(player: Player): PendingIntent? {
return mediaController.sessionActivity
}
//get current playing song title
override fun getCurrentContentText(player: Player): CharSequence? {
return mediaController.metadata.description.subtitle.toString()
}
//get current playing song icon
override fun getCurrentLargeIcon(
player: Player,
callback: PlayerNotificationManager.BitmapCallback
): Bitmap? {
Glide.with(context).asBitmap()
.load(mediaController.metadata.description.iconUri)
.into(object : CustomTarget<Bitmap>(){
override fun onResourceReady(
resource: Bitmap,
transition: Transition<in Bitmap>?
) {
callback.onBitmap(resource)
}

override fun onLoadCleared(placeholder: Drawable?) = Unit
})
return null
}
}
}
我试图在我的 build.gradle 文件中添加所有可能的依赖项,但无法解决此问题。

最佳答案

PlayerNotificationManager.createWithNotificationChannel()已弃用。以下是实现相同功能的方法:

private val notificationManager: PlayerNotificationManager  

Use Builder
init {
val mediaController = MediaControllerCompat(context, sessionToken)

notificationManager = PlayerNotificationManager.Builder(
context,
NOTIFICATION_ID, CHANNEL_ID)
.setChannelNameResourceId(R.string.notification_Channel_name)
.setChannelDescriptionResourceId(R.string.notification_Channel_Description)
.setMediaDescriptionAdapter(DescriptionAdapter(mediaController))
.setNotificationListener(notificationListener)
.build()

}

关于android - 如何修复此 PlayerNotificationManager.createWithNotificationChannel 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69306536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com