问题描述
我试图从Lollipop的RemoteController迁移到MediaController,但是我在获取MediaController实例时遇到了麻烦.在MediaController中说:
I am trying to move from RemoteController to MediaController for Lollipop but I'm having trouble getting a MediaController instance. In MediaController it says:
但是,当我查看MediaSessionManager时,除了addOnActiveSessionsChangedListener,getActiveSessions和removeOnActiveSessionsChangedListener之外,没有其他方法对我没有帮助.我尝试从MediaSession创建令牌,但是这无法使我的回调从其他媒体播放器获取任何信息.
However when I look at MediaSessionManager there are no methods other than addOnActiveSessionsChangedListener, getActiveSessions, and removeOnActiveSessionsChangedListener these help me none.I tried creating a token from a MediaSession but that didn't enable my callback to get anything from other media players.
推荐答案
MediaSessionManager.getActiveSessions()为您提供与当前正在播放的音乐播放器关联的MediaController
实例列表.然后,您可以使用 MediaController.registerCallback()来注册 MediaController.Callback 创建的实现,该实现与已弃用的 RemoteController.OnClientUpdateListener (或仅将媒体控件直接发送回MediaController
.
MediaSessionManager.getActiveSessions() gives you a list of MediaController
instances associated with the currently playing music player(s). You can then use MediaController.registerCallback() to register a MediaController.Callback implementation you've created, which has similar callbacks to the deprecated RemoteController.OnClientUpdateListener (or just send media controls directly back to the MediaController
.
当然,在大多数情况下,您希望将MediaController
的列表与系统保持同步:这就是 MediaSessionManager.addOnActiveSessionsChangedListener()适用于:它为您提供了更新列表每次使用的玩家名单更改时都会被调用的MediaController
中的.根据文档,如果您使用的是权限,则可以将null
传入ComponentName notificationListener
参数.
Of course, in most cases you want to keep your list of MediaController
s in sync with the system: that is what MediaSessionManager.addOnActiveSessionsChangedListener() is for: it gives you an updated list of MediaController
s with which to use and is called every time the list of players change. As per the documentation, if you are using the permission you can pass null
in for the ComponentName notificationListener
parameter.
这篇关于如何从MediaSessionManager创建MediaController实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!