roger roger - 3 years ago 234
Android Question

ThumbnailUtils.createVideoThumbnail return null bitmap for mp4 file

When I get bitmap for mp4 file with:

ThumbnailUtils.createVideoThumbnail(mediaFile.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
return null

Answer Source

Try this, May be you media file path was wrong. Use below method you will get exact path. Its working for me

 Bitmap thumb = ThumbnailUtils.createVideoThumbnail(getPath(outputFileUri),
                        MediaStore.Images.Thumbnails.MINI_KIND);

photo_Img.setImageBitmap(thumb);

/**
 * Get file path
 */
public static String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = context.managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download