基本上我想在android.i中更改音频文件的专辑封面,通过以下方法获取所有音频文件:
private void loadAudio() {
ContentResolver contentResolver = myContext.getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor cursor = contentResolver.query(uri, null, selection, null, sortOrder);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
long thisId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
long albumId = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
final Uri ART_CONTENT_URI = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(ART_CONTENT_URI, albumId);
songList.add(new songModel(thisId, title,artist,albumArtUri,data,albumId));
}
}
cursor.close();
}
我无法使用Mp3agic,因为它只处理.mp3文件。 我想要的是从媒体商店删除相关音频的专辑封面的路径,并插入一个新的如下:
ContentResolver res = getContext().getContentResolver();
InputStream in = null;
try {
in = res.openInputStream(Uri.parse(path));
} catch (FileNotFoundException e) {
albumartexists = false;
}
if (albumartexists)
{
Toast.makeText(getContext(), "file exists", Toast.LENGTH_SHORT).show();
getContext().getContentResolver().delete(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"),id), null, null);
}
ContentValues values = new ContentValues();
values.put("album_id",id);
values.put("_data",Environment.getExternalStorageDirectory() + "/Thumbnail/"+targetFileName);
Uri newuri = res.insert(Uri.parse("content://media/external/audio/albumart"), values);
if(newuri==null)
{
Toast.makeText(getContext(), "nwure is null", Toast.LENGTH_SHORT).show();
getContext().getContentResolver().delete(ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"),id), null, null);
newuri = getContext().getContentResolver().insert(Uri.parse("content://media/external/audio/albumart"), values);
}
此代码适用于某些文件,而对于某些文件,当albumart随之更改时,会更改几首歌曲的albumart。 我不知道错误在哪里。 请帮帮我! 不知道代码或其他什么问题。
此代码已被提及here
编辑:我正在使用JaudioTagger它工作正常,但更改了一个音频专辑的艺术变化为所有请帮助