1、使用Glide可以加载视频封面,是不是首帧就不知道了
Glide
.with(context)
.load(Uri.fromFile(new File(filePath)))
.into(mImage);
2、也可以通过MediaMetadataRetriever获取Bitmap,这个就占内存多一些
MediaMetadataRetriever media = new MediaMetadataRetriever();
media.setDataSource(videoPath);
Bitmap bitmap = media.getFrameAtTime();
3、也可以在媒体库查询中通过BitmapFactory.decodeFile('媒体库的content路径');生成bitmap
Cursor cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, MediaStore.Video.Media.ALBUM + "=?", new String[]{Constants.DIRECTORY_VIDEO}, MediaStore.Video.Media.DEFAULT_SORT_ORDER);
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID));
//视频缩略图路径
String albumPath = "";
Cursor thumbCursor = context.getApplicationContext().getContentResolver().query(
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
null, MediaStore.Video.Thumbnails.VIDEO_ID
+ "=" + id, null, null);
if (thumbCursor.moveToFirst()) {
albumPath = thumbCursor.getString(thumbCursor
.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Bitmap bitmap = BitmapFactory.decodeFile(albumPath);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null)
cursor.close();
}
4、同Glide一样,Fresco也可以加载
mImage.setImageURI(Uri.parse("file://" + filePath));
网友评论