3
我在我的模擬器中有9首歌曲,列表視圖中出現的項目數量爲9個。好極了,太棒了!唯一的問題是這9首歌是同一首歌。我一直在繞過這個網站,並沒有找到解決我的問題。下面的代碼是我用來查詢媒體商店的。如何從mediastore獲取歌曲?
package javierpech.codeit.xaverius;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
public class queryMediaStore {
private ArrayList<HashMap<String, String>> songs= new ArrayList<HashMap<String, String>>();
private String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
private Uri externalUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
private Cursor cursor;
private String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
private String[] projection = {
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
// MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA,
// MediaStore.Audio.Media.DURATION
};
//PUBLIC CONSTRUCTOR
public queryMediaStore(){
}
public ArrayList<HashMap<String, String>> updatePlaylist(Context c){
HashMap<String, String> tempSong = new HashMap<String, String>();
cursor = c.getContentResolver().query(
externalUri,
projection,
selection,
null,
sortOrder);
if (cursor!= null)
{
if(cursor.moveToFirst()){
while(cursor.moveToNext()){
tempSong.put("songArtist", cursor.getString(0));
tempSong.put("songTitle", cursor.getString(1));
tempSong.put("songPath", cursor.getString(2));
songs.add(tempSong);
}
}
}cursor.close();
return songs;
}
}