Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 411
roger Avatar asked Dec 08 '14 04:12

roger


4 Answers

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);
}
like image 92
Murali Ganesan Avatar answered Oct 16 '22 14:10

Murali Ganesan


I think you must set requires permission in AndroidManifest <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

like image 34
msj Avatar answered Oct 16 '22 14:10

msj


File file = new File(filepath);
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
like image 2
Vinil Chandran Avatar answered Oct 16 '22 12:10

Vinil Chandran


From android docs:

public static Bitmap createVideoThumbnail (String filePath, int kind)

Create a video thumbnail for a video. May return null if the video is corrupt or the format is not supported.

Hence, I guess you need to re-check the mp4 file.

like image 1
gaurav jain Avatar answered Oct 16 '22 14:10

gaurav jain