【问题标题】:Loading album art efficiently Android高效加载专辑封面 Android
【发布时间】:2015-08-10 14:55:37
【问题描述】:

我无法有效地加载手机 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;
}

如果有人有任何想法,我很乐意提供帮助!非常感谢。

【问题讨论】:

    标签: android albumart


    【解决方案1】:

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

    【讨论】:

    • 非常感谢!我会检查一下,看看我能做些什么。
    猜你喜欢
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    相关资源
    最近更新 更多