
文章插圖
【樂如網 樂如網功夫戰警】大家好,小豆豆來為大家解答以上的問題 。樂如網功夫戰警 , 樂如網這個很多人還不知道,現在讓我們一起來看看吧!
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網絡
- 網上訂的飛機票需要取票嗎? 網上訂的機票需要取票嗎
- 網線最長可以接多少米
- 南寧租房信息網 南寧市租房網個人房源
- 網銀盾丟了會有什么后果
- 如何戒掉網賭?
- 怎么把網頁設置成桌面圖標
