Much like the music app does i want to access the name of the song (not the name of the file) or the artist or album. For example, i want to populate a listview with the names of all the songs on the phone.
views:
35answers:
1
A:
There are two approaches to this, one to read the meta tags from the music files themselves and one to use the MediaStore
content provider. MediaStore
is essentially a public database that you may query for all media related information on the phone.
Using MediaStore
is very simple and can be found in the docs here.
Here is a simple example from one of my applications:
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Artists.ARTIST };
tempCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
tempCursor.moveToFirst(); //reset the cursor
int col_index=-1;
int numSongs=tempCursor.getCount();
int currentNum=0;
do{
col_index = tempCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
artist = tempCursor.getString(col_index);
//do something with artist name here
//we can also move into different columns to fetch the other values
}
currentNum++;
}while(tempCursor.moveToNext());
smith324
2010-08-07 10:13:01