0

I'm new to android development, and I'm listing all videos from storage(my mobile) and want to create thumbnail display in custom ListView. My problem is when creating the thumbnail it's taking time, how to solve this ? please help me out.

below code is to create the thumbnail

@Override
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_list);

    ListView videolist=(ListView)findViewById(R.id.video_list);
    ArrayList<String> videoName = new ArrayList<>();
    final ArrayList<String> videoPath = new ArrayList<>();
    ArrayList<Bitmap> videoThumbnail = new ArrayList<>();

    String selection =MediaStore.Video.Media._ID;
    String[] columns = { MediaStore.Video.Media.DATA,MediaStore.Video.Media.DISPLAY_NAME};

    Cursor cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            columns, selection, null, null);

    while (cursor.moveToNext()){

        Bitmap bmThumbnail;
        bmThumbnail = ThumbnailUtils.createVideoThumbnail(String.valueOf(Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)))),
                MediaStore.Video.Thumbnails.MICRO_KIND);
        videoName.add(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)));
        videoPath.add(String.valueOf(Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)))));
        videoThumbnail.add(bmThumbnail);
    }
    cursor.close();
    Toast.makeText(getApplicationContext(), ""+videoThumbnail.size(), Toast.LENGTH_LONG).show();

    VideoAdapter videoAdapter = new VideoAdapter(this, videoName,videoThumbnail);
    videolist.setAdapter(videoAdapter);
gauravsheohar
  • 396
  • 5
  • 12
chethankumar
  • 409
  • 2
  • 5
  • 15

5 Answers5

1

Add following library to your Gradle :

compile 'com.github.bumptech.glide:glide:3.6.1'

Then in your code do something like this :

Glide.with(context)
                .load(URI_OF_YOUR_VIDEO)
                .placeholder(R.drawable.ic_video_place_holder)
                .into(imageView);

It's very smooth and also cache your image.

Amir
  • 16,067
  • 10
  • 80
  • 119
0

A common solution for this is to generate the thumbnails one time only, then save them to a file.

Another choice maybe multithreading, but may cause OutOfMemoryError if device RAM is low.

0

Use

Bitmap bitmapThumb = MediaStore.Video.Thumbnails.getThumbnail(mActivity.getContentResolver(),
     Long.parseLong(video_id), 
     Images.Thumbnails.MINI_KIND, 
     options);

FYI

Thumbnails.MICRO_KIND for 96 x 96

Thumbnails.MINI_KIND for 512 x 384 px

Community
  • 1
  • 1
Aks4125
  • 4,522
  • 4
  • 32
  • 48
0

You can create all your thumnails in background thread using AsyncTask intimating the user that some progress is going on. When all thumbnailing is done then you can do the rest of the work.

Hope this helps.

Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
0

Yes you can do this with Glide, but not with Picasso.

Glide.with(context)
     .load(im.getUri())
     .into(holder.imageView);

(I am using a RecyclerView)

Elletlar
  • 3,136
  • 7
  • 32
  • 38