MediaBrowserServiceCompat vs mediaSessionCompat?

假如想象 提交于 2019-12-05 08:20:34

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/41648980/mediabrowserservicecompat-vs-mediasessioncompat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!