Android:从播放列表中检索歌曲时出错

时间:2013-07-06 17:48:33

标签: android android-contentresolver

我在Android中从播放列表中检索歌曲时遇到问题。我目前正在尝试使用以下代码实现此目的(基于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);

其中id是我使用cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists._ID));检索的播放列表ID(我知道这是正确的)

但是这会导致以下错误:

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=?)

我有一种有趣的感觉,问题在于以下几点: String where = MediaStore.Audio.Playlists._ID + "=?";但我不知道如何纠正它。

1 个答案:

答案 0 :(得分:1)

您不需要where子句,因为您已经使用了播放列表的内容URI。我会试试这个:

Cursor mCursor = getActivity().getContentResolver().query(
            MediaStore.Audio.Playlists.Members.getContentUri("external", Long.parseLong(id)), 
            proj, null, null, null);