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);
}