Google Play Music API for Android-ThrowExceptions

Exception or error:

I’m working on a music application for Android.
I need two things:

  • Get album cover for artist, album name, track name, etc;
  • Open Google Play page for buying this album.

For the first thing I’m currently using iTunes API — but this is not patriotic for true Android developer. If Google Play Music has similar service, I would preferred to use it. Does it exist?

What about second? I can use this code to show all search results according with my query:

Intent intent = new Intent(Intent.ACTION_VIEW)
                             .setData(Uri.parse("market://search?q=<My Query>"));
startActivity(intent);

But I want to show album or track buying page exactly. Is is possible for Google Play?

How to solve:

There’s no official API for this from Google.

However, you can use an unofficial API that is being developed by Simon Weber. It’s called Unofficial-Google-Music-API, and it seems to be actively maintained(as of this writing).

The documentation and examples are pretty straightforward, and you can find details about the song’s metadata as listed here. Specifically, it gives an url to download cover art and the id for matching in the Play Store.

You may have to play around with the URL a bit for your search, though. For instance, you can use the returned albumMatchedId field to search by album like:

https://play.google.com/store/music/album?id=Bdkf6ywxmrhflvtasnayxlkgpcm

This should bring you to the album’s page, where you can purchase each song or the entire album.

I haven’t found a way to jump straight to a specific track, but I’m not sure if that’s possible anyway, judging from the layout of the app.

Leave a Reply

Your email address will not be published. Required fields are marked *