dimanche 30 novembre 2014

Android: How to list mp3 albums


Vote count:

0




I want to try develop simple android music player. I have this method below to list album title, but it gives duplicate albums list.



public void getAlbumList() {
//query external audio
Activity a=getActivity();
ContentResolver musicResolver = a.getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
//String[] projection = null;

//String sortOrder = null;

String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";

String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension("mp3");

String[] selectionArgsMp3 = new String[]{ mimeType };
Cursor musicCursor = musicResolver.query(musicUri, null, selectionMimeType, selectionArgsMp3, null);
//iterate over results if valid

if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int atitleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ALBUM);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ALBUM_ID);
//int bitmap = musicCursor.getColumnIndex
// (android.provider.MediaStore.Audio.Albums.ALBUM_ART);
//add songs to list
while (musicCursor.moveToNext()){
long thisId = musicCursor.getLong(idColumn);
String thisaTitle = musicCursor.getString(atitleColumn);

albumList.add(new Album(thisId, thisaTitle));
}

}
}


I have tried this


but it doesn't work.



asked 35 secs ago







Android: How to list mp3 albums

Aucun commentaire:

Enregistrer un commentaire