Android: Get thumbnails of video files through the Thumbnailutils class

Source: Internet
Author: User

In the video player often see, there are a lot of video thumbnails, this article is about the Thumbnailutils class to get the thumbnail image of the video file;

Run as follows:

The code is as follows:

Mainactivity.java:

 PackageCom.vrinux.thumbnailutilsdemo;Importandroid.app.Activity;ImportAndroid.graphics.Bitmap;ImportAndroid.media.ThumbnailUtils;ImportAndroid.os.Bundle;ImportAndroid.os.Environment;ImportAndroid.provider.MediaStore;ImportAndroid.widget.ImageView; Public  class mainactivity extends Activity {    //Define a ImageView object imgobj;    PrivateImageView imgobj;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main);//Get object imgobj;Imgobj = (ImageView) Findviewbyid (R.id.imgid);//Define a video file path;String FilePath =NULL;//The name of the video file;String filename ="VIDEO.3GP";//Determine if the sdcard is mounted; Because the Android version of the Mount path is not the same, it is recommended to use a method of judgment;        if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {//Get the path to the SDcard rootString Sdpath = Environment.getexternalstoragedirectory (). GetPath ();//SDcard The path of the video file by assembling the root path and file name;FilePath = Sdpath +"/"+ filename;//Call the method defined below to get the video of the specified size;            //The final parameter I am not very clear what is meant, just so use, its source code is not open source;Bitmap Bitmap = Getvidiobitmap (FilePath, -, -, MediaStore.Images.Thumbnails.MICRO_KIND);//The bitmap to be obtained is displayed with Imgobj;Imgobj.setimagebitmap (bitmap); }    } PublicBitmapGetvidiobitmap(String FilePath,intWidthintHeightintKind) {//define a bitmap to resemble bitmap;Bitmap Bitmap =NULL;The captured images of the//thumbnailutils are kept in the original proportions, but I find that sometimes some of the ImageView controls are not shown;        //Adjust the Thumbnailutils method of the Createvideothumbnail to obtain a screenshot of the video;Bitmap = Thumbnailutils.createvideothumbnail (FilePath, kind);//Adjust the Thumbnailutils method extractthumbnail the original image (that is, the image captured above) to the specified size;        //Last parameters of the definition I'm not quite sure, because it's closed source;Bitmap = Thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input);//Put back bitmap object;        returnBitmap }}

Activity_main.xml:

<linearlayout xmlns:android="Http://schemas.android.com/apk/res/android"  Android:layout_width="Fill_parent"android:layout_height="Fill_parent"  Android:orientation="vertical" >                <ImageViewandroid:id="@+id/imgid"android:layout_width= "Wrap_content" android:layout_height="wrap_content" />                        </linearlayout>

Android: Get thumbnails of video files through the Thumbnailutils class

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.