为什么 PlayerNotificationManager 不在 Android 11(R) 中的 startForeground 上显示通知?
Why PlayerNotificationManager not showing Notification on startForeground in Android 11(R)?
我将 PlayerNotificationManager 与 Exoplayer 一起使用,最多 Android 10 个通知托盘在 startForeground() 上可见,但在我升级到 Android 11 时,在我的 phone 之一中,媒体播放器的通知托盘停止显示。
请帮忙!!
这里我在 Google Pixel Now 上调试:
正在 Google Pixel android 11 上工作,但不在三星 G973F 上。
为什么这不适用于三星?
给你,我没有测试过这个,但我认为这会起作用,
// Create a media session. NotificationCompat.MediaStyle
// PlayerService is your own Service or Activity responsible for media playback.
val mediaSession = MediaSessionCompat(this, "PlayerService")
// Create a MediaStyle object and supply your media session token to it.
val mediaStyle = Notification.MediaStyle().setMediaSession(mediaSession.sessionToken)
// Create a Notification which is styled by your MediaStyle object.
// This connects your media session to the media controls.
// Don't forget to include a small icon.
val notification = Notification.Builder(this@PlayerService, CHANNEL_ID)
.setStyle(mediaStyle)
.setSmallIcon(R.drawable.ic_app_logo)
.build()
// Specify any actions which your users can perform, such as pausing and skipping to
the next track.
val pauseAction: Notification.Action = Notification.Action.Builder(
pauseIcon, "Pause", pauseIntent
).build()
notification.addAction(pauseAction)
查看此 link 以获取完整指南
https://android-developers.googleblog.com/2020/08/playing-nicely-with-media-controls.html
在这里,我在 git ExoPlayer 上出现了问题,这是一个特定于设备的问题,
所以,这是那个问题的link,
https://github.com/google/ExoPlayer/issues/8500
将 MediaSessionConnector 与 ExoPlayer PlayerNotificationManager 和 MediaSessions 结合使用:
https://github.com/google/ExoPlayer/tree/release-v2/extensions/mediasession
这里简单介绍一下MediaSession和MediaSessionConnector的使用:
https://developer.android.com/codelabs/supporting-mediasession
我将 PlayerNotificationManager 与 Exoplayer 一起使用,最多 Android 10 个通知托盘在 startForeground() 上可见,但在我升级到 Android 11 时,在我的 phone 之一中,媒体播放器的通知托盘停止显示。
请帮忙!!
这里我在 Google Pixel Now 上调试:
正在 Google Pixel android 11 上工作,但不在三星 G973F 上。 为什么这不适用于三星?
给你,我没有测试过这个,但我认为这会起作用,
// Create a media session. NotificationCompat.MediaStyle
// PlayerService is your own Service or Activity responsible for media playback.
val mediaSession = MediaSessionCompat(this, "PlayerService")
// Create a MediaStyle object and supply your media session token to it.
val mediaStyle = Notification.MediaStyle().setMediaSession(mediaSession.sessionToken)
// Create a Notification which is styled by your MediaStyle object.
// This connects your media session to the media controls.
// Don't forget to include a small icon.
val notification = Notification.Builder(this@PlayerService, CHANNEL_ID)
.setStyle(mediaStyle)
.setSmallIcon(R.drawable.ic_app_logo)
.build()
// Specify any actions which your users can perform, such as pausing and skipping to
the next track.
val pauseAction: Notification.Action = Notification.Action.Builder(
pauseIcon, "Pause", pauseIntent
).build()
notification.addAction(pauseAction)
查看此 link 以获取完整指南 https://android-developers.googleblog.com/2020/08/playing-nicely-with-media-controls.html
在这里,我在 git ExoPlayer 上出现了问题,这是一个特定于设备的问题, 所以,这是那个问题的link,
https://github.com/google/ExoPlayer/issues/8500
将 MediaSessionConnector 与 ExoPlayer PlayerNotificationManager 和 MediaSessions 结合使用:
https://github.com/google/ExoPlayer/tree/release-v2/extensions/mediasession
这里简单介绍一下MediaSession和MediaSessionConnector的使用:
https://developer.android.com/codelabs/supporting-mediasession