about how Android intercepts thumbnails and what problems they encounter

Source: Internet
Author: User

A recent project needs to write to the recording video and then intercept the thumbnail display feature. In the previous wording is called the system's own camera function, but the effect is poor.

Later I intend to write a method of recording the video myself, successfully, and save it in the local path.

However, when extracting thumbnails, a series of problems are encountered.

A great God told me to read it from the database. But their level is somewhat low, has not studied the database read and write files.

Thus, one way to find out online is to mediametadataretriever this class.


Don't say much nonsense, put on the code.

public class Mainactivity extends Activity {private Button btn;private ImageView iv;static String TAG = "mainactivity"; String path; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); btn = (Button) Findviewbyid (R.id.button); iv = (ImageView) Findviewbyid ( R.ID.IV); Btn.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//TODO auto-generated method stub bitmap Bitmap;//file file = new file (Getapplicationcontext (). Getfilesdir (),//"/see.mp4"); try {path = Environment.getexternalstoragedirectory (). Getcanonicalfile () + "/see.mp4"; LOG.E (TAG, path);} catch (IOException E1) {//TODO auto-generated catch block E1.printstacktrace ();} Mediametadataretriever MMR = new Mediametadataretriever ();//System.out.println (Uri.fromfile (file). toString ()); Mmr.setdatasource (path); bitmap = Mmr.getframeattime (1 * +); Iv.setimagebitmap (bitmap); System.out.println (Mmr.extractmetadata (mediametadataretriever.metadata_key_date) + "");System.out.println (Mmr.extractmetadata (mediametadataretriever.metadata_key_mimetype) + ""); Mmr.release ();}});} 
Layout file is simple

<relativelayout      xmlns:android= "http://schemas.android.com/apk/res/android"      xmlns:tools= "http// Schemas.android.com/tools "      android:layout_width=" match_parent "      android:layout_height=" Match_parent "      >        <button          android:id= "@+id/button"          android:layout_width= "Wrap_content"          android: layout_height= "Wrap_content"          android:text= "get frame picture of video"           android:layout_centerinparent= "true"      />      <imageview        android:id= "@+id/iv"        android:layout_width= "fill_parent"        android:layout_ height= "Match_parent"        android:layout_below= "@id/button"        ></ImageView>  </ Relativelayout>  


One of the problems encountered earlier is that you cannot read files under this path. Instead, read it with a URI, and the problem is found.

I finally found out that there was something missing on the authority.

<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

about how Android intercepts thumbnails and what problems they encounter

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.