Skip to content Skip to sidebar Skip to footer

Retrieve A Thumbnail Of A Video

I'm trying to make an application for showing the best movie trailers. I'd like to show a grid view with the thumbnails of each video and then clicking them open a new Activity for

Solution 1:

If you are using API 2.0 or newer this will work.

To get video id:

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

Cursor cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
                                    proj, MediaStore.Video.Media.DISPLAY_NAME+"=?",newString[] {"name.mp4"}, null);
cursor.moveToFirst()
id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));

To get the thumbnail of the video:

ImageViewiv= (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolvercrThumb= getContentResolver();
BitmapFactory.Options options=newBitmapFactory.Options();
options.inSampleSize = 1;
BitmapcurThumb= MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);

EDIT:

If you are on android-8 (Froyo) or above, you can use ThumbnailUtils.createVideoThumbnail from video path:

Bitmapthumb= ThumbnailUtils.createVideoThumbnail(path,
    MediaStore.Images.Thumbnails.MINI_KIND);

Hope it helps!

Post a Comment for "Retrieve A Thumbnail Of A Video"