private Bitmap getVideoThumb(String filePath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
bitmap = retriever.getFrameAtTime(1000L, MediaMetadataRetriever.OPTION_PREVIOUS_SYNC);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
} catch (RuntimeException ex) {
ex.printStackTrace();
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
ex.printStackTrace();
}
}
saveVideoThumb(bitmap);
return bitmap;
} private void saveVideoThumb(Bitmap thumb) {
thumbPath = filePath + System.currentTimeMillis() + Suffix.JPG;
File img = new File(thumbPath);
if (!img.exists()) {
try {
img.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileOutputStream fos;
try {
fos = new FileOutputStream(thumbPath);
thumb.compress(Bitmap.CompressFormat.JPEG, 100, fos);// 把数据写入文件
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}