Mediametadataretriever class obtains Media File Information

Source: Internet
Author: User

API Description: mediametadataretriever class provides a unified interface for retrieving frame and meta data from an input media file.

The mediametadataretriever class provides a unified interface for retrieving frames and metadata from an input media file.

API official link: http://developer.android.com/reference/android/media/MediaMetadataRetriever.html

1. The following uses a small example to demonstrate how to obtain part of media information from a music file:

Public class mainactivity extends activity {Private Static final string tag = "mainactivity"; @ targetapi (10) @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); mediametadataretriever MMR = new mediametadataretriever (); string STR = getexternalstoragedirectory () + "music/hetangyuese.mp3"; log. D (TAG, "str:" + Str); try {MMR. setdatasource (STR); String title = MMR. extractmetadata (mediametadataretriever. metadata_key_title); // API level 10. This function is available from gb2.3.3. D (TAG, "title:" + title); string album = MMR. extractmetadata (mediametadataretriever. metadata_key_album); log. D (TAG, "album:" + album); string mime = MMR. extractmetadata (mediametadataretriever. metadata_key_mimetype); log. D (TAG, "MIME:" + MIME); string artist = MMR. extractmetadata (mediametadataretriever. metadata_key_artist); log. D (TAG, "Artist:" + artist); string duration = MMR. extractmetadata (mediametadataretriever. metadata_key_duration); // The unit of playback duration is millisecond log. D (TAG, "Duration:" + duration); string bitrate = MMR. extractmetadata (mediametadataretriever. metadata_key_bitrate); // This function is available only from API Level 14, that is, log from ics4.0. D (TAG, "bitrate:" + bitrate); string date = MMR. extractmetadata (mediametadataretriever. metadata_key_date); log. D (TAG, "date:" + date);} catch (illegalargumentexception e) {// todo auto-generated catch blocke. printstacktrace ();} catch (illegalstateexception e) {// todo auto-generated catch blocke. printstacktrace () ;}@ override public Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_main, menu); Return true;} public static string getexternalstoragedirectory () {return environment. getexternalstoragedirectory () + "/";}}

The information output is as follows:

08-09 15:53:52. 119: D/mainactivity (5293): Str:/mnt/sdcard/music/hetangyuese.mp3
08-09 15:53:52. 810: D/mainactivity (5293): Title: hetang moonlight
08-09 15:53:52. 829: D/mainactivity (5293): album: I'm from grassland
08-09 15:53:52. 859: D/mainactivity (5293): MIME: Audio/MPEG
08-09 15:53:52. 868: D/mainactivity (5293): ARTIST: Phoenix Legend
08-09 15:53:52. 893: D/mainactivity (5293): Duration: 9172
08-09 15:53:52. 899: D/mainactivity (5293): bitrate: 128000
08-09 15:53:52. 909: D/mainactivity (5293): Date: NULL

2. If it is a video file, you can also use the getframeattime method to obtain bitmap at the specified time location, which can be used to capture images (including thumbnails.

By viewing the API, the keycode for sampling rate acquisition (samplerate) is not found and may be provided in later versions.

The above is a brief introduction to the mediametadataretriever class.

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.