首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么PlayerNotificationManager不在安卓11(R)的startForeground上显示通知?

为什么PlayerNotificationManager不在安卓11(R)的startForeground上显示通知?
EN

Stack Overflow用户
提问于 2021-01-22 16:58:24
回答 2查看 1.7K关注 0票数 1

我在Exoplayer上使用PlayerNotificationManager,在startForeground()上最多可以看到Android10的通知托盘,但是当我升级到Android11时,我的一部手机上的媒体播放器通知托盘停止显示。

请帮帮我!!

现在我在Google Pixel上调试了一下:

在谷歌像素安卓11上工作,但不在三星G973F上工作。为什么这对三星不起作用?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-02-02 13:42:51

在这里,我提出了一个关于git ExoPlayer的问题,这是一个设备特定的问题,所以,这是该问题的链接,

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

票数 2
EN

Stack Overflow用户

发布于 2021-01-25 14:38:00

给你,我还没有测试过这个,但我认为它会起作用,

代码语言:javascript
复制
// 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,请查看此链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65842077

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档