Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble playing a song in Google Music player

Is there any way to start playing a song in Google music player app from my app? I am trying following code, but google music player only opens the search results & does not actually play the song.

    Intent intent = new Intent();
    intent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
    intent.putExtra(SearchManager.QUERY, "It's my life");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setPackage("com.google.android.music");
    activity.startActivity(intent);

The documentation for INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH says following - An intent to perform a search for music media and automatically play content from the result when possible.

So, according to documentation, it should be able to play the song. But, it only opens the search results and does not play it. Any ideas what I am missing here?

Thanks for any help you can offer.

like image 703
user1309043 Avatar asked Apr 02 '12 21:04

user1309043


1 Answers

Argh, finally figured it out by getting a heap dump of the Play Music process. You need to add

intent.putExtra("queryComplete", "It's my life");

and everything will work. The value has to be the same as the SearchManager.QUERY extra.

like image 94
Tavian Barnes Avatar answered Oct 11 '22 13:10

Tavian Barnes