I have an Android Auto app. I would like to take advantage of pagination for browsing within the app. It seems that you can set EXTRA_PAGE and EXTRA_PAGE_SIZE by getting a reference to the MediaBrowserCompat and passing those constants in .subscribe(). However, I can't figure out how to get a reference to the MediaBrowserCompat that Android Auto Audio uses in order to call .subscribe().
This seems way too complicated for something that should be simple, am I just overthinking things?
Please note: Usually in Android when you see compat suffix at the end, it is new (enhanced) version of one without compat.
MediaActivity is not special Activity, it's a kind of Activity, which is designed to play the musics. And, as you asked MediaBrowserCompat and MediaBrowserServiceCompat, I changed my default architecture (Architecture 2 presented below), to Architecture 1 (Architecture 1 presented below which is new introduced in version 22), just to give the exact answer that you asked.
Two Architectures are:
Architecture1)
1)
MediaActivity <--uses----> MediaBrowserCompat <---uses--> MediaServiceBrowserCompat <----> MediaSessionCompat <---> MediaSession <--pass session token --> MediaControllerCompat <-- it also passes token to create --> MediaController /* latest API introduced in 22 */
2)
3)
Uses MediaSessionCompat to control music playing.
4)
Once a session is created the owner of the session may pass its session token to other processes to allow them to create a MediaControllerCompat to interact with the session.
5)
A MediaController can be created if you have a MediaSessionCompat.Token from the session owner.
Now, You created MediaController
From here, both Architecture do the same thing.
Architecture2)
1)
MediaActivity <--uses----> MediaBrowser <---uses--> MediaServiceBrowser /* old one introduced in 21. This is default */
2)
3)
Uses MediaSession to control music playing
4)
Once a session is created the owner of the session may pass its session token to other processes to allow them to create a MediaController to interact with the session.
5)
A MediaController can be created through MediaSessionManager if you hold the "android.permission.MEDIA_CONTENT_CONTROL" permission or are an enabled notification listener or by getting a MediaSession.Token directly from the session owner.
Now, You created MediaController
From here, both Architecture do the same thing.
Note: By default, when you create Android Auto project, it still uses Architecture 2, But, I'm using Architecture 1 because you asked to do via MediaBrowserCompat. So, you can be a little confused here.
Since exact implementation is kind of long, so I'm providing exact link where you kind find the implementation via MediaBrowserCompat way (Architecture 1) https://github.com/googlesamples/android-MediaBrowserService
I am posting basic code here based on the Architecture -- because it's a new one introduced in version 22 -- just to enough to show how you can get MediaBrowserCompat reference.
mConnectionCallbacks is the main thing that connectes MediaServiceBrowserCompat with MediaBrowserCompat. MediaBrowserCompat controls the media provided by the MediaServiceBrowserCompat. Activity, which is suitablely designed to control the media is called MediaActivity. MediaActivity uses MediaBrowserCompat to control media (eg, volume, play change etc). MediaBrowserCompat setups mConnectionCallbacks which further has onConnected() etc methods where you can put your own logic there.
And, now, you can create MediaBrowserServiceCompat /* note MediaBrowserServiceCompat is service */ as below.
For more research, you can read this link, which exactly explains the logic I presented above. https://developer.android.com/guide/topics/media-apps/audio-app/building-a-mediabrowser-client.html#connect-ui-and-mediacontroller