Background
The company recently asked me to take charge of the app plus video recording and publishing functions, I simply completed the basic recording and video compression function, and later found that the release interface needs to upload video screenshots, online search for information, here to tidy up.
Code implementation
/**
* Get a screenshot of the video file * *
@param path to a video file
@return Bitmap returns the obtained Bitmap/public
static Bitmap Getvideothumb (String path) {
Mediametadataretriever media = new Mediametadataretriever ();
Media.setdatasource (path);
return Media.getframeattime ();
}
/**
* Get a video file thumbnail api>=8 (2.2)
* *
@param path to a video file
@param kind thumbnail resolution: Mini_kind, Micro_kind, Full_screen_kind
* @return Bitmap returns the obtained Bitmap
/public static Bitmap GETVIDEOTHUMB2 (String path, int Kind) {return
thumbnailutils.createvideothumbnail (path, kind);
}
public static Bitmap GETVIDEOTHUMB2 (String path) {return
getVideoThumb2 (path, MediaStore.Video.Thumbnails.FULL_ Screen_kind);
}
These are the ways to get screenshots and thumbnails of video files, and you may also need to save bitmap as a file:
/**
* Bitmap Save As File
* *
* @param bitmap input bitmap
* @param name output file ' s name
* @return String o Utput file ' s path
/public static String Bitmap2file (Bitmap Bitmap, String name) {
file F = new file (environm Ent.getexternalstoragedirectory () + name + ". jpg");
if (f.exists ()) F.delete ();
FileOutputStream fout = null;
try {
fout = new FileOutputStream (f);
Bitmap.compress (Bitmap.CompressFormat.JPEG, fout);
Fout.flush ();
Fout.close ();
} catch (IOException e) {return
null;
}
return F.getabsolutepath ();
}
The above content is small to introduce you to the Android how to obtain video files screenshots, thumbnails of the relevant knowledge, I hope to help you!