views:

303

answers:

2

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).

A: 

I guess see this: http://code.google.com/p/android/issues/detail?id=5746

Tee
But there are only more questions, no solutions.
Manuel
A: 

Please find the solution at my blog: http://sadeqbillah.wordpress.com/2010/09/20/showing-video-thumbnails-in-android-2-0/

Happy Coding :-)

Meer Sadeq Billah
Yeah, but that's not really helping, I'm afraid. What I want to do is to get the thumbnail of one specific video. So it goes all down to the part in your code where you do: || Bitmap thumb = MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), id, MediaStore.Video.Thumbnails.MICRO_KIND, null); || But that's exactly what I'm doing above. And I won't get a bitmap.
Manuel
Well, my code works fine in Samsung Galaxy S. The thumbnail is shown if I select a Video. I have tried with managedQuery() though. Can you please mail me the portion of your code? I can then try to see if it works in my device. Then we may find out a way through.
Meer Sadeq Billah