Translate

Thursday, October 26, 2017

Describe MediaMetadataRetriever and how to find Media file duration android



MediaMetadataRetriever: This class is used to extract metadata from media file. It comes from “android.media.MediaMetadataRetriever” package. It has many of available metadata types. A developer can use this class as per need. Here is the below some metadata types that we can extract from a media file in android.
  • METADATA_KEY_ALBUM : This key of metadata is used to extract the information about the Album associated with media file.
  • METADATA_KEY_ALBUMARTIST : This key of metadata is used to extract the information about the Artist or Performer associated with media file.
  • METADATA_KEY_ARTIST : This key of metadata is used to extract the information about the Artist associated with media file.
  • METADATA_KEY_AUTHOR : This key of metadata is used to extract the information about the author associated with media file.
  • METADATA_KEY_COMPOSER : This key of metadata is used to extract the information about the Composer associated with media file.
  • METADATA_KEY_BITRATE : This key of metadata is used to extract the information about the Bitrate associated with media file.
  • METADATA_KEY_GENRE: This key of metadata is used to extract the information about the Genre associated with media file.
Methods available in MediaMetadataRetriever class:
  1. void setDataSource(String path) : This method is used to set the media file source path in string format.
  2. string extractMetadata(int keyCode) : This method is used to extract metadata as per keys selected that are mentioned above.
  3. byte[] getEmbeddedPicture() : This method is used to extract album art associated with media file.

 
Code to get Media Duration : 
 
private long getMediaDuration(){
    android.media.MediaMetadataRetriever metaRetriever = new android.media.MediaMetadataRetriever();
    metaRetriever.setDataSource(mRecordedFileName);
    return Long.parseLong(metaRetriever.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION));
}

No comments:

Post a Comment

Could not identify launch activity: Default activity not found : Error while Launching activity

Problem : I got this Error , When I tried to create an application without any Activity . Basically like to develop an Android Headless appl...