废话不多说,直接给方法你(在系统媒体数据库里面取)
private void getMusic() {
listMapplaylist.clear();
Cursor cursor = this.getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.ALBUM_ID, }, "is_music=1 and _display_name like '%.mp3'", null, MediaStore.Audio.Media.TITLE);
if (cursor!= null){
if (cursor.getCount() > 0){
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
sId = cursor.getString(cursor.getColumnIndex("_id"));
sDisplayName = cursor.getString(cursor.getColumnIndex("title"));//名称
lDuration = cursor.getLong(cursor.getColumnIndex("duration"));//长度
sArtist = cursor.getString(cursor.getColumnIndex("artist"));//演唱者
sPath = cursor.getString(cursor.getColumnIndex("_data"));//歌曲路径
Map
map.put("id", sId);
map.put("musicName", sDisplayName);
map.put("duration", sDurationtime);
map.put("artist", sArtist);
map.put("path", sPath);
if (!(sPath.substring(sPath.lastIndexOf(".")).equalsIgnoreCase(".mp4"))
&& !(sPath.substring(sPath.lastIndexOf(".")).equalsIgnoreCase(".3gp"))) {
listMapplaylist.add(map);
}
cursor.moveToNext();
}
}
cursor.close();
}
}
可以获取数据库里的数据,安卓把所有的媒体信息在装如SD的时候加载进了数据库,
Cursor cursor=mResolver.query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null,
null,
null,
MediaStore.Audio.Media.DISPLAY_NAME);
这个是查询所有歌曲信息,并俺歌曲名排序
为了下android的文库真麻烦,还要回答问题。。。哥们给分吧