正在开发一款音乐播放器,刚好完毕。但是为了让界面更好看点,所以想把歌手的专辑海报图片作为背景,api中好像这方面的函数,但是我看到某些播放器,有这个功能,手机自带的播放器就有,不知道从何下手 !!谢谢!!!指定下~~~~~~~~~~

解决方案 »

  1.   

    你说的是专辑封面,MP3和wma格式的音乐文件是可以有专辑封面的,android提供了获取专辑封面的方法,我是这样用的,希望对你 有帮助:
    private static final BitmapFactory.Options sBitmapOptionsCache = new BitmapFactory.Options();
    sBitmapOptionsCache.inPreferredConfig = Bitmap.Config.RGB_565;
    sBitmapOptionsCache.inDither = false;
    static HashMap<Integer, SoftReference<Bitmap>> sAlbumArtCache = new HashMap<Integer, SoftReference<Bitmap>>(
    100, 0.85f); // Get album art for specified album. This method will not try to
    // fall back to getting artwork directly from the file, nor will
    // it attempt to repair the database.
    public static Bitmap getArtworkQuick(Context context, int album_id, int w,
    int h) {
    // NOTE: There is in fact a 1 pixel border on the right side in the
    // ImageView used to display this drawable. Take it into account now, so
    // we don't
    // have to scale later.
    if (sAlbumArtCache.containsKey(album_id)) {
    SoftReference<Bitmap> albumArt = sAlbumArtCache.get(album_id);
    Bitmap bitmap = albumArt.get();
    if (bitmap != null) {
    return bitmap;
    } else {
    sAlbumArtCache.remove(album_id);
    Log.d("Music", "getArtworkQuick(): no Bitmap for " + album_id);
    }
    }// else {
    // Log.d("Music", "getArtworkQuick(): no cache for " + album_id);
    // } w -= 1;
    ContentResolver res = context.getContentResolver();
    Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
    if (uri != null) {
    ParcelFileDescriptor fd = null;
    try {
    fd = res.openFileDescriptor(uri, "r");
    int sampleSize = 1; // Compute the closest power-of-two scale factor
    // and pass that to sBitmapOptionsCache.inSampleSize, which will
    // result in faster decoding and better quality
    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) {
    // finally rescale to exactly the size we need
    // if (sBitmapOptionsCache.outWidth != w
    // || sBitmapOptionsCache.outHeight != h) {
    // Bitmap temp = b;
    // b = Bitmap.createScaledBitmap(b, w, h, false);
    // temp.recycle();
    // } sAlbumArtCache.put(album_id, new SoftReference<Bitmap>(b));
    } return b;
    } catch (FileNotFoundException e) { } finally {
    try {
    if (fd != null)
    fd.close();
    } catch (IOException e) {
    }
    }
    }
    return null;
    }android的opencore这一块是不支持wma文件的,如果你想取到wma文件的专辑封面,可以参考http://download.csdn.net/detail/dazme886/3638064