FileDocCategorySizeDatePackage
MediaMetadataRetriever.javaAPI DocAndroid 1.5 API10179Wed May 06 22:42:00 BST 2009android.media

MediaMetadataRetriever

public class MediaMetadataRetriever extends Object
MediaMetadataRetriever class provides a unified interface for retrieving frame and meta data from an input media file. {@hide}

Fields Summary
private int
mNativeContext
public static final int
MODE_GET_METADATA_ONLY
public static final int
MODE_CAPTURE_FRAME_ONLY
public static final int
METADATA_KEY_CD_TRACK_NUMBER
public static final int
METADATA_KEY_ALBUM
public static final int
METADATA_KEY_ARTIST
public static final int
METADATA_KEY_AUTHOR
public static final int
METADATA_KEY_COMPOSER
public static final int
METADATA_KEY_DATE
public static final int
METADATA_KEY_GENRE
public static final int
METADATA_KEY_TITLE
public static final int
METADATA_KEY_YEAR
public static final int
METADATA_KEY_DURATION
public static final int
METADATA_KEY_NUM_TRACKS
public static final int
METADATA_KEY_IS_DRM_CRIPPLED
public static final int
METADATA_KEY_CODEC
public static final int
METADATA_KEY_RATING
public static final int
METADATA_KEY_COMMENT
public static final int
METADATA_KEY_COPYRIGHT
public static final int
METADATA_KEY_BIT_RATE
public static final int
METADATA_KEY_FRAME_RATE
public static final int
METADATA_KEY_VIDEO_FORMAT
public static final int
METADATA_KEY_VIDEO_HEIGHT
public static final int
METADATA_KEY_VIDEO_WIDTH
Constructors Summary
public MediaMetadataRetriever()

        native_setup();
    
Methods Summary
public native android.graphics.BitmapcaptureFrame()
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.

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

public native 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.

return
null if no such graphic is found.

public native java.lang.StringextractMetadata(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.

param
keyCode One of the constants listed below at the end of the class.
return
The meta data value associate with the given keyCode on success; null on failure.

protected voidfinalize()

        try {
            native_finalize();
        } finally {
            super.finalize();
        }
    
public native intgetMode()

return
the current mode of operation. A negative return value indicates some runtime error has occurred.

private final native voidnative_finalize()

private native voidnative_setup()

public native voidrelease()
Call it when one is done with the object. This method releases the memory allocated internally.

public native voidsetDataSource(java.lang.String path)
Sets the data source (file pathname) to use. Call this method before the rest of the methods in this class. This method may be time-consuming.

param
path The path of the input media file.
throws
IllegalArgumentException If the path is invalid.

public native voidsetDataSource(java.io.FileDescriptor fd, long offset, long length)
Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns. Call this method before the rest of the methods in this class. This method may be time-consuming.

param
fd the FileDescriptor for the file you want to play
param
offset the offset into the file where the data to be played starts, in bytes. It must be non-negative
param
length the length in bytes of the data to be played. It must be non-negative.
throws
IllegalArgumentException if the arguments are invalid

public voidsetDataSource(java.io.FileDescriptor fd)
Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns. Call this method before the rest of the methods in this class. This method may be time-consuming.

param
fd the FileDescriptor for the file you want to play
throws
IllegalArgumentException if the FileDescriptor is invalid

        // intentionally less than LONG_MAX
        setDataSource(fd, 0, 0x7ffffffffffffffL);
    
public voidsetDataSource(android.content.Context context, android.net.Uri uri)
Sets the data source as a content Uri. Call this method before the rest of the methods in this class. This method may be time-consuming.

param
context the Context to use when resolving the Uri
param
uri the Content URI of the data you want to play
throws
IllegalArgumentException if the Uri is invalid
throws
SecurityException if the Uri cannot be used due to lack of permission.

        if (uri == null) {
            throw new IllegalArgumentException();
        }
        
        String scheme = uri.getScheme();
        if(scheme == null || scheme.equals("file")) {
            setDataSource(uri.getPath());
            return;
        }

        AssetFileDescriptor fd = null;
        try {
            ContentResolver resolver = context.getContentResolver();
            try {
                fd = resolver.openAssetFileDescriptor(uri, "r");
            } catch(FileNotFoundException e) {
                throw new IllegalArgumentException();
            }
            if (fd == null) {
                throw new IllegalArgumentException();
            }
            FileDescriptor descriptor = fd.getFileDescriptor();
            if (!descriptor.valid()) {
                throw new IllegalArgumentException();
            }
            // Note: using getDeclaredLength so that our behavior is the same
            // as previous versions when the content provider is returning
            // a full file.
            if (fd.getDeclaredLength() < 0) {
                setDataSource(descriptor);
            } else {
                setDataSource(descriptor, fd.getStartOffset(), fd.getDeclaredLength());
            }
            return;
        } catch (SecurityException ex) {
        } finally {
            try {
                if (fd != null) {
                    fd.close();
                }
            } catch(IOException ioEx) {
            }
        }
        setDataSource(uri.toString());
    
public native voidsetMode(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.

param
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