从sdcard路径获取视频缩略图但在gridview上加载速度非常慢

时间:2015-06-05 06:58:15

标签: android android-layout android-adapter

我正在加载视频sdcard路径的缩略图。但缩略图加载太晚了。我正在使用Custom gallery.Below是我的代码。如何让缩略图加载更快。请回答。

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    View view = convertView;
    if (view == null)
    {
        view = inflater.inflate(R.layout.custom_album_item_photo, parent, false);
        holder = new ViewHolder();
        holder.imageView = (ImageView) view.findViewById(R.id.imgLoader);
        holder.t1 = (TextView) view.findViewById(R.id.alb_name);

        view.setTag(holder);
    } 
    else 
    {
        holder = (ViewHolder) view.getTag();
    }
    holder.t1.setText(ALBUMS_LIST.get(position).getName());
    File f = new File(ALBUMS_LIST.get(position).getCover());
    Bitmap bitmap =ThumbnailUtils.createVideoThumbnail(ALBUMS_LIST.get(position).getCover(),MediaStore.Video.Thumbnails.MICRO_KIND);

    holder.imageView.setImageBitmap(bitmap);


    return view;

}
static class ViewHolder {
    ImageView imageView;
    TextView t1;
}

`

1 个答案:

答案 0 :(得分:-1)

我使用下面的代码解决了mySelf,并替换为createvideoThumbnail代码:

        ContentResolver crThumb = mContext.getContentResolver();
    BitmapFactory.Options opt=new BitmapFactory.Options();
    opt.inSampleSize = 1;
    int id=(int) data.get(position).getId();
    Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, opt);

    holder.imageView.setImageBitmap(curThumb);