如何从MediaStore获取歌曲的一些数据?

时间:2019-03-31 12:08:39

标签: java android mediastore

大家!我有一个项目-MusicApp,需要从android设备的外部存储中检索所有歌曲。我想下一个:URL,标题,艺术家,图标。怎么做?现在,我有了下一个代码:

    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();
    }

和模型

 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;
    }

}

我有网址,标题,艺术家,但我没有图标。怎么做?

0 个答案:

没有答案