获取一个视频网址的第一帧或者其他时间段的图片

private Bitmap createVideoThumbnail(String url, int width, int height) {//其中URL是视频地址 如http://123.56.82.95/data/upload/20160614/aabb.mp4
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
int kind = MediaStore.Video.Thumbnails.MINI_KIND;
try {
if (Build.VERSION.SDK_INT >= 14) {
retriever.setDataSource(url, new HashMap<String, String>());
} else {
retriever.setDataSource(url);
}
bitmap = retriever.getFrameAtTime(100);//100表示视频的一个类似时间点或者频数
} catch (IllegalArgumentException ex) {
// Assume this is a corrupt video file
} catch (RuntimeException ex) {
// Assume this is a corrupt video file.
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
// Ignore failures while cleaning up.
}
}
if (kind == MediaStore.Images.Thumbnails.FULL_SCREEN_KIND && bitmap != null) {
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
}
return bitmap;
}
我这个怎么就不行了啊!我这代码是我的精华啊!


posted @ 2016-06-23 15:50  神游风云  阅读(277)  评论(0编辑  收藏  举报