这是我的代码,我从我的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;
}
知道我想要获得该特定歌曲的图像。