gpt4 book ai didi

android - 如何获取视频缩略图路径,而不是位图

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:45:33 25 4
gpt4 key购买 nike

这个问题实际上在这里被问到并且应该在这里得到回答:android get video thumbnail PATH, not Bitmap .

我已经试了好几次了,但还是不行。我总是得到一个 null 返回。请问有什么帮助吗?

编辑:我现在使用的示例代码:

public static String getVideoThumbnailPath(Context context,
String filePath) {
String thubmnailPath;
String where = Video.Thumbnails.VIDEO_ID
+ " In ( select _id from video where _data =?)";
final String[] VIDEO_THUMBNAIL_TABLE = new String[] { Video.Media._ID, // 0
Video.Media.DATA, // 1
};
Uri videoUri = MediaStore.Video.Thumbnails.getContentUri("external");

Cursor c = context.getContentResolver().query(videoUri,
VIDEO_THUMBNAIL_TABLE, where, new String[] { filePath }, null);

if ((c != null) && c.moveToFirst()) {
thubmnailPath = c.getString(1);
c.close();
Log.i(TAG, "thumb path: " + thubmnailPath);
return thubmnailPath;
} else {
c.close();
Log.i(TAG, "thumb path is null");
return null;
}
}

最佳答案

首先,你需要知道文件的内容uri。如果您有文件路径,this 将向您展示如何获取内容 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;
}

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

关于android - 如何获取视频缩略图路径,而不是位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27903264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com