android get video thumbnail PATH, not Bitmap

前端 未结 2 1203
悲&欢浪女
悲&欢浪女 2021-01-12 08:39

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

MediaStore.Images.Thumbnails.queryMiniThumbnail
相关标签:
2条回答
  • 2021-01-12 08:50

    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;
        }
    
    0 讨论(0)
  • 2021-01-12 08:55

    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.

    0 讨论(0)
提交回复
热议问题