我正在写一个Android音乐播放器,我在播放列表中找到下一首歌时遇到了问题。 我有一首歌的两个值, 播放列表ID(MediaStore.Audio.Playlists.Members.PLAYLIST_ID) 和播放列表歌曲ID MediaStore.Audio.Playlists.Members._ID
这是相关的代码,尝试在当前歌曲之后的所有歌曲上获得光标:
Uri qUri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0 AND " + MediaStore.Audio.Playlists.Members._ID + " > " + songId +
" AND "+ MediaStore.Audio.Playlists.Members.PLAYLIST_ID + " = " + playlistId;
String[] projection = { MediaStore.Audio.Playlists.Members._ID };
Cursor cursor;
/* Execute query. */
try{
cursor = mContentResolver.query(qUri, projection, selection, null, null);
} catch(SQLiteException s)
{
ReconApp.debugToast("SQLiteException in next track finder", ReconApp.ERROR_TOAST);
s.printStackTrace();
return -1;
}
它捕获以下异常
10-14 14:24:08.207: ERROR/DatabaseUtils(1479): android.database.sqlite.SQLiteException: ambiguous column name: _id: , while compiling: SELECT audio_playlists_map._id AS _id FROM audio_playlists_map, audio WHERE (audio._id = audio_id AND playlist_id = 1) AND (is_music != 0 AND _id > 29 AND playlist_id = 1)
由于某种原因它会搜索两个表:audio_playlists_map,audio,这似乎是问题的根源。
是否可以找到具有这些值的下一首歌?它会使我的程序变得复杂,必须以不同的方式处理播放列表歌曲并存储其他一些值,我甚至不知道它会是什么,MediaStore.Audio.Playlists.Members.AUDIO_ID可能吗?
答案 0 :(得分:2)
//你只能寻找和追加。试试这个
String[] projection = new String[] {MediaStore.Audio.Playlists.Members.PLAYLIST_ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Playlists.Members.AUDIO_ID};
Uri contentUri = MediaStore.Audio.Playlists.Members.getContentUri("external", _playlistid);
contentUri = contentUri.buildUpon().appendQueryParameter("limit", "1").build();
Cursor playlistCursor = getContentResolver().query(contentUri,
projection,
null, null, MediaStore.Audio.Playlists.Members.PLAY_ORDER);