I am working on music app player.I got all song from sd card correctly. but I am stuck on sorting of audio song by album. my code is here
public void getSongList(){
//query external audio
ContentResolver musicResolver = getActivity().getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = new String[] { android.provider.MediaStore.Audio.Media._ID, android.provider.MediaStore.Audio.Media.ALBUM,
android.provider.MediaStore.Audio.Media.ARTIST };
String selection = null;
String[] selectionArgs = null;
String sortOrder = android.provider.MediaStore.Audio.Media.ALBUM + " ASC";
Cursor musicCursor = musicResolver.query(musicUri, projection, selection, selectionArgs, sortOrder);
//iterate over results if valid
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int pathColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.DATA);
int durationColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.DURATION);
//add songs to list
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisPath = musicCursor.getString(pathColumn);//getRealPathFromURI(pathColumn);
String thisDuration = musicCursor.getString(durationColumn);
long durationInLong = 0;
if(thisDuration!=null){
durationInLong = Long.parseLong(thisDuration);
}
String finalDuration = utils.milliSecondsToTimer(durationInLong);
songList.add(new Song(thisId, thisTitle, thisArtist,thisPath,finalDuration,firstsong));
}
while (musicCursor.moveToNext());
}
how to get song list by album or genres or artist.
Aucun commentaire:
Enregistrer un commentaire