I am writing a voice assistant and would like to be able to launch search results in Spotify. To understand how to connect to Spotify and other apps, I am playing with the Google's Media Controller Test app, which is described as doing the following:
Create a simple MediaController that connects to a MediaBrowserService in order to test inter-app media controls.
This app works with the Universal Android Music Player sample, or any other app that implements the media APIs.
When I run the app, it identifies Spotify as providing a MediaBrowserService
, but I get an error when I try connecting to Spotify through the app:
Here's is the connection code:
mBrowser = new MediaBrowserCompat(this, mMediaAppDetails.componentName,
new MediaBrowserCompat.ConnectionCallback() {
@Override
public void onConnected() {
setupMediaController();
mBrowseMediaItemsAdapter.setRoot(mBrowser.getRoot());
}
@Override
public void onConnectionSuspended() {
//TODO(rasekh): shut down browser.
mBrowseMediaItemsAdapter.setRoot(null);
}
@Override
public void onConnectionFailed() {
showToastAndFinish(getString(
R.string.connection_failed_msg, mMediaAppDetails.appName));
}
}, null);
mBrowser.connect();
Specifically, shortly after calling mBrowser.connect()
, the callback's onConnectionFailed()
method is called.
Does this imply that Spotify refuses MediaBrowserService
requests from non-whitelisted apps (as described here) and that there's no way for an individual app writer to connect to Spotify's MediaBrowserService
, or is there some other way to connect? FWIW, Google Play Music also rejects connections through the app.
I have also tried getting Spotify to search and play by launching an intent, but that was unsuccessful.