Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android get video thumbnail PATH, not Bitmap

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

like image 297
cubesoft Avatar asked Jan 23 '13 15:01

cubesoft


2 Answers

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.

like image 145
Munish Katoch Avatar answered Oct 20 '22 08:10

Munish Katoch


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;
    }
like image 34
tuantv.dev Avatar answered Oct 20 '22 09:10

tuantv.dev