7

When I get bitmap for mp4 file with: ThumbnailUtils.createVideoThumbnail(mediaFile.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND); return null

roger
  • 9,063
  • 20
  • 72
  • 119

4 Answers4

7

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);
}
Murali Ganesan
  • 2,925
  • 4
  • 20
  • 31
4

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

msj
  • 199
  • 1
  • 2
  • 13
2
File file = new File(filepath);
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
Vinil Chandran
  • 1,563
  • 1
  • 19
  • 33
1

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.

Rajesh Jadav
  • 12,801
  • 5
  • 53
  • 78
gaurav jain
  • 3,119
  • 3
  • 31
  • 48
  • what do you mean corrupt? My mp4 file can play in windows. – roger Dec 08 '14 at 06:19
  • If the video is not corrupt, then I see only one reason for this behavior. Check the file path and ensure it's correct. It returns null bitmap in case path is wrong. – gaurav jain Dec 08 '14 at 10:00
  • 1
    As you can see, I get the path with `mediaFile.getAbsolutePath()`, am I wrong? – roger Dec 08 '14 at 10:07
  • I really did use another video, and it worked. But the rest (I tried 5 different videos) didn't work. – bighugedev Aug 23 '23 at 23:41