Search code examples
android-serviceandroid-mediaplayerandroid-support-library

MediaBrowserServiceCompat vs mediaSessionCompat?


I just developed a music app (local songs) When trying to build playback control on lock-screen and notification using mediaSessionCompat I found ianhanniballake's following link: https://medium.com/google-developers/mediabrowserservicecompat-and-the-modern-media-playback-app-7959a5196d90#.kfvx5jfyn

Though the blog was nicely explained, I didn't understand the difference between mediaSessionCompat and MediaBrowserServiceCompat.

Can someone explain why MediaBrowserServiceCompat is used? Is it necessary? Is mediaSessionCompat enough?

Thanks in advance


Solution

  • mediaBrowserCompat and mediaBrowserServiceCompat are used if you have many UI interfaces like Android Auto, Wear, mobile etc so the playback runs in all devices synchronously. mediaBrowserCompat is coded in the Activties where you need to control the service from. So it can be coded multiple times, like one for Main Activity of phone, one for Auto, one for Wear, etc. Whereas, mediaBrowserServiceCompat is coded only once inside the service class for the above mentioned mediaBrowserServiceCompats can connect to it and control the playback using mediaControllerCompat. The connection is set using setSession(token) and accessed by getSession(token).