如何在Android中获取一首歌的专辑形象?

时间:2015-12-01 09:39:58

标签: android

Hy朋友。 我想获得歌曲的专辑形象。但我不知道如何得到它。 请帮助我。

这是我的代码,我从我的SD卡中检索所有歌曲的标题和歌曲的持续时间。

public List<SongDetails> getSongList(Context context)
{
    ContentResolver musicResolver = context.getContentResolver();
    Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    Cursor musicCursor = musicResolver.query(musicUri , null , null , null , null);
    songDetailsList = new ArrayList<>();

    if(musicCursor != null && musicCursor.moveToFirst())
    {
        do
        {
            SongDetails songDetails = new SongDetails();
            songDetails.setSongTitle(musicCursor.getString(musicCursor.getColumnIndex(MediaStore.Audio.Media.TITLE)));

            String songDuration = musicCursor.getString(musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION));

            if(String.valueOf(songDuration) != null){
                try{
                    Long time = Long.valueOf(songDuration);
                    long seconds = time/1000;
                    long minutes = seconds/60;
                    seconds = seconds % 60;

                    if(seconds<10){
                        String csongs_duration = String.valueOf(minutes) + ":0" + String.valueOf(seconds);
                        songDetails.setSongDuration(csongs_duration);
                    }else{
                        String ccsongs_duration = String.valueOf(minutes) + ":" + String.valueOf(seconds);
                        songDetails.setSongDuration(ccsongs_duration);
                    }
                }catch(NumberFormatException e){
                }
            }else{
                String nothing = "0";
                songDetails.setSongDuration(nothing);
            }
            songDetailsList.add(songDetails);
        }while(musicCursor.moveToNext());
    }

    return songDetailsList;
}

知道我想要获得该特定歌曲的图像。

0 个答案:

没有答案