everyone! I have a project - MusicApp where I need to retrieve all songs from external storage of an android device. I wanna get the next: url, title, artist, icon. How to do it? Now, I have the next code:
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor cursor =
getContentResolver().query(uri, null, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
String art = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
int resID = getResources().getIdentifier(art, "drawable", getPackageName());
mAdapter.addSong(new SongOne(resID, url, name, artist));
} while (cursor.moveToNext());
}
cursor.close();
}
And the model
public class SongOne {
private int img;
private String url;
private String title;
private String artist;
public SongOne(int img, String url, String title, String artist) {
this.img = img;
this.url = url;
this.title = title;
this.artist = artist;
}
public int getImg() {
return img;
}
public String getUrl() {
return url;
}
public String getTitle() {
return title;
}
public String getArtist() {
return artist;
}
}
I got the url, title, artist but I've not gotten the icons. How to do it?