可以自己上网找专辑封面的,保存到电脑里。在itunes里点这张专辑的“显示简介”,然后在“专辑封面”里把复制进去就可以了。注意的大小,如果横竖比例不行的话,itunes会把它截掉一部分
该为使用如下代码解析得到:
参考源码中,音乐目录:
packages/apps/Music/src/com/android/music/MusicUtilsjava中函数: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 = contextgetContentResolver();
Uri uri = ContentUriswithAppendedId(sArtworkUri, album_id);
if (uri != null) {
InputStream in = null;
try {
in = resopenInputStream(uri);
return BitmapFactorydecodeStream(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 (bmgetConfig() == null) {
bm = bmcopy(BitmapConfigRGB_565, false);
if (bm == null && allowdefault) {
return getDefaultArtwork(context);
}
}
} else if (allowdefault) {
bm = getDefaultArtwork(context);
}
return bm;
} finally {
try {
if (in != null) {
inclose();
}
} 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 = Uriparse("content://media/external/audio/media/" + songid + "/albumart");
ParcelFileDescriptor pfd = contextgetContentResolver()openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfdgetFileDescriptor();
bm = BitmapFactorydecodeFileDescriptor(fd);
}
} else {
Uri uri = ContentUriswithAppendedId(sArtworkUri, albumid);
ParcelFileDescriptor pfd = contextgetContentResolver()openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfdgetFileDescriptor();
bm = BitmapFactorydecodeFileDescriptor(fd);
}
}
} catch (FileNotFoundException ex) {
}
if (bm != null) {
mCachedBit = bm;
}
return bm;
}
private static Bitmap getDefaultArtwork(Context context) {
BitmapFactoryOptions opts = new BitmapFactoryOptions();
optsinPreferredConfig = BitmapConfigRGB_565;
return BitmapFactorydecodeStream(
contextgetResources()openRawResource(Rdrawableplay_img_default), null, opts);
}
private static final Uri sArtworkUri = Uriparse("content://media/external/audio/albumart");
private static final BitmapFactoryOptions sBitmapOptions = new BitmapFactoryOptions();
private static Bitmap mCachedBit = null;
获取cursor:
myCur = getContentResolver()query(
MediaStoreAudioMediaEXTERNAL_CONTENT_URI,
new String[] { MediaStoreAudioMediaTITLE,
MediaStoreAudioMediaDURATION,
MediaStoreAudioMediaARTIST,
MediaStoreAudioMedia_ID,
MediaStoreAudioMediaALBUM,
MediaStoreAudioMediaDISPLAY_NAME,
MediaStoreAudioMediaDATA,
MediaStoreAudioMediaALBUM_ID}, null,null, null);
myCurmoveToPosition(position);
设置专辑封面:
long songid = myCurgetLong(3);
long albumid = myCurgetLong(7);
Bitmap bm = MusicUtilsgetArtwork(this, songid, albumid,true);
if(bm != null){
Logd(TAG,"bm is not null==========================");
playImgsetImageBitmap(bm);
}else{
Logd(TAG,"bm is null============================");
}
以上就是关于itunes里面的歌曲封面怎么获取全部的内容,包括:itunes里面的歌曲封面怎么获取、android 怎样获取歌曲的专辑封面、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)