내 앱에서 나는 음악 재생을 담당하는 포 그라운드 서비스와 함께 알림을 표시했습니다. 알림은com.google.android.exoplayer2.ui.PlayerNotificationManager
android.support.v4.media.session.MediaSessionCompat
com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
mediaSession = MediaSessionCompat(this, "Player", null, null)
mediaSession.isActive = true
mediaSessionConnector = MediaSessionConnector(mediaSession)
mediaSessionConnector.setPlayer(exoPlayer)
playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
this,
"notification_channel_player",
R.string.notification_channel_name_player,
0,
PLAYER_NOTIFICATION_ID,
object : PlayerNotificationManager.MediaDescriptionAdapter {
override fun createCurrentContentIntent(player: Player?): PendingIntent? {
// intent
}
override fun getCurrentLargeIcon(player: Player?, callback: PlayerNotificationManager.BitmapCallback?): Bitmap? {
// large icon
}
override fun getCurrentContentText(player: Player?): String? {
// artist
}
override fun getCurrentContentTitle(player: Player?): String {
// title
}
},
object : NotificationListener {
override fun onNotificationPosted(notificationId: Int, notification: Notification?, ongoing: Boolean) {
startForeground(notificationId, notification)
}
})
playerNotificationManager.setSmallIcon(R.drawable.ic_notification)
// has previous and next
playerNotificationManager.setUseNavigationActions(true)
playerNotificationManager.setUseNavigationActionsInCompactView(true)
// no fast-forward and rewind
playerNotificationManager.setFastForwardIncrementMs(0)
playerNotificationManager.setRewindIncrementMs(0)
// no stop
playerNotificationManager.setUseStopAction(false)
playerNotificationManager.setMediaSessionToken(mediaSession.sessionToken)
playerNotificationManager.setPlayer(exoPlayer)
화면이 켜져 있으면 콘텐츠 제목과 텍스트를 표시하는 데 문제가 없습니다. 하지만 화면을 잠그고 AOD 모드에서 Pixel 3에 "제목 없음"이 표시됩니다. 하지만 Apple Music을 사용하면 제목과 아티스트가 잘 표시됩니다.
내 질문은 현재 구현을 기반으로이 제목과 텍스트를 어떻게 구성 할 수 있습니까? 감사.
나는 문제를 발견하고 해결했기 때문에 내 질문에 대답합니다.
알림의 미디어 설명 어댑터 만 설정했지만 실제로 미디어 세션에서도 메타 데이터를 설정해야합니다. 우리가 사용하고 있기 때문에 mediaSessionConnector
, 그것은 전달하여 설정을 할 수 있습니다 QueueNavigator
받는 사람을 mediaSessionConnector
우리가 현재 미디어의 메타 데이터를 구축하기 위해 플레이어 인스턴스 및 창 인덱스를 사용할 수 있습니다. 전의:
val timelineQueueNavigator = object : TimelineQueueNavigator(mediaSession) {
override fun getMediaDescription(player: Player?, windowIndex: Int): MediaDescriptionCompat {
player?.let { safePlayer ->
return MediaDescriptionCompat.Builder().apply {
setTitle("......")
setSubtitle("......")
}.build()
}
return MediaDescriptionCompat.Builder().build()
}
}
mediaSessionConnector.setQueueNavigator(timelineQueueNavigator)
또 다른 점은 기본적으로이다 mediaSessionConnector
사용 MediaSessionConnector.DefaultMediaMetadataProvider
. METADATA_KEY_ARTIST
AOD 모드에서 아티스트로 사용할 설정은 없습니다 . 그래서 내 자신의 MediaMetadataProvider를 만들어 METADATA_KEY_ARTIST
.
if (description.subtitle != null) {
val subTitle = description.subtitle.toString()
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, subTitle)
builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, subTitle)
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다