Reputation: 7932
I am trying to get a song from a playlist then play it in android.
All answers i can find relies on
MediaStore.MediaColumn.DATA
to find the file path and then feed it to the MediaPlayer.
But when i tried to do it, i kept getting "invalid column _data" exception.I can still query for other stuff about the song, like the "AUDIO_ID". So my question is, is it possible to play the song with only the "AUDIO_ID" known? How? Or is there something that i am missing for the "data", since every other people are able to use it.
This is my code for getting playlist.
private Cursor getPlaylistCursor() {
String[] proj = { MediaStore.Audio.Playlists._ID,MediaStore.Audio.Playlists.NAME };
Uri playlistUri = Uri.parse("content://com.google.android.music.MusicConten/playlists");
Cursor playlistCursor = getContentResolver().query(playlistUri, proj,null, null, null);
playlistCursor.moveToFirst();
return playlistCursor;
}
This is what i am working on for getting song, as i said, i cannot query the "data", if the "data" argument is added to the projection, i get an exception.
private void getSongListCursor(Long playlistID) {
String[] proj2 = { MediaStore.Audio.Playlists.Members.TITLE,
MediaStore.Audio.Playlists.Members.AUDIO_ID };
String playListRef = "content://com.google.android.music.MusicContent/playlists/"
+ playlistID + "/members";
Uri songUri = Uri.parse(playListRef);
Cursor songCursor = getContentResolver().query(songUri, proj2, null,
null, null);
}
SO now, i have the audio ID of a song, how do i play it?
Upvotes: 2
Views: 1553
Reputation: 1290
Everything is possible ;-)
My approach is to use the Google Play Music server to obtain the streaming URL corresponding to the selected song ID. Just let me know if you need help with authentication and jump-start with the unofficial API for Google Play Music.
Upvotes: 1