I have the following code;
String[] projection = { MediaStore.Video.VideoColumns._ID, MediaStore.Video.VideoColumns.DATA };
//String selection = MediaStore.Video.VideoColumns.KIND + "=" + MediaStore.Video.VideoColumns.;
String sort = MediaStore.Video.VideoColumns._ID + " DESC";
Cursor myCursor = getActivity().managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, sort);
try
{
myCursor.moveToFirst();
Log.d("VIDEO_URI", intent.getDataString());
Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(
getActivity().getContentResolver(), myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns._ID)),
MediaStore.Video.Thumbnails.MICRO_KIND,
(BitmapFactory.Options) null );
ImageView iv = (ImageView) getActivity().findViewById(R.id.attached_media_image);
//Log.d("IMAGE", curThumb.toString());
iv.setImageBitmap(bitmap);
}
catch (Exception e) {
// TODO: handle exception
Log.e("ERROR", e.toString());
}
I get the following in my LogCat when this is ran;
03-13 12:05:14.740: D/VIDEO_URI(7269): content://media/external/video/media/474
But it doesn’t set the image of the iv to anything, and when I try to run the Log.d(“IMAGE”, curThumb.toString()); line, that is commented out in this example, it throws a null exception.
Any help would be much appreciated thank you.
The thumbnail generation is not guaranteed to succeed since the part that generates thumbnails cannot do so for some video codecs. The returned
Bitmapwill benullin that case.bitmap != null?curThumb, I can see no definition of that in your code.Edit: Your error is that you use the ID from the thumbnails table not the id of the video.
All you need to do is to get the Bitmap this way:
Api Doc says: “origId: Original image id associated with thumbnail of interest.”