MediaMetadataRetrieverpublic class MediaMetadataRetriever extends Object MediaMetadataRetriever class provides a unified interface for retrieving
frame and meta data from an input media file. |
Fields Summary |
---|
private long | mNativeContext | private static final int | EMBEDDED_PICTURE_TYPE_ANY | public static final int | OPTION_PREVIOUS_SYNCThis option is used with {@link #getFrameAtTime(long, int)} to retrieve
a sync (or key) frame associated with a data source that is located
right before or at the given time. | public static final int | OPTION_NEXT_SYNCThis option is used with {@link #getFrameAtTime(long, int)} to retrieve
a sync (or key) frame associated with a data source that is located
right after or at the given time. | public static final int | OPTION_CLOSEST_SYNCThis option is used with {@link #getFrameAtTime(long, int)} to retrieve
a sync (or key) frame associated with a data source that is located
closest to (in time) or at the given time. | public static final int | OPTION_CLOSESTThis option is used with {@link #getFrameAtTime(long, int)} to retrieve
a frame (not necessarily a key frame) associated with a data source that
is located closest to or at the given time. | public static final int | METADATA_KEY_CD_TRACK_NUMBERThe metadata key to retrieve the numeric string describing the
order of the audio data source on its original recording. | public static final int | METADATA_KEY_ALBUMThe metadata key to retrieve the information about the album title
of the data source. | public static final int | METADATA_KEY_ARTISTThe metadata key to retrieve the information about the artist of
the data source. | public static final int | METADATA_KEY_AUTHORThe metadata key to retrieve the information about the author of
the data source. | public static final int | METADATA_KEY_COMPOSERThe metadata key to retrieve the information about the composer of
the data source. | public static final int | METADATA_KEY_DATEThe metadata key to retrieve the date when the data source was created
or modified. | public static final int | METADATA_KEY_GENREThe metadata key to retrieve the content type or genre of the data
source. | public static final int | METADATA_KEY_TITLEThe metadata key to retrieve the data source title. | public static final int | METADATA_KEY_YEARThe metadata key to retrieve the year when the data source was created
or modified. | public static final int | METADATA_KEY_DURATIONThe metadata key to retrieve the playback duration of the data source. | public static final int | METADATA_KEY_NUM_TRACKSThe metadata key to retrieve the number of tracks, such as audio, video,
text, in the data source, such as a mp4 or 3gpp file. | public static final int | METADATA_KEY_WRITERThe metadata key to retrieve the information of the writer (such as
lyricist) of the data source. | public static final int | METADATA_KEY_MIMETYPEThe metadata key to retrieve the mime type of the data source. Some
example mime types include: "video/mp4", "audio/mp4", "audio/amr-wb",
etc. | public static final int | METADATA_KEY_ALBUMARTISTThe metadata key to retrieve the information about the performers or
artist associated with the data source. | public static final int | METADATA_KEY_DISC_NUMBERThe metadata key to retrieve the numberic string that describes which
part of a set the audio data source comes from. | public static final int | METADATA_KEY_COMPILATIONThe metadata key to retrieve the music album compilation status. | public static final int | METADATA_KEY_HAS_AUDIOIf this key exists the media contains audio content. | public static final int | METADATA_KEY_HAS_VIDEOIf this key exists the media contains video content. | public static final int | METADATA_KEY_VIDEO_WIDTHIf the media contains video, this key retrieves its width. | public static final int | METADATA_KEY_VIDEO_HEIGHTIf the media contains video, this key retrieves its height. | public static final int | METADATA_KEY_BITRATEThis key retrieves the average bitrate (in bits/sec), if available. | public static final int | METADATA_KEY_TIMED_TEXT_LANGUAGESThis key retrieves the language code of text tracks, if available.
If multiple text tracks present, the return value will look like:
"eng:chi" | public static final int | METADATA_KEY_IS_DRMIf this key exists the media is drm-protected. | public static final int | METADATA_KEY_LOCATIONThis key retrieves the location information, if available.
The location should be specified according to ISO-6709 standard, under
a mp4/3gp box "@xyz". Location with longitude of -90 degrees and latitude
of 180 degrees will be retrieved as "-90.0000+180.0000", for instance. | public static final int | METADATA_KEY_VIDEO_ROTATIONThis key retrieves the video rotation angle in degrees, if available.
The video rotation angle may be 0, 90, 180, or 270 degrees. |
Constructors Summary |
---|
public MediaMetadataRetriever()
native_setup();
|
Methods Summary |
---|
private native android.graphics.Bitmap | _getFrameAtTime(long timeUs, int option)
| private native void | _setDataSource(android.os.IBinder httpServiceBinder, java.lang.String uri, java.lang.String[] keys, java.lang.String[] values)
| public native java.lang.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.
| protected void | finalize()
try {
native_finalize();
} finally {
super.finalize();
}
| public byte[] | getEmbeddedPicture()Call this method after setDataSource(). This method finds the optional
graphic or album/cover art associated associated with the data source. If
there are more than one pictures, (any) one of them is returned.
return getEmbeddedPicture(EMBEDDED_PICTURE_TYPE_ANY);
| private native byte[] | getEmbeddedPicture(int pictureType)
| public android.graphics.Bitmap | getFrameAtTime(long timeUs)Call this method after setDataSource(). This method finds a
representative frame close to the given time position if possible,
and returns it as a bitmap. This is useful for generating a thumbnail
for an input data source. Call this method if one does not care
how the frame is found as long as it is close to the given time;
otherwise, please call {@link #getFrameAtTime(long, int)}.
return getFrameAtTime(timeUs, OPTION_CLOSEST_SYNC);
| public android.graphics.Bitmap | getFrameAtTime()Call this method after setDataSource(). This method finds a
representative frame at any time position if possible,
and returns it as a bitmap. This is useful for generating a thumbnail
for an input data source. Call this method if one does not
care about where the frame is located; otherwise, please call
{@link #getFrameAtTime(long)} or {@link #getFrameAtTime(long, int)}
return getFrameAtTime(-1, OPTION_CLOSEST_SYNC);
| public android.graphics.Bitmap | getFrameAtTime(long timeUs, int option)Call this method after setDataSource(). This method finds a
representative frame close to the given time position by considering
the given option if possible, and returns it as a bitmap. This is
useful for generating a thumbnail for an input data source or just
obtain and display a frame at the given time position.
if (option < OPTION_PREVIOUS_SYNC ||
option > OPTION_CLOSEST) {
throw new IllegalArgumentException("Unsupported option: " + option);
}
return _getFrameAtTime(timeUs, option);
| private final native void | native_finalize()
| private static native void | native_init()
| private native void | native_setup()
| public native void | release()Call it when one is done with the object. This method releases the memory
allocated internally.
| public void | setDataSource(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.
if (path == null) {
throw new IllegalArgumentException();
}
FileInputStream is = null;
try {
is = new FileInputStream(path);
FileDescriptor fd = is.getFD();
setDataSource(fd, 0, 0x7ffffffffffffffL);
} catch (FileNotFoundException fileEx) {
throw new IllegalArgumentException();
} catch (IOException ioEx) {
throw new IllegalArgumentException();
}
try {
if (is != null) {
is.close();
}
} catch (Exception e) {}
| public void | setDataSource(java.lang.String uri, java.util.Map headers)Sets the data source (URI) to use. Call this
method before the rest of the methods in this class. This method may be
time-consuming.
int i = 0;
String[] keys = new String[headers.size()];
String[] values = new String[headers.size()];
for (Map.Entry<String, String> entry: headers.entrySet()) {
keys[i] = entry.getKey();
values[i] = entry.getValue();
++i;
}
_setDataSource(
MediaHTTPService.createHttpServiceBinderIfNecessary(uri),
uri,
keys,
values);
| public native void | setDataSource(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.
| public void | setDataSource(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.
// intentionally less than LONG_MAX
setDataSource(fd, 0, 0x7ffffffffffffffL);
| public void | setDataSource(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.
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());
|
|