簡體   English   中英

顯示MediaStore.Audio.Albums.ALBUM_ART中的專輯封面

[英]Display album art from MediaStore.Audio.Albums.ALBUM_ART

我在帶有自定義CursorAdapter的LoaderManager中使用CursorLoader。 我已經可以顯示專輯和相關的藝術家,現在我想要顯示封面。

這是我的自定義CursorAdapter:

public class AlbumsAdapter extends CursorAdapter {


    private final LayoutInflater mInflater;

     public AlbumsAdapter(Context context, Cursor c) {
        super(context, c);
        mInflater=LayoutInflater.from(context);

    }
    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        TextView albumTitle =(TextView)view.findViewById(R.id.albumTextView);
        albumTitle.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)));

        TextView artistName=(TextView)view.findViewById(R.id.artistTextView);
        artistName.setText(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)));

        ImageView albumCover=(ImageView)view.findViewById(R.id.artistTextView);
        // Here what should I do ?

    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final View view=mInflater.inflate(R.layout.albums_row,parent,false); 
        return view;
    }   
}

我嘗試了以下未成功的方法:

    String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
    File imgFile = new  File(path);
    if(imgFile.exists()){

        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

        ImageView albumCover=(ImageView)view.findViewById(R.id.album_cover);
        albumCover.setImageBitmap(myBitmap);

    }

MediaStore.Audio.Albums.ALBUM_ART返回什么,以及如何使用它使ImageView失去封面? 謝謝。

我已經實現了在ImageViews使用以下命令加載專輯封面:

    String coverPath = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
    Drawable img = Drawable.createFromPath(coverPath);
    ImageView coverAlbum=(ImageView)view.findViewById(R.id.album_cover);
    coverAlbum.setImageDrawable(img);

問題是列表非常慢。 我想我應該縮小封面的分辨率,以消耗更少的內存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM