-1

I have to write a program where all the videos store in my device to be shown with thumbnails. i am able to list them all but most of them are coming with black thumbnail while in gallery application those shows perfectly.

please help me! what i have tried is

MediaStore.Video.Thumbnails.getThumbnail(mContex.getContentResolver(), id, MediaStore.Video.Thumbnails.MICRO_KIND, null);

or

ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MICRO_KIND)
skygeek
  • 1,548
  • 11
  • 24
  • For `ThumbnailUtils.createVideoThumbnail()`, you should provide path to video file, _e.g._ `"/sdcard/Video/myfile.mp4"`, and not a **uri**. – Alex Cohn Sep 19 '12 at 14:01
  • @AlexCohn Cohn that is file only the variable name is uri:( eddited my question!! – skygeek Sep 19 '12 at 14:03

2 Answers2

2

Some video files (e.g. mp4s that can be downloaded from YouTube) have few black frames in the beginning, and this is what you will see with ThumbnailUtils.createVideoThumbnail().

You can use MediaMetadataRetriever class to extract frames from the file at some offset from time=0. To get the best results you, should use getFrameAtTime(t, OPTION_NEXT_SYNC) and iterate through time t to find a non-trivial thumbnail. You can try the steps of 500000 (half second).

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

Use This Code. Its Working For Me. From

    int id = **"The Video's ID"**
    ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
    ContentResolver crThumb = getContentResolver();
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize = 1;
    Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
    iv.setImageBitmap(curThumb);


If It is not working Use This  

Bitmap bmThumbnail;
        bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MICRO_KIND);
Community
  • 1
  • 1
Rishabh Agrawal
  • 861
  • 2
  • 15
  • 25
  • Bitmap bmThumbnail; bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList[position], Thumbnails.MICRO_KIND); – Rishabh Agrawal Sep 19 '12 at 13:45
  • this too. i wrote in my question what i have already tried actually some of the videos showing their thumbs but some are coming black. – skygeek Sep 19 '12 at 13:49