Search code examples
androidremote-controlandroid-mediasessionmediaplayback

Android: Things I am not clear about MediaSessionManager and RemoteController


I tried to browse the web to see what MediaSessionManager does and used for and reading RemoteController (the deprecated since API 21) so I can see whether these api can solve my problem.

At the moment, I am using AudioManger and send the key event to stop / pause / play of the current audio from other music player... It does do the job. Now I am wondering whether it can be done for media player e.g YouTube app which playing a video and my app from other device can act like a remote to control the video playback on the second device.

I ended up reading MediaSessionManager. It give all active media session with the currently playing music players. I am not sure is it the right solution to solve my scenario above. Since I am working on Android 4.4.2, I think MediaSessionManager probably not the right way so I found something called RemoteController but unsure how it really work and whether it help solving my problem

There is too many thing here, I don't know where to start.


Solution

  • Both RemoteController and the MediaController instances retrievable through MediaSessionManager are local only - they allow one app on a device to control the playback of another app.

    If you support only API 21+ devices, MediaSessionManager is much more easier to work with and reliable than RemoteController, but if you also want to support KitKat devices then there is no other option than RemoteController.

    Of course, once users have enabled the NotificationListenerService on the device you want to control, you can build whatever device to device communication protocol you want to send the media status to the other controlling device and send commands back to the device you want to control. That infrastructure would be something unique to your app however - there's no built in classes that do that.