如何获取相册缩略图中的Andr​​oid? [英] How do I get Album Thumbnails in Android?

查看:146
本文介绍了如何获取相册缩略图中的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我用了这个专辑列表:

I have a list of albums which I got using this:

private List<Album> getAlbums() {
Cursor cur = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
  List<Album> albums = new ArrayList<Album>();

  if (cur.moveToFirst()) {
   do {
    int albumIdIndex = cur.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
    int albumIndex = cur.getColumnIndex(MediaStore.Audio.Media.ALBUM);
    int artistIndex = cur.getColumnIndex(MediaStore.Audio.Media.ARTIST);
    int albumId = cur.getInt(albumIdIndex);
    String name = cur.getString(albumIndex);
    String artist = cur.getString(artistIndex);
    LogUtil.i(TAG, "albumid= " + albumId + ", album= " + name + ", artist=" + artist);

    Album album = new Album(albumId, name, artist);
    if (!albums.contains(album)) {
     albums.add(album);
    }    
   } while (cur.moveToNext());

  }

  return albums;
 }

我用的这个专辑列表中的ListActivity,但我也想拿到专辑的缩略图。

I use this list of albums in a ListActivity, but I also want to get the thumbnails of the Albums.

我知道我可以使用下面的code,以获得实际的作品,但我需要的缩略图,因为我得到的内存,如果我使用完整的图像列表活动:

I know I can use the following code to get the actual artwork, but I need the thumbnails because I get Out Of Memory if I use the full images in a List Activity:

Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);

我看到这个帖子: <一href="http://stackoverflow.com/questions/2902232/android-media-thumbnails-serious-issues">http://stackoverflow.com/questions/2902232/android-media-thumbnails-serious-issues 但我没有imageId,只有ALBUMID,所以我不认为这会有所帮助。

I saw this post: http://stackoverflow.com/questions/2902232/android-media-thumbnails-serious-issues But I do not have the imageId, only the albumid, so I don't think it helps.

推荐答案

获取每个专辑封面,创建它使用Bitmap.createScaledBitmap()的新版本,使用,再循环()旧的位图,使记忆消失,移动到下一个图像。保持一个HashMap或东西,以确保你不会加载相同的专辑封面两次以上(多个曲目都会有相同的专辑封面ID,它缓存。

Get each album art, create a new version of it using Bitmap.createScaledBitmap(), use that, recycle() the old bitmap to make memory go away, move to next image. Keep a HashMap or something to make sure you don't load the same album art twice or more (More than one track will have the same Album art id, cache it.

应该很好地工作。 (我的作品)

Should work well. (Works for me)

这篇关于如何获取相册缩略图中的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆