GoodDay and BadDay

jjunda.egloos.com

포토로그



MP3에서 albumart 뽑기 Android

안드로이드 어플에서 앨범정보는 참 쉽게 가져올수 있다..

album art라는걸로 검색해왔다면은 이미 앨범정보쯤은 가져왔을건데..

album art만 현재 못가져왔을것이다..

정보가 저장된곳이 다르댄다;;

아래대로 하면은 가져올수 있다.

String[] cols = new String[] {
            MediaStore.Audio.Albums._ID,
            MediaStore.Audio.Albums.ALBUM_ART
    };

Cursor cur = getContentResolver().query(
                 MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                 cols , null , null, null);
   cur.moveToPosition(pos);  
    int idNum = cur.getInt(0);
    Bitmap album_art = getBitmapImage( idNum,200, 200);
    mAlbumArt.setImageBitmap(album_art);


//안사나 안펍에 있는 함수 퍼옴
public Bitmap getBitmapImage(int id, int w, int h) {
        ContentResolver res = mContext.getContentResolver();
              Uri uri = ContentUris.withAppendedId(sArtworkUri, id);
              if (uri != null) {
                  ParcelFileDescriptor fd = null;
                  try {
                      fd = res.openFileDescriptor(uri, "r");
                      int sampleSize = 1;
                    
                      sBitmapOptionsCache.inJustDecodeBounds = true;
                      BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor(), null, sBitmapOptionsCache);
                      int nextWidth = sBitmapOptionsCache.outWidth >> 1;
                      int nextHeight = sBitmapOptionsCache.outHeight >> 1;
                      while (nextWidth>w && nextHeight>h) {
                          sampleSize <<= 1;
                          nextWidth >>= 1;
                          nextHeight >>= 1;
                      }
                      sBitmapOptionsCache.inSampleSize = sampleSize;
                      sBitmapOptionsCache.inJustDecodeBounds = false;
                      Bitmap b = BitmapFactory.decodeFileDescriptor(
                              fd.getFileDescriptor(), null, sBitmapOptionsCache);
                      if (b != null) {
                          if (sBitmapOptionsCache.outWidth != w || sBitmapOptionsCache.outHeight != h) {
                              Bitmap tmp = Bitmap.createScaledBitmap(b, w, h, true);
                              b.recycle();
                              b = tmp;
                          }
                      }
                      return b;
                  } catch (FileNotFoundException e) { return null;
                  } catch (Exception e) { return null;
                  } finally {
                      try {
                          if (fd != null)
                              fd.close();
                      } catch (IOException e) {
                      }
                  }
              }
              return null;
       }




메모장

곧 봄이다.. 나른나른..

W 위젯