最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

android代码修改mp3文件封面,android

IT圈 admin 30浏览 0评论

android代码修改mp3文件封面,android

我正在尝试从音频文件Uri中获取专辑封面,这是我的代码:

// uri is the audio file uri

public static Bitmap getSongCoverArt(Context context, Uri uri){

Bitmap songCoverArt = null;

String[] projections = {MediaStore.Audio.Media.ALBUM_ID};

Cursor cursor = null;

try {

cursor = context.getContentResolver().query(uri, projections, null, null, null);

int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);

cursor.moveToFirst();

Uri songCover = Uri.parse("content://media/external/audio/albumart");

Uri uriSongCover = ContentUris.withAppendedId(songCover, column_index);

Log.d(TAG, uriSongCover.toString());

ContentResolver res = context.getContentResolver();

try {

InputStream in = res.openInputStream(uriSongCover);

songCoverArt = BitmapFactory.decodeStream(in);

}catch (FileNotFoundException e){

Log.e(TAG, e.getMessage());

}

}finally {

if(cursor != null){

cursor.close();

}

}

return songCoverArt;

}

此函数始终返回“对于content:// media / external / audio / albumart / 0没有条目”

android代码修改mp3文件封面,android

我正在尝试从音频文件Uri中获取专辑封面,这是我的代码:

// uri is the audio file uri

public static Bitmap getSongCoverArt(Context context, Uri uri){

Bitmap songCoverArt = null;

String[] projections = {MediaStore.Audio.Media.ALBUM_ID};

Cursor cursor = null;

try {

cursor = context.getContentResolver().query(uri, projections, null, null, null);

int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);

cursor.moveToFirst();

Uri songCover = Uri.parse("content://media/external/audio/albumart");

Uri uriSongCover = ContentUris.withAppendedId(songCover, column_index);

Log.d(TAG, uriSongCover.toString());

ContentResolver res = context.getContentResolver();

try {

InputStream in = res.openInputStream(uriSongCover);

songCoverArt = BitmapFactory.decodeStream(in);

}catch (FileNotFoundException e){

Log.e(TAG, e.getMessage());

}

}finally {

if(cursor != null){

cursor.close();

}

}

return songCoverArt;

}

此函数始终返回“对于content:// media / external / audio / albumart / 0没有条目”

发布评论

评论列表 (0)

  1. 暂无评论