How can I create a MediaController instance from MediaSessionManager?

前端 未结 1 929
谎友^
谎友^ 2021-01-15 15:42

I am trying to move from RemoteController to MediaController for Lollipop but I\'m having trouble getting a MediaController instance. In MediaController it says:

相关标签:
1条回答
  • 2021-01-15 16:13

    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.

    Of course, in most cases you want to keep your list of MediaControllers in sync with the system: that is what MediaSessionManager.addOnActiveSessionsChangedListener() is for: it gives you an updated list of MediaControllers 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.

    0 讨论(0)
提交回复
热议问题