太 检索我使用的专辑ID:
String SONG_ALBUMID = MediaStore.Audio.Albums.ALBUM_ID;
但是MediaStore.Audio.Albums.ALBUM_ID和MediaStore.Audio.Media.ALBUM_ID有什么区别
谢谢
MediaStore.Audio.Albums.ALBUM_ID 是专辑表中的专辑 ID,并且 MediaStore.Audio.Media.ALBUM_ID将是文件表中album_id的"外键"。在一般的关系数据库设计中,当访问文件表时,我们所需要的只是访问相册表并检索所有相关相册信息(如album_title(的abum_id。android数据库中的表格文件包含很多细节 例如
_id INTEGER
_data TEXT
_size INTEGER
format INTEGER
parent INTEGER
date_added INTEGER
date_modified INTEGER
mime_type TEXT
title TEXT
description TEXT
_display_name TEXT
picasa_id TEXT
orientation INTEGER
latitude DOUBLE
longitude DOUBLE
datetaken INTEGER
mini_thumb_magic INTEGER
bucket_id TEXT
bucket_display_name TEXT
isprivate INTEGER
title_key TEXT
artist_id INTEGER
album_id INTEGER
composer TEXT
track INTEGER
year INTEGER
is_ringtone INTEGER
is_music INTEGER
is_alarm INTEGER
is_notification INTEGER
is_podcast INTEGER
album_artist TEXT
duration INTEGER
bookmark INTEGER
artist TEXT
album TEXT
resolution TEXT
tags TEXT
category TEXT
language TEXT
mini_thumb_data TEXT
name TEXT
media_type INTEGER
old_id INTEGER
storage_id INTEGER
is_drm INTEGER
width INTEGER
height INTEGER
这里有 2 种方法: (在解析程序查询中包含请求的列(
public String getalbum_id(Cursor pcursor) {
int album_col = pcursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
String album_id = pcursor.getString(album_col);
if (album_id.length() > 0) {
return album_id;
} else {
return "";
}
}
public String getAlbumIdfromPath(Context context, String datapath) {
ContentResolver cr = context.getContentResolver();
final String _id = MediaStore.Audio.Media._ID;
final String path = MediaStore.Audio.Media.DATA;
final String album_id = MediaStore.Audio.Media.ALBUM_ID;
final String[] columns = {_id, album_id};
final String[] trackpath = {"%" + datapath + "%"};
String where = path + " LIKE ?";
String stralbum_id = null;
Cursor crs = cr.query(uri, columns, where, trackpath, null);
if (crs != null && crs.moveToFirst()) {
stralbum_id = crs.getString(crs.getColumnIndexOrThrow(album_id));
crs.close();
}
return stralbum_id;
}
现在显示,我之前已经发布过,但我使用 Gilde 库。它完成了所有艰苦的工作。
// loading album cover using Glide library
String artist_id = (c.getString(c
.getColumnIndex(MediaStore.Audio.Artists._ID)));
Cursor albs = albums.getArtistsAlbumcursor(mContext, artist_id);
String stralbumId=null;
if(albs!=null && albs.moveToFirst()){
stralbumId= albs.getString(albs.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
}
Uri ImageUrl = plist.getAlbumUri(mContext, stralbumId);
if (ImageUrl != null) {
Glide.with(mContext)
.asBitmap()
.load(ImageUrl)
.into(image);
}
}
其中getAlbumuri是:
public Uri getAlbumUri(Context mContext,String album_id){
if(mContext!=null) {
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri imageUri = Uri.withAppendedPath(sArtworkUri, String.valueOf(album_id));
return imageUri;
}
return null;
}
在模块构建中包含以下内容.gradle
implementation 'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
private final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;