1

I am getting the list of video url from the sdcard and passing to the adapter. In adapter, creating the thumbnail bitmap from the url of video. It became very slow to load the gridview and scrolling also very slow. Is there any ways to make it faster and easy to take the thumbnail from sd card.

@Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {

            convertView = infalter.inflate(R.layout.gallery_item, null);
            holder = new ViewHolder();
            holder.imgQueue = (ImageView) convertView.findViewById(R.id.imgQueue);

            holder.imgQueueMultiSelected = (ImageView) convertView
                    .findViewById(R.id.imgQueueMultiSelected);

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.imgQueue.setTag(position);

        try {

            Bitmap bitmap=ThumbnailUtils.createVideoThumbnail(data.get(position).sdcardPaththumbvideo, MediaStore.Video.Thumbnails.MINI_KIND);

            if (bitmap==null) {
                holder.imgQueue.setImageResource(R.drawable.no_media);
            }
            else{
                holder.imgQueue.setImageBitmap(bitmap);
            }



        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

1 Answer 1

2

Move ThumbnailUtils.createVideoThumbnail() off of the main application thread. In this sample project, I used the SmartImageView library to load the thumbnails asynchronously, applying my custom VideoThumbnailImage as a ViewBinder on my SimpleCursorAdapter showing the results of finding all videos:

  private static class ThumbnailBinder implements
      SimpleCursorAdapter.ViewBinder {
    @Override
    public boolean setViewValue(View v, Cursor c, int column) {
      if (column == c.getColumnIndex(MediaStore.Video.Media._ID)) {
        VideoThumbnailImage thumb=
            new VideoThumbnailImage(
                                    c.getInt(column),
                                    MediaStore.Video.Thumbnails.MICRO_KIND);

        ((SmartImageView)v).setImage(thumb,
                                     R.drawable.ic_media_video_poster);

        return(true);
      }

      return(false);
    }
  }

  private static class VideoThumbnailImage implements SmartImage {
    private int videoId;
    private int thumbnailKind;

    VideoThumbnailImage(int videoId, int thumbnailKind) {
      this.videoId=videoId;
      this.thumbnailKind=thumbnailKind;
    }

    @Override
    public Bitmap getBitmap(Context ctxt) {
      return(MediaStore.Video.Thumbnails.getThumbnail(ctxt.getContentResolver(),
                                                      videoId,
                                                      thumbnailKind,
                                                      null));
    }
  }
2
  • Thanks CW, let me try this Jun 23, 2014 at 13:10
  • After struggled I can able to maintain the cache for video thumbnail. Thanks a lot CW and thanks for given SmartImageView. Its really awesome Jun 24, 2014 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.