0

I tried to create a video thumbnail as described here. I also read the reference here.

In my app I first let the user choose a video with:

startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("video/*"), ACTIVITY_PICKVIDEO);

Then I determine the video ID with:

fileID = Integer.parseInt(contentUri.getLastPathSegment());

So, the video content://media/external/video/media/5 would have the ID 5.

Then I try to get the thumbnail bitmap with:

ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, fileID, MediaStore.Video.Thumbnails.MICRO_KIND, options);

There's no exception thrown but the bitmap has a width and height of -1. I'm not sure if the ID needed in getThubnail() is actually the ID that I determined above.

Does anyone know of a working example how to get the thumbnail bitmap if you have the content Uri?

Interestingly (maybe so) I get null when trying with MediaStore.Video.Thumbnails.MINI_KIND as thumbnail size and an IllegalArgumentException ("Unsupported kind: 2") when I try FULL_SCREEN_KIND.

I'm using a Motorola Milestone with Android 2.1.

EDIT: I also tried getting the ID with querying for the BaseColumns._ID but it turns out to be the same as in the Uri (in the given example the _ID is 5).

Community
  • 1
  • 1
Manuel
  • 8,135
  • 10
  • 32
  • 29

1 Answers1

10

for getting video id try this

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+"=?",new String[] {"name.mp4"}, null);
cursor.moveToFirst()
fileid = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));

for getting thumbnail :

ContentResolver crThumb = getContentResolver();
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb,fileid, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv2.setImageBitmap(curThumb);

here iv2 is imageview and name.mp4 will represent your file name

zobi8225
  • 2,258
  • 4
  • 20
  • 20
Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
  • @Manuel : use this function android.media.ThumbnailUtils.createVideoThumbnail( path,MediaStore.Video.Thumbnails.MINI_KIND ); here path is file path using this you can get thumbnail of particular one video – Jaiprakash Soni Mar 14 '11 at 10:31