public class MediaMetadataRetriever extends Object
Modifier and Type | Field and Description |
---|---|
static int |
METADATA_KEY_ALBUM
The metadata key to retrieve the information about the album title
of the data source.
|
static int |
METADATA_KEY_ALBUMARTIST
The metadata key to retrieve the information about the performers or
artist associated with the data source.
|
static int |
METADATA_KEY_ARTIST
The metadata key to retrieve the information about the artist of
the data source.
|
static int |
METADATA_KEY_AUTHOR
The metadata key to retrieve the information about the author of
the data source.
|
static int |
METADATA_KEY_BITRATE
This key retrieves the average bitrate (in bits/sec), if available.
|
static int |
METADATA_KEY_CAPTURE_FRAMERATE
This key retrieves the original capture framerate, if it's
available.
|
static int |
METADATA_KEY_CD_TRACK_NUMBER
The metadata key to retrieve the numeric string describing the
order of the audio data source on its original recording.
|
static int |
METADATA_KEY_COMPILATION
The metadata key to retrieve the music album compilation status.
|
static int |
METADATA_KEY_COMPOSER
The metadata key to retrieve the information about the composer of
the data source.
|
static int |
METADATA_KEY_DATE
The metadata key to retrieve the date when the data source was created
or modified.
|
static int |
METADATA_KEY_DISC_NUMBER
The metadata key to retrieve the numberic string that describes which
part of a set the audio data source comes from.
|
static int |
METADATA_KEY_DURATION
The metadata key to retrieve the playback duration of the data source.
|
static int |
METADATA_KEY_GENRE
The metadata key to retrieve the content type or genre of the data
source.
|
static int |
METADATA_KEY_HAS_AUDIO
If this key exists the media contains audio content.
|
static int |
METADATA_KEY_HAS_VIDEO
If this key exists the media contains video content.
|
static int |
METADATA_KEY_IS_DRM
If this key exists the media is drm-protected.
|
static int |
METADATA_KEY_LOCATION
This key retrieves the location information, if available.
|
static int |
METADATA_KEY_MIMETYPE
The metadata key to retrieve the mime type of the data source.
|
static int |
METADATA_KEY_NUM_TRACKS
The metadata key to retrieve the number of tracks, such as audio, video,
text, in the data source, such as a mp4 or 3gpp file.
|
static int |
METADATA_KEY_TIMED_TEXT_LANGUAGES
This key retrieves the language code of text tracks, if available.
|
static int |
METADATA_KEY_TITLE
The metadata key to retrieve the data source title.
|
static int |
METADATA_KEY_VIDEO_HEIGHT
If the media contains video, this key retrieves its height.
|
static int |
METADATA_KEY_VIDEO_ROTATION
This key retrieves the video rotation angle in degrees, if available.
|
static int |
METADATA_KEY_VIDEO_WIDTH
If the media contains video, this key retrieves its width.
|
static int |
METADATA_KEY_WRITER
The metadata key to retrieve the information of the writer (such as
lyricist) of the data source.
|
static int |
METADATA_KEY_YEAR
The metadata key to retrieve the year when the data source was created
or modified.
|
static int |
OPTION_CLOSEST
This option is used with
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. |
static int |
OPTION_CLOSEST_SYNC
This option is used with
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. |
static int |
OPTION_NEXT_SYNC
This option is used with
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. |
static int |
OPTION_PREVIOUS_SYNC
This option is used with
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. |
Constructor and Description |
---|
MediaMetadataRetriever() |
Modifier and Type | Method and Description |
---|---|
String |
extractMetadata(int keyCode)
Call this method after setDataSource().
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
byte[] |
getEmbeddedPicture()
Call this method after setDataSource().
|
Bitmap |
getFrameAtTime()
Call this method after setDataSource().
|
Bitmap |
getFrameAtTime(long timeUs)
Call this method after setDataSource().
|
Bitmap |
getFrameAtTime(long timeUs,
int option)
Call this method after setDataSource().
|
void |
release()
Call it when one is done with the object.
|
void |
setDataSource(Context context,
Uri uri)
Sets the data source as a content Uri.
|
void |
setDataSource(FileDescriptor fd)
Sets the data source (FileDescriptor) to use.
|
void |
setDataSource(FileDescriptor fd,
long offset,
long length)
Sets the data source (FileDescriptor) to use.
|
void |
setDataSource(MediaDataSource dataSource)
Sets the data source (MediaDataSource) to use.
|
void |
setDataSource(String path)
Sets the data source (file pathname) to use.
|
void |
setDataSource(String uri,
Map<String,String> headers)
Sets the data source (URI) to use.
|
public static final int OPTION_PREVIOUS_SYNC
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.getFrameAtTime(long, int)
,
Constant Field Valuespublic static final int OPTION_NEXT_SYNC
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.getFrameAtTime(long, int)
,
Constant Field Valuespublic static final int OPTION_CLOSEST_SYNC
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.getFrameAtTime(long, int)
,
Constant Field Valuespublic static final int OPTION_CLOSEST
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.getFrameAtTime(long, int)
,
Constant Field Valuespublic 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_WRITER
public static final int METADATA_KEY_MIMETYPE
public static final int METADATA_KEY_ALBUMARTIST
public static final int METADATA_KEY_DISC_NUMBER
public static final int METADATA_KEY_COMPILATION
public static final int METADATA_KEY_HAS_AUDIO
public static final int METADATA_KEY_HAS_VIDEO
public static final int METADATA_KEY_VIDEO_WIDTH
public static final int METADATA_KEY_VIDEO_HEIGHT
public static final int METADATA_KEY_BITRATE
public static final int METADATA_KEY_TIMED_TEXT_LANGUAGES
public static final int METADATA_KEY_IS_DRM
public static final int METADATA_KEY_LOCATION
public static final int METADATA_KEY_VIDEO_ROTATION
public static final int METADATA_KEY_CAPTURE_FRAMERATE
public void setDataSource(String path) throws IllegalArgumentException
path
- The path of the input media file.IllegalArgumentException
- If the path is invalid.public void setDataSource(String uri, Map<String,String> headers) throws IllegalArgumentException
uri
- The URI of the input media.headers
- the headers to be sent together with the request for the dataIllegalArgumentException
- If the URI is invalid.public void setDataSource(FileDescriptor fd, long offset, long length) throws IllegalArgumentException
fd
- the FileDescriptor for the file you want to playoffset
- the offset into the file where the data to be played starts,
in bytes. It must be non-negativelength
- the length in bytes of the data to be played. It must be
non-negative.IllegalArgumentException
- if the arguments are invalidpublic void setDataSource(FileDescriptor fd) throws IllegalArgumentException
fd
- the FileDescriptor for the file you want to playIllegalArgumentException
- if the FileDescriptor is invalidpublic void setDataSource(Context context, Uri uri) throws IllegalArgumentException, SecurityException
context
- the Context to use when resolving the Uriuri
- the Content URI of the data you want to playIllegalArgumentException
- if the Uri is invalidSecurityException
- if the Uri cannot be used due to lack of
permission.public void setDataSource(MediaDataSource dataSource) throws IllegalArgumentException
dataSource
- the MediaDataSource for the media you want to playIllegalArgumentException
public String extractMetadata(int keyCode)
keyCode
- One of the constants listed below at the end of the class.public Bitmap getFrameAtTime(long timeUs, int option)
timeUs
- The time position where the frame will be retrieved.
When retrieving the frame at the given time position, there is no
guarantee that the data source has a frame located at the position.
When this happens, a frame nearby will be returned. If timeUs is
negative, time position and option will ignored, and any frame
that the implementation considers as representative may be returned.option
- a hint on how the frame is found. Use
OPTION_PREVIOUS_SYNC
if one wants to retrieve a sync frame
that has a timestamp earlier than or the same as timeUs. Use
OPTION_NEXT_SYNC
if one wants to retrieve a sync frame
that has a timestamp later than or the same as timeUs. Use
OPTION_CLOSEST_SYNC
if one wants to retrieve a sync frame
that has a timestamp closest to or the same as timeUs. Use
OPTION_CLOSEST
if one wants to retrieve a frame that may
or may not be a sync frame but is closest to or the same as timeUs.
OPTION_CLOSEST
often has larger performance overhead compared
to the other options if there is no sync frame located at timeUs.public Bitmap getFrameAtTime(long timeUs)
getFrameAtTime(long, int)
.timeUs
- The time position where the frame will be retrieved.
When retrieving the frame at the given time position, there is no
guarentee that the data source has a frame located at the position.
When this happens, a frame nearby will be returned. If timeUs is
negative, time position and option will ignored, and any frame
that the implementation considers as representative may be returned.getFrameAtTime(long, int)
public Bitmap getFrameAtTime()
getFrameAtTime(long)
or getFrameAtTime(long, int)
getFrameAtTime(long)
,
getFrameAtTime(long, int)
public byte[] getEmbeddedPicture()
public void release()
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.