Android Get video Voice file length of time

Source: Internet
Author: User

Mode one: Use Contentresolver

The contentresolver of the system provides us with the method of querying the Media Library, and the information of some media files, such as name, file path, length of play, etc. are kept in the media library.

Uri Contenturi =Media.external_content_uri; string[] Columns= {mediastore.audio.media._id,//Song IDMediaStore.Audio.Media.DURATION,//Total playback duration of the song}; Contentresolver Mresolver=Context.getcontentresolver (); String selection= MediaStore.Audio.Media.DATA + "=?"; String selectionargs[]={path}; Cursor Cursor= Mresolver.query (Contenturi,NULL, Selection, Selectionargs,NULL);if(Cursor! =NULL&&Cursor.movetofirst ()) {    intDuration =Cursor.getint (Cursor.getcolumnindex (media.duration)); Cursor.close ();}

Mode two: Use Mediametadataretriever

MediaMetadataRetrieverclass provides a unified interface for getting frames and metadata (meta data) from a media file.

 

New// before getting, set file path (should only be local path)String duration =          // free if (! textutils.isempty (Duration)) {    long dur = long.parselong (duration);}

In addition, the Mediametadataretriever class provides a unified interface for getting frames and metadata (meta data) from a media file. If you get the video at a certain point in time getFrameAtTime(long timeUs) , this method returns an Bitmap object.

Android Get video Voice file length of time

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.