文章插图
【乐如网 乐如网功夫战警】大家好,小豆豆来为大家解答以上的问题 。乐如网功夫战警 , 乐如网这个很多人还不知道,现在让我们一起来看看吧!
1、该图片为使用如下代码解析得到: 参考源码中 , 音乐目录:packages/apps/Music/src/com/android/music/中函数: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 = ntentResolver();Uri uri = ppendedId(sArtworkUri, album_id);if (uri != null) {InputStream in = null;try {in = nputStream(uri);return eStream(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 (nfig() == null) {bm = (_565, false);if (bm == null && allowdefault) {return getDefaultArtwork(context);}}} else if (allowdefault) {bm = getDefaultArtwork(context);}return bm;} finally {try {if (in != null) {();}} 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 = ("content://media/external/audio/media/" + songid + "/albumart");ParcelFileDescriptor pfd = ntentResolver().openFileDescriptor(uri, "r");if (pfd != null) {FileDescriptor fd = leDescriptor();bm = eFileDescriptor(fd);}} else {Uri uri = ppendedId(sArtworkUri, albumid);ParcelFileDescriptor pfd = ntentResolver().openFileDescriptor(uri, "r");if (pfd != null) {FileDescriptor fd = leDescriptor();bm = eFileDescriptor(fd);}}} catch (FileNotFoundException ex) {}if (bm != null) {mCachedBit = bm;}return bm;}private static Bitmap getDefaultArtwork(Context context) {ns opts = new ns();ferredConfig = _565;return eStream(sources().openRawResource(_img_default), null, opts);}private static final Uri sArtworkUri = ("content://media/external/audio/albumart");private static final ns sBitmapOptions = new ns();private static Bitmap mCachedBit = null;获取cursor:myCur = getContentResolver().query(NAL_CONTENT_URI,new String[] { ,ION,T,._ID,,AY_NAME,,_ID}, null,null, null);oPosition(position);设置专辑封面图片:long songid = ng(3);long albumid = ng(7);Bitmap bm = twork(this, songid, albumid,true);if(bm != null){Log.d(TAG,"bm is not null==========================");ageBitmap(bm);}else{Log.d(TAG,"bm is null============================");}这是抽取专辑图片的方法,扫描歌曲的时候自己把歌曲的id和专辑的id传进去就能获取private static final Uri sArtworkUri = ("content://media/external/audio/albumart");/*** 将MP3里图片读取出来* * @param context* @param songid* @param albumid* @return*/public static Bitmap getMusicBitemp(Context context, long songid,long albumid) {Bitmap bm = null;// 专辑id和歌曲id小于0说明没有专辑、歌曲 。
2、并抛出异常if (albumid < 0 && songid < 0) {throw new IllegalArgumentException("Must specify an album or a song id");}try {if (albumid < 0) {Uri uri = ("content://media/external/audio/media/"+ songid + "/albumart");ParcelFileDescriptor pfd = ntentResolver().openFileDescriptor(uri, "r");if (pfd != null) {FileDescriptor fd = leDescriptor();bm = eFileDescriptor(fd);}} else {Uri uri = ppendedId(sArtworkUri, albumid);ParcelFileDescriptor pfd = ntentResolver().openFileDescriptor(uri, "r");if (pfd != null) {FileDescriptor fd = leDescriptor();bm = eFileDescriptor(fd);} else {return null;}}} catch (FileNotFoundException ex) {}return bm;} 。
本文到此分享完毕,希望对大家有所帮助 。
- 书法网首页 书法网首页图片
- 拉手网团购电影票 团购买电影票
- 铸造英才网 铸造英才网最新招聘信息
- 苹果5手机是几g网络
- 网上订的飞机票需要取票吗? 网上订的机票需要取票吗
- 网线最长可以接多少米
- 南宁租房信息网 南宁市租房网个人房源
- 网银盾丢了会有什么后果
- 如何戒掉网赌?
- 怎么把网页设置成桌面图标