我正在使用PlayerNotificationManager与Exoplayer和Android 10通知托盘在startForeground()上可见,但在我的一个手机中,当我升级到Android 11时,媒体播放器的通知托盘停止显示。
请帮助! !
这里我在Google Pixel Now上调试:
可以在Google Pixel android 11上工作,但不能在三星G973F上工作。为什么这对三星不起作用?
在这里,我出现了git ExoPlayer的问题,这是一个设备特定的问题,这是那个问题的链接,
https://github.com/google/ExoPlayer/issues/8500
使用MediaSessionConnector与ExoPlayer PlayerNotificationManager和mediasession:
https://github.com/google/ExoPlayer/tree/release-v2/extensions/mediasession
这里有使用MediaSession和MediaSessionConnector更简单:
https://developer.android.com/codelabs/supporting-mediasession
给你,我还没有测试过,但我认为这将工作,
// 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)
查看此链接以获得完整的指南https://android-developers.googleblog.com/2020/08/playing-nicely-with-media-controls.html