我的视频播放器效果很好,但每个视频格式的缩略图都是黑色的。我的代码是
public static Bitmap getVideoBitmap(String path, int widthWanted, int heightWanted) {
Bitmap thumbnail = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(path);
} catch (IllegalArgumentException e) {
retriever.release();
retriever = null;
return null;
}
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int timeUs = Integer.valueOf(duration);
for(int i = 1; i <= timeUs; i++) {
thumbnail = retriever.getFrameAtTime(i * 1000 * 1000, MediaMetadataRetriever.OPTION_NEXT_SYNC);
}
thumbnail = getWantedBitmap(thumbnail, widthWanted, heightWanted);
return thumbnail;
}