
android下使用cursor获取专辑,主要是在数据库里面先保存专辑的url地址,当使用cursor游标遍历数据库数据的时候,使用资源 *** 作类进行加载相应的url,如下代码:
Cursor cursor = contextgetContentResolver()query(MediaEXTERNAL_CONTENT_URI, columns, null, null, null);
Loge("cursor" , (cursor==null) + "");
while(cursormoveToNext()) {
// 查找封面
long albumId = cursorgetLong(5);
// 读取专辑
String album_uri = "content://media/external/audio/albumart"; // 专辑Uri对应的字符串
Uri albumUri = ContentUriswithAppendedId(Uriparse(album_uri), albumId);
// 取 ==> 得到一个输入流
Bitmap coverPhoto = null ;
try {
InputStream is = contextgetContentResolver()openInputStream(albumUri);
if(null != is) {
coverPhoto = BitmapFactorydecodeStream(is);
}
} catch (Exception e) {
eprintStackTrace();
}
dataadd(new Audio(cursorgetLong(0), cursorgetString(1) , cursorgetString(2) , cursorgetLong(3) , cursorgetString(4) , albumId , coverPhoto));
}
cursorclose();
ContentResolver mResolver = getContentResolver();
Cursor cursor = mResolverquery(MediaStoreAudioMediaEXTERNAL_CONTENT_URI, null, null, null, MediaStoreAudioMediaDEFAULT_SORT_ORDER);
int i = 0;
int cursorCount = cursorgetCount();
if (cursorCount >0 )
{
cursormoveToFirst();
while (i < cursorCount)
{
//歌曲文件的路径 :MediaStoreAudioMediaDATA
url = cursorgetString(cursorgetColumnIndexOrThrow(MediaStoreAudioMediaDATA));
if(urltoLowerCase()indexOf("指定的歌曲路径") > 0)
{
}
i++;
cursormoveToNext();
}
cursorclose();
}
以上就是关于android 下使用Cursor如何获得专辑图片全部的内容,包括:android 下使用Cursor如何获得专辑图片、Android 怎么读取指定目录下的音乐文件、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)