如何访问android中手机上存储的音乐名称,艺术家,专辑名称?
问题描述:
很像音乐应用程序做我想要访问的歌曲(而不是文件名),或艺术家或专辑的名称。例如,我想用手机上所有歌曲的名字填充一个listview。如何访问android中手机上存储的音乐名称,艺术家,专辑名称?
答
有两种方法可供选择,一个读meta标签从音乐文件本身和一个使用MediaStore
内容提供商。 MediaStore
本质上是一个公共数据库,您可以查询手机上的所有媒体相关信息。
使用MediaStore
非常简单,可以在文档here中找到。
这里是我的应用程序一个简单的例子:
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Artists.ARTIST };
tempCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
tempCursor.moveToFirst(); //reset the cursor
int col_index=-1;
int numSongs=tempCursor.getCount();
int currentNum=0;
do{
col_index = tempCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
artist = tempCursor.getString(col_index);
//do something with artist name here
//we can also move into different columns to fetch the other values
}
currentNum++;
}while(tempCursor.moveToNext());