Reputation: 2793
I'm having trouble retrieving songs from playlists in Android. I am currently attempting to achieve this using the following code (based on an answer to this question given here):
String where = MediaStore.Audio.Playlists._ID
+ "=?";
String whereVal[] = {id};
String[] proj =
{
MediaStore.Audio.Playlists.Members.AUDIO_ID,
MediaStore.Audio.Playlists.Members.ARTIST,
MediaStore.Audio.Playlists.Members.TITLE,
MediaStore.Audio.Playlists.Members._ID
};
Cursor mCursor = getActivity().getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", Long.parseLong(id)),
proj, where, whereVal, null);
where id is the playlist ID that I retrieve using cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists._ID));
(and I know that this is correct)
However this is causing the following error:
07-06 19:35:02.496: E/AndroidRuntime(8818): android.database.sqlite.SQLiteException:
ambiguous column name: _id (code 1): , while compiling: SELECT audio_id, artist, title,
audio_playlists_map._id AS _id FROM audio_playlists_map, audio WHERE (audio._id =
audio_id AND playlist_id=?) AND (_id=?)
I have a funny feeling that the problem lies in the following:
String where = MediaStore.Audio.Playlists._ID + "=?";
but I have no clue how to rectify it.
Upvotes: 0
Views: 365
Reputation: 1308
You don't need the where clause since you already use the content URI of the playlist. I would try this:
Cursor mCursor = getActivity().getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", Long.parseLong(id)),
proj, null, null, null);
Upvotes: 2