概述
展开全部
该图片为使用如下代码解e5a48de588b662616964757a686964616f31333339666135析得到:
参考源码中,音乐目录:
packages/apps/Music/src/com/android/music/MusicUtils.java中函数:getArtwork(context, song_id, album_id, true)
public static Bitmap getArtwork(Context context, long song_id, long album_id,
boolean allowdefault) {
if (album_id < 0) {
// This is something that is not in the database, so get the album art directly
// from the file.
if (song_id >= 0) {
Bitmap bm = getArtworkFromFile(context, song_id, -1);
if (bm != null) {
return bm;
}
}
if (allowdefault) {
return getDefaultArtwork(context);
}
return null;
}
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
if (uri != null) {
InputStream in = null;
try {
in = res.openInputStream(uri);
return BitmapFactory.decodeStream(in, null, sBitmapOptions);
} catch (FileNotFoundException ex) {
// The album art thumbnail does not actually exist. Maybe the user deleted it, or
// maybe it never existed to begin with.
Bitmap bm = getArtworkFromFile(context, song_id, album_id);
if (bm != null) {
if (bm.getConfig() == null) {
bm = bm.copy(Bitmap.Config.RGB_565, false);
if (bm == null && allowdefault) {
return getDefaultArtwork(context);
}
}
} else if (allowdefault) {
bm = getDefaultArtwork(context);
}
return bm;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
}
}
}
return null;
}
private static Bitmap getArtworkFromFile(Context context, long songid, long albumid) {
Bitmap bm = null;
byte [] art = null;
String path = null;
if (albumid < 0 && songid < 0) {
throw new IllegalArgumentException("Must specify an album or a song id");
}
try {
if (albumid < 0) {
Uri uri = Uri.parse("content://media/external/audio/media/" + songid + "/albumart");
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
} else {
Uri uri = ContentUris.withAppendedId(sArtworkUri, albumid);
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
}
} catch (FileNotFoundException ex) {
}
if (bm != null) {
mCachedBit = bm;
}
return bm;
}
private static Bitmap getDefaultArtwork(Context context) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.RGB_565;
return BitmapFactory.decodeStream(
context.getResources().openRawResource(R.drawable.play_img_default), null, opts);
}
private static final Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
private static final BitmapFactory.Options sBitmapOptions = new BitmapFactory.Options();
private static Bitmap mCachedBit = null;
获取cursor:
myCur = getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM_ID}, null,null, null);
myCur.moveToPosition(position);
设置专辑封面图片:
long songid = myCur.getLong(3);
long albumid = myCur.getLong(7);
Bitmap bm = MusicUtils.getArtwork(this, songid, albumid,true);
if(bm != null){
Log.d(TAG,"bm is not null==========================");
playImg.setImageBitmap(bm);
}else{
Log.d(TAG,"bm is null============================");
}
已赞过
已踩过<
你对这个回答的评价是?
评论
收起
最后
以上就是儒雅凉面为你收集整理的java 获取mp3 封面_android 怎样获取歌曲的专辑封面的全部内容,希望文章能够帮你解决java 获取mp3 封面_android 怎样获取歌曲的专辑封面所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复