7

Is it possible to get the video thumbnail PATH, not Bitmap object itself? I'm aware of method

MediaStore.Images.Thumbnails.queryMiniThumbnail

but since I use my own Bitmap caching mechanism I want to have the path to video thumbnail rather than the Bitmap object itself. This method returns Bitmap object, not path. Thanks

cubesoft
  • 3,448
  • 7
  • 49
  • 91

2 Answers2

6

First get the video file URL and then use below query.

Sample Code:

private static final String[] VIDEOTHUMBNAIL_TABLE = new String[] {
    Video.Media._ID, // 0
    Video.Media.DATA, // 1 from android.provider.MediaStore.Video
    };

Uri videoUri = MediaStore.Video.Thumbnails.getContentUri("external");

cursor c = cr.query(videoUri, VIDEOTHUMBNAIL_TABLE, where, 
           new String[] {filepath}, null);

if ((c != null) && c.moveToFirst()) {
  VideoThumbnailPath = c.getString(1);
}

VideoThumbnailPath, should have video thumbnail path. Hope it help's.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Munish Katoch
  • 517
  • 3
  • 6
  • What's the value of "where" parameter (3rd parameter on call of c.query)? – cubesoft Jan 23 '13 at 19:53
  • Where String: Video.Thumbnails.VIDEO_ID + " In ( select _id from video where _data =?)"; – Munish Katoch Jan 23 '13 at 20:04
  • I can't get this code to work since `c.moveToFirst()` is always false. What exactly is the 'where' string and filepath is the absolute path of the file, right? – Nii Laryea Jan 05 '15 at 15:48
  • 2
    This is so confusing and it is not working for me, anyone able to give a better solution? – Lion789 Aug 01 '15 at 06:11
  • 2
    It does not works, is cr : ContentResolver crThumb = App.getContext().getContentResolver(); , and Cursor is : Cursor c = crThumb.query(videoUri, VIDEO_THUMBNAIL_TABLE, " _data =?", new String[] { videoPath }, null); ???? – Hossein Kurd Aug 17 '15 at 05:13
  • please add full example, `cr, cursor...` – user25 Jun 05 '18 at 16:38
2

Get Video thumbnail path from video_id:

public static String getVideoThumbnail(Context context, int videoID) {
        try {
            String[] projection = {
                    MediaStore.Video.Thumbnails.DATA,
            };
            ContentResolver cr = context.getContentResolver();
            Cursor cursor = cr.query(
                    MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
                    projection, 
                    MediaStore.Video.Thumbnails.VIDEO_ID + "=?", 
                    new String[] { String.valueOf(videoID) }, 
                    null);
            cursor.moveToFirst();
            return cursor.getString(0);
        } catch (Exception e) {
        }
        return null;
    }
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
tuantv.dev
  • 108
  • 7