I'm the developer of a voice command application and a user has reported that your play from search feature isn't responding.
I've narrowed the issue down to an unstructured request, such as one detailed here:
developer.android.com/guide/components/intents-common.html#PlaySearchThis intent will work correctly:
private void structuredMusicIntent() {
final String title = "Billie Jean";
final String artist = "Michael Jackson";
final String album = "Thriller";
final String query = "Billie Jean Michael Jackson";
final Intent intent = new Intent();
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "vnd.android.cursor.item/audio");
intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, title);
intent.putExtra(SearchManager.QUERY, query);
try {
startActivity(intent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
} catch (final Exception e) {
e.printStackTrace();
}
}
However, if I am unable to resolve the specifics of the track/album/artist etc prior to sending the intent and fall back to an unstructured request, the logcat for GoneMad shows various errors, depending on the combination I try:
private void unstructuredMusicIntent() {
final String query = "Billie Jean Michael Jackson";
final Intent intent = new Intent();
intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(SearchManager.QUERY, query);
// intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "vnd.android.cursor.item/audio");
// intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, "vnd.android.cursor.item/*");
try {
startActivity(intent);
} catch (final ActivityNotFoundException e) {
e.printStackTrace();
} catch (final Exception e) {
e.printStackTrace();
}
}
Music Streaming apps, such as Spotify, Google Play Music etc and local apps such as PowerAmp can handle these unstructured requests - I wondered if this is an error somewhere in your code, or it is as yet unsupported?
If it's the latter, I wonder if handling it gracefully, by placing the query in the search bar would be an interim option? At least then the user would be aware 'something' happened and it would also cover the event of requesting media that doesn't exist on the device.
Any questions, happy to help.
Cheers
Ben