Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying Google Play Music database in Android

I am trying to query for the playlists created by "Google Play Music" app but haven't been able to do so. I created a playlist using locally stored content. I used the following code to query:

Cursor c = managedQuery(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                                       new String[] {MediaStore.Audio.Playlists._ID,
                                                     MediaStore.Audio.Playlists.NAME
                                                    }, null, null, null);

This works fine for Winamp but not for Google Play Music. In fact, Winamp doesn't display the playlists created with Google Play Music. However, Google Play Music displays the playlists created with Winamp. My guess is that Google Play Music is using its own database to store the playlists where as other players use Content Provider with uri MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI to store their playlists. Is there a way to get playlists created with Google Play Music?

like image 259
Aman Bakshi Avatar asked Mar 12 '12 14:03

Aman Bakshi


2 Answers

I know this thread is old, but I have been grappling with this problem too.

Google Play Music exposes its playlists at this non-standard Content URI

// list all playlists with their ID and Name
Cursor cursor = getContentResolver().query(
    "content://com.google.android.music.MusicContent/playlists", 
    new String[] {"_id", "playlist_name" }, 
    null, null, null);

The Google Play Music content provider uses the following column names

  • isAllLocal
  • playlist_owner_name
  • hasLocal
  • hasRemote
  • hasAny
  • KeepOnId
  • playlist_art_url
  • playlist_share_token
  • _id
  • _count
  • playlist_owner_profile_photo_url
  • keeponSongCount
  • playlist_description
  • playlist_type
  • playlist_id
  • keeponDownloadedSongCount
  • playlist_name

I would have never figured this out without this really helpful app Content Provider Helper

like image 135
jdgilday Avatar answered Sep 23 '22 23:09

jdgilday


Try this.

String[] proj = {MediaStore.Audio.AudioColumns.TITLE,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media._ID};
Uri gMusicUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
Cursor cursor = getApplicationContext().getContentResolver()
            .query(gMusicUri,
                    proj, null, null, null);
like image 44
user1411426 Avatar answered Sep 24 '22 23:09

user1411426