Android
android.media
public class

android.media.MediaMetadataRetriever

java.lang.Object
android.media.MediaMetadataRetriever

MediaMetadataRetriever class provides a unified interface for retrieving frame and meta data from an input media file.

Summary

Constants

      Value  
int  METADATA_KEY_ALBUM    0x00000001 
int  METADATA_KEY_ARTIST    0x00000002 
int  METADATA_KEY_AUTHOR    0x00000003 
int  METADATA_KEY_CD_TRACK_NUMBER    0x00000000 
int  METADATA_KEY_COMPOSER    0x00000004 
int  METADATA_KEY_DATE    0x00000005 
int  METADATA_KEY_DURATION    0x00000009 
int  METADATA_KEY_GENRE    0x00000006 
int  METADATA_KEY_NUM_TRACKS    10  0x0000000a 
int  METADATA_KEY_TITLE    0x00000007 
int  METADATA_KEY_YEAR    0x00000008 
int  MODE_CAPTURE_FRAME_ONLY    0x00000002 
int  MODE_GET_METADATA_ONLY    0x00000001 

Public Constructors

            MediaMetadataRetriever()

Public Methods

          Bitmap  captureFrame()
Call this method after setDataSource().
          byte[]  extractAlbumArt()
Call this method after setDataSource().
          String  extractMetadata(int keyCode)
Call this method after setDataSource().
          void  release()
Call it when one is done with the object.
          void  setDataSource(String path)
Call this method before the rest.
          void  setMode(int mode)
Call this method before setDataSource() so that the mode becomes effective for subsequent operations.

Protected Methods

          void  finalize()
Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
Methods inherited from class java.lang.Object

Details

Constants

public static final int METADATA_KEY_ALBUM

Constant Value: 1 (0x00000001)

public static final int METADATA_KEY_ARTIST

Constant Value: 2 (0x00000002)

public static final int METADATA_KEY_AUTHOR

Constant Value: 3 (0x00000003)

public static final int METADATA_KEY_CD_TRACK_NUMBER

Constant Value: 0 (0x00000000)

public static final int METADATA_KEY_COMPOSER

Constant Value: 4 (0x00000004)

public static final int METADATA_KEY_DATE

Constant Value: 5 (0x00000005)

public static final int METADATA_KEY_DURATION

Constant Value: 9 (0x00000009)

public static final int METADATA_KEY_GENRE

Constant Value: 6 (0x00000006)

public static final int METADATA_KEY_NUM_TRACKS

Constant Value: 10 (0x0000000a)

public static final int METADATA_KEY_TITLE

Constant Value: 7 (0x00000007)

public static final int METADATA_KEY_YEAR

Constant Value: 8 (0x00000008)

public static final int MODE_CAPTURE_FRAME_ONLY

Constant Value: 2 (0x00000002)

public static final int MODE_GET_METADATA_ONLY

Constant Value: 1 (0x00000001)

Public Constructors

public MediaMetadataRetriever()

Public Methods

public Bitmap captureFrame()

Call this method after setDataSource(). This method finds a representative frame if successful and returns it as a bitmap. This is useful for generating a thumbnail for an input media source.

Returns

  • A Bitmap containing a representative video frame, which can be null, if such a frame cannot be retrieved.

public byte[] extractAlbumArt()

Call this method after setDataSource(). This method finds the optional graphic or album art associated (embedded or external url linked) the related data source.

Returns

  • null if no such graphic is found.

public String extractMetadata(int keyCode)

Call this method after setDataSource(). This method retrieves the meta data value associated with the keyCode. The keyCode currently supported is listed below as METADATA_XXX constants. With any other value, it returns a null pointer.

Parameters

keyCode One of the constants listed below at the end of the class.

Returns

  • The meta data value associate with the given keyCode on success; null on failure.

public void release()

Call it when one is done with the object. This method releases the memory allocated internally.

public void setDataSource(String path)

Call this method before the rest. This method may be time-consuming.

Parameters

path The path of the input media file.

Throws

IllegalArgumentException If the path is invalid.

public void setMode(int mode)

Call this method before setDataSource() so that the mode becomes effective for subsequent operations. This method can be called only once at the beginning if the intended mode of operation for a MediaMetadataRetriever object remains the same for its whole lifetime, and thus it is unnecessary to call this method each time setDataSource() is called. If this is not never called (which is allowed), by default the intended mode of operation is to both capture frame and retrieve meta data (i.e., MODE_GET_METADATA_ONLY | MODE_CAPTURE_FRAME_ONLY). Often, this may not be what one wants, since doing this has negative performance impact on execution time of a call to setDataSource(), since both types of operations may be time consuming.

Parameters

mode The intended mode of operation. Can be any combination of MODE_GET_METADATA_ONLY and MODE_CAPTURE_FRAME_ONLY: 1. MODE_GET_METADATA_ONLY & MODE_CAPTURE_FRAME_ONLY: For neither frame capture nor meta data retrieval 2. MODE_GET_METADATA_ONLY: For meta data retrieval only 3. MODE_CAPTURE_FRAME_ONLY: For frame capture only 4. MODE_GET_METADATA_ONLY | MODE_CAPTURE_FRAME_ONLY: For both frame capture and meta data retrieval

Protected Methods

protected void finalize()

Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Throws

Throwable
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56