Android得到視訊縮圖
阿新 • • 發佈:2019-01-03
public Bitmap getVideoThumbnail(String filePath) {
Bitmap bitmap = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
bitmap = retriever.getFrameAtTime();
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (RuntimeException e) {
e.printStackTrace();
}
finally {
try {
retriever.release();
}
catch (RuntimeException e) {
e.printStackTrace();
}
}
return bitmap;
}
其中函式getFrameAtTime()有其他過載函式,該函式會隨機選擇一幀抓取,如果想要指定具體時間的縮圖,可以用函式getFrameAtTime(long timeUs), getFrameAtTime(long timeUs, int option),具體如何使用可以查doc。