2

So Google deprecated the whole RemoteControlClient, and replaced it with MediaSession. Then, to add backwards compatibility, the added MediaSessionCompat in the support library, so you don't need to use RemoteControlClient anymore.

However, they didn't add a replacement for receiving the metadata and play state for another player, nor being able to control it. Sure, you can make your own MediaSessionCompat if you are a media player, but what if you just want to remote control other media players?

My question is, what is the replacement for MediaSessionManager using the support library? Specifically, how to I get a list of all the current MediaSessionCompat sessions on the system (for instance MediaSessionManager.addOnActiveSessionsChangedListener() using the new API)?

Basically, how do I make this following code work on API < 21:

private MediaSessionManager mSessionManager;
private MediaController mController;

private MediaSessionManager.OnActiveSessionsChangedListener sessionListener = new MediaSessionManager.OnActiveSessionsChangedListener() {

    @Override
    public void onActiveSessionsChanged(List<MediaController> controllers) {
        mController = controllers.get(0);
        mController.registerCallback(controllerCallback);
    }
};


@Override
public void onCreate() {
    super.onCreate();

    mSessionManager = (MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);

    ComponentName componentName = new ComponentName(this, "com.example.MyNotificationListener");
    mSessionManager.addOnActiveSessionsChangedListener(sessionListener, componentName);

}
phreakhead
  • 14,721
  • 5
  • 39
  • 40

1 Answers1

0

It's not possible. There is no replacement for MediaSessionManager in the support libs so you are stuck with it.

https://stackoverflow.com/a/36626943/396106

Community
  • 1
  • 1
timothyjc
  • 2,188
  • 3
  • 29
  • 54
  • 1
    Please do not post links to [duplicate answers](//meta.stackexchange.com/a/211726/206345). Instead, consider other actions that could help future users find the answer they need, as described in the linked post. – Mogsdad Apr 14 '16 at 16:18