How to get screenshots and thumbnails of video files in Android _android

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.