有效加载相册封面Android



我一直无法有效加载位于手机SD卡上的所有专辑封面。我可以得到所有的信息,但由于位图解码过程,可能需要15-20秒的时间。如果可能的话,我也不想失去这个订单。下面是我的代码:

    public String[] getAudioList() {
    final Cursor mCursor = getContentResolver().query(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Albums.ARTIST, MediaStore.Audio.Media.ALBUM}, null, null,
            "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");
    int count = mCursor.getCount();
    songs = new String[count];
    copyArtist = new String[count];
    albums = new String[count];
    mAudioPath = new String[count];
    artists = new String[count];
    int i = 0;
    if (mCursor.moveToFirst()) {
        do {
            songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
            albums[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
            artists[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
            mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
            copyArtist[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
            final Long albumId = mCursor.getLong(mCursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
            int duration = mCursor.getInt(mCursor
                    .getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
            try {
                Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
                Uri uri = ContentUris.withAppendedId(sArtworkUri, albumId);
                uriArr.add(uri);
                ParcelFileDescriptor pfd = this.getContentResolver()
                        .openFileDescriptor(uri, "r");
                FileDescriptor fd = pfd.getFileDescriptor();
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 4;
                Bitmap bm = BitmapFactory.decodeFileDescriptor(fd, null, options);
                bitmapArrFull.add(bm);
            } catch (Exception e) {
                e.printStackTrace();
            }
            i++;
        } while (mCursor.moveToNext());
    }
    mCursor.close();
    return songs;
}

如果有人有任何想法,我希望得到一些帮助!非常感谢。

查看开发者的网站,那里有有用的信息:
http://developer.android.com/training/displaying-bitmaps/index.html

相关内容

  • 没有找到相关文章

最新更新