Exoplayer通知图像添加

时间:2019-01-08 08:29:03

标签: notifications exoplayer

我正在exoplayer中使用PlayerNotificationManager。

请让我们所有人知道以下内容...

How to set custom image in Exoplayer Notification with action handler.
How to set subtext in Exoplayer Notification.
Will be of great help. Thank you.

1 个答案:

答案 0 :(得分:0)

您可以在创建MediaDescriptionAdapter时这样做:

在下面的代码中,trackTitletrackSubtitleimageUri是要在通知中显示的数据。

该图片与Glide异步加载,并且通知图片在callBack中进行了更新。

希望有帮助! BR的问候!

    private fun getMediaDescriptionAdapter(
        trackTitle: String,
        trackSubtitle: String
    ): PlayerNotificationManager.MediaDescriptionAdapter {
        return object : PlayerNotificationManager.MediaDescriptionAdapter {
            override fun createCurrentContentIntent(player: Player?): PendingIntent? {
                val intent = Intent(applicationContext, MainActivity::class.java)
                return PendingIntent.getActivity(
                    applicationContext,
                    0,
                    intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
                )
            }

            override fun getCurrentContentText(player: Player?): String? {
                return trackSubtitle
            }

            override fun getCurrentContentTitle(player: Player?): String {
                return trackTitle
            }

            override fun getCurrentLargeIcon(
                player: Player?,
                callback: PlayerNotificationManager.BitmapCallback?
            ): Bitmap? {

                if (trackPlaybackState.imageUri == null) return null

                // load the media image asyncronously
                val thread = Thread {
                    try {
                        val uri = Uri.parse(trackPlaybackState.imageUri.toString())
                        val bitmap = Glide.with(applicationContext)
                            .asBitmap()
                            .load(uri)
                            .submit().get()

                        trackImage = bitmap
                        callback?.onBitmap(bitmap)
                    } catch (e: ExecutionException) {
                        e.printStackTrace()
                    } catch (e: InterruptedException) {
                        e.printStackTrace()
                    }
                }
                thread.start()

                return trackImage
            }
        }
    }