I once used MediaStore for my music application, this is a very more efficient and correct way to retrieve data and then display it using a ListView. This will retrieve any music file stored in any folder on your SDCard.
//your database elect statement
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
//your projection statement
String[] projection = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ALBUM_ID
};
//query
cursor = this.managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
while(cursor.moveToNext()){
songs.add(cursor.getString(0));
songs.add(cursor.getString(1));
songs.add(cursor.getString(2));
songs.add(cursor.getString(3));
songs.add(cursor.getString(4));
songs.add(cursor.getString(5));
album_id.add((long) cursor.getFloat(6));
}
int a[]= new int[]{R.id.textView1 ,R.id.textView3};//, R.id.textview2};
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.items, cursor, new String[]{MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST/*, MediaStore.Audio.Media.DURATION*/} ,a);
setListAdapter(adapter);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…