android - 如何显示视频路径中的视频缩略图?
问题描述
我想在 ImageView 中显示来自存储视频路径的视频缩略图。是否有一个函数可以获取视频路径并返回缩略图的位图?我通过以下代码获取视频路径:
public ArrayList<String> getAllMedia() {
HashSet<String> videoItemHashSet = new HashSet<>();
String[] projection = {MediaStore.Video.VideoColumns.DATA, MediaStore.Video.Media.DISPLAY_NAME};
Cursor cursor = getContext().getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
try {
cursor.moveToFirst();
do {
videoItemHashSet.add((cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA))));
} while(cursor.moveToNext());
cursor.close();
} catch(Exception e) {
e.printStackTrace();
}
ArrayList<String> downloadedList = new ArrayList<>(videoItemHashSet);
return downloadedList;
}
解决方案
这是创建缩略图的默认方式。
迷你类
Bitmap thumb;
//MINI_KIND, size: 512 x 384 thumbnail
thumb = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
img_tumbnail.setImageBitmap(thumb);
微类
Bitmap thumb;
//MICRO_KIND, size: 96 x 96 thumbnail
thumb= ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);
img_tumbnail.setImageBitmap(thumb);
此外,您可以将 Glide 用于 Url 以及 Device 的 Video path。
Glide.with(context).with(this)
.asBitmap()
.load(videoFilePath) // or URI/path
.into(imgView); //imageview to set thumbnail to
.override(50,50)
此外,您可以使用Glide调整缩略图的大小。
推荐阅读
- ios - 如何从 Azure DevOps 下载 iOS 应用存档?
- apache-spark - 执行者决策的火花数
- python - 这是 python 字典的相同代码吗?
- ios - 如果应用程序已关闭或在后台,如何删除特定的远程通知
- django - Django Cycle 包含模板标签
- python - Google Colab 中 Python 的多处理问题
- android - 没有导航道具的 React Navigation 在发布模式下不起作用(Android 签名应用程序)
- jquery - 将 html 元素设置为 null 或空格会导致字段位移
- r - 冲积地块边距
- react-native - 如何在本机反应中制作路线?