How to get the video thumbnail path, and not the bitmap

寵の児 提交于 2019-12-03 17:21:25
Nii Laryea

First, you need to know the content uri of the file. If you have the file path, this shows you how to get the content uri.

public static String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA };
public static String[] mediaColumns = { MediaStore.Video.Media._ID };

public static String getThumbnailPathForLocalFile(Activity context,
        Uri fileUri) {

    long fileId = getFileId(context, fileUri);

    MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),
            fileId, MediaStore.Video.Thumbnails.MICRO_KIND, null);

    Cursor thumbCursor = null;
    try {

        thumbCursor = context.managedQuery(
                MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
                thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + " = "
                        + fileId, null, null);

        if (thumbCursor.moveToFirst()) {
            String thumbPath = thumbCursor.getString(thumbCursor
                    .getColumnIndex(MediaStore.Video.Thumbnails.DATA));

            return thumbPath;
        }

    } finally {
    }

    return null;
}

public static long getFileId(Activity context, Uri fileUri) {

    Cursor cursor = context.managedQuery(fileUri, mediaColumns, null, null,
            null);

    if (cursor.moveToFirst()) {
        int columnIndex = cursor
                .getColumnIndexOrThrow(MediaStore.Video.Media._ID);
        int id = cursor.getInt(columnIndex);

        return id;
    }

    return 0;
}

Reference: http://androidcodezs.blogspot.com/2013/10/android-thumbnail-from-video.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!