public void getMuicessd(){
Cursor query = contentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,null,null,null,null,null);
if(query!=null){
while (query.moveToNext()){
@SuppressLint("Range") String title = query.getString(query.getColumnIndex(MediaStore.Audio.Media.TITLE));
@SuppressLint("Range") String artist = query.getString(query.getColumnIndex(MediaStore.Audio.Media.ARTIST));
@SuppressLint("Range") String duration = query.getString(query.getColumnIndex(MediaStore.Audio.Media.DURATION));
@SuppressLint("Range") String data = query.getString(query.getColumnIndex(MediaStore.Audio.Media.DATA));
@SuppressLint("Range") String size = query.getString(query.getColumnIndex(MediaStore.Audio.Media.SIZE));
@SuppressLint("Range") String Album_id = query.getString(query.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
Uri parse = Uri.parse("content://media/external/audio/albums/" + Album_id);
Cursor query1 = contentResolver.query(parse, null, null, null, null);
while (query1.moveToNext()){
@SuppressLint("Range") String album_art = query1.getString(query1.getColumnIndex("album_art"));
JavaBean.DataDTO dataDTO = new JavaBean.DataDTO();
dataDTO.setTitle(title);
dataDTO.setArtist(artist);
dataDTO.setAlbum(album_art);
dataDTO.setDuration(duration);
dataDTO.setData(data);
dataDTO.setSize(Double.parseDouble(size));
list.add(dataDTO);
MusicUtils.getInstance().setList(list);
}
}
}
}
获取本地音乐
最新推荐文章于 2024-11-09 12:43:52 发布
该代码段通过ContentResolver查询MediaStore.Audio.Media.EXTERNAL_CONTENT_URI获取手机上的音乐信息,包括标题、艺术家、时长、数据路径、大小和专辑ID。然后进一步查询专辑ID对应的专辑艺术图,将这些信息封装到JavaBean.DataDTO对象中,并存入列表。最后,使用MusicUtils.getInstance().setList将列表保存。
摘要由CSDN通过智能技术生成