您的位置:首页 > 其它

MediaMetadataRetriever

2016-06-02 14:27 519 查看
public class

MediaMetadataRetriever

extends Object

java.lang.Object
   ↳android.media.MediaMetadataRetriever


类概述

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


摘要

常量
intMETADATA_KEY_ALBUMThe metadata key to retrieve the information about the album title of the data source.
intMETADATA_KEY_ALBUMARTISTThe metadata key to retrieve the information about the performers or artist associated with the data source.
intMETADATA_KEY_ARTISTThe metadata key to retrieve the information about the artist of the data source.
intMETADATA_KEY_AUTHORThe metadata key to retrieve the information about the author of the data source.
intMETADATA_KEY_CD_TRACK_NUMBERThe metadata key to retrieve the numberic string describing the order of the audio data source on its original recording.
intMETADATA_KEY_COMPILATIONThe metadata key to retrieve the music album compilation status.
intMETADATA_KEY_COMPOSERThe metadata key to retrieve the information about the composer of the data source.
intMETADATA_KEY_DATEThe metadata key to retrieve the date when the data source was created or modified.
intMETADATA_KEY_DISC_NUMBERThe metadata key to retrieve the numberic string that describes which part of a set the audio data source comes from.
intMETADATA_KEY_DURATIONThe metadata key to retrieve the playback duration of the data source.
intMETADATA_KEY_GENREThe metadata key to retrieve the content type or genre of the data source.
intMETADATA_KEY_MIMETYPEThe metadata key to retrieve the mime type of the data source.
intMETADATA_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.
intMETADATA_KEY_TITLEThe metadata key to retrieve the data source title.
intMETADATA_KEY_WRITERThe metadata key to retrieve the information of the writer (such as lyricist) of the data source.
intMETADATA_KEY_YEARThe metadata key to retrieve the year when the data source was created or modified.
intOPTION_CLOSESTThis 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.
intOPTION_CLOSEST_SYNCThis 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.
intOPTION_NEXT_SYNCThis 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.
intOPTION_PREVIOUS_SYNCThis 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.
公有构造函数
MediaMetadataRetriever()
公有方法
StringextractMetadata(int keyCode)Call this method after setDataSource().
byte[]getEmbeddedPicture()Call this method after setDataSource().
BitmapgetFrameAtTime(long
timeUs, int option)Call this method after setDataSource().
BitmapgetFrameAtTime(long timeUs)Call this method after setDataSource().
BitmapgetFrameAtTime()Call this method after setDataSource().
voidrelease()Call it when one is done with the object.
voidsetDataSource(FileDescriptor fd,
long offset, long length)Sets the data source (FileDescriptor) to use.
voidsetDataSource(String path)Sets the data source (file pathname) to use.
voidsetDataSource(FileDescriptor fd)Sets the data source (FileDescriptor) to use.
voidsetDataSource(Context context, Uri uri)Sets the data source as a content Uri.
保护方法
voidfinalize()Called before the object's memory is reclaimed by the VM.
[展开]
继承的方法


 来自
class java.lang.Object


常量


public static final int METADATA_KEY_ALBUM

引入自:API 级别10

The metadata key to retrieve the information about the album title of the data source.

常量值: 1 (0x00000001)


public static final int METADATA_KEY_ALBUMARTIST

引入自:API 级别10

The metadata key to retrieve the information about the performers or artist associated with the data source.

常量值: 13 (0x0000000d)


public static final int METADATA_KEY_ARTIST

引入自:API 级别10

The metadata key to retrieve the information about the artist of the data source.

常量值: 2 (0x00000002)


public static final int METADATA_KEY_AUTHOR

引入自:API 级别10

The metadata key to retrieve the information about the author of the data source.

常量值: 3 (0x00000003)


public static final int METADATA_KEY_CD_TRACK_NUMBER

引入自:API 级别10

The metadata key to retrieve the numberic string describing the order of the audio data source on its original recording.

常量值: 0 (0x00000000)


public static final int METADATA_KEY_COMPILATION

引入自:API 级别10

The metadata key to retrieve the music album compilation status.

常量值: 15 (0x0000000f)


public static final int METADATA_KEY_COMPOSER

引入自:API 级别10

The metadata key to retrieve the information about the composer of the data source.

常量值: 4 (0x00000004)


public static final int METADATA_KEY_DATE

引入自:API 级别10

The metadata key to retrieve the date when the data source was created or modified.

常量值: 5 (0x00000005)


public static final int METADATA_KEY_DISC_NUMBER

引入自:API 级别10

The metadata key to retrieve the numberic string that describes which part of a set the audio data source comes from.

常量值: 14 (0x0000000e)


public static final int METADATA_KEY_DURATION

引入自:API 级别10

The metadata key to retrieve the playback duration of the data source.

常量值: 9 (0x00000009)


public static final int METADATA_KEY_GENRE

引入自:API 级别10

The metadata key to retrieve the content type or genre of the data source.

常量值: 6 (0x00000006)


public static final int METADATA_KEY_MIMETYPE

引入自:API 级别10

The metadata key to retrieve the mime type of the data source. Some example mime types include: "video/mp4", "audio/mp4", "audio/amr-wb", etc.

常量值: 12 (0x0000000c)


public static final int METADATA_KEY_NUM_TRACKS

引入自:API 级别10

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.

常量值: 10 (0x0000000a)


public static final int METADATA_KEY_TITLE

引入自:API 级别10

The metadata key to retrieve the data source title.

常量值: 7 (0x00000007)


public static final int METADATA_KEY_WRITER

引入自:API 级别10

The metadata key to retrieve the information of the writer (such as lyricist) of the data source.

常量值: 11 (0x0000000b)


public static final int METADATA_KEY_YEAR

引入自:API 级别10

The metadata key to retrieve the year when the data source was created or modified.

常量值: 8 (0x00000008)


public static final int OPTION_CLOSEST

引入自:API 级别10

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.


参见

getFrameAtTime(long,
int)


常量值: 3 (0x00000003)


public static final int OPTION_CLOSEST_SYNC

引入自:API 级别10

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.


参见

getFrameAtTime(long,
int)


常量值: 2 (0x00000002)


public static final int OPTION_NEXT_SYNC

引入自:API 级别10

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.


参见

getFrameAtTime(long,
int)


常量值: 1 (0x00000001)


public static final int OPTION_PREVIOUS_SYNC

引入自:API 级别10

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.


参见

getFrameAtTime(long,
int)


常量值: 0 (0x00000000)


公有构造函数


public MediaMetadataRetriever ()

引入自:API 级别10


公有方法


public String extractMetadata (int
keyCode)

引入自:API 级别10

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.


参数

keyCodeOne of the constants listed below at the end of the class.

返回值

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


public byte[] getEmbeddedPicture ()

引入自:API 级别10

Call this method after setDataSource(). This method finds the optional graphic or album art associated associated with the data source. If there are more than one pictures, (any) one of them is returned.


返回值

null if no such graphic is found.


public Bitmap getFrameAtTime (long
timeUs, int option)

引入自:API 级别10

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.


参数

timeUsThe 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.
optiona 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.

返回值

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


public Bitmap getFrameAtTime (long
timeUs)

引入自:API 级别10

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 
getFrameAtTime(long,
int)
.


参数

timeUsThe 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.

返回值

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


参见

getFrameAtTime(long,
int)



public Bitmap getFrameAtTime ()

引入自:API 级别10

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 
getFrameAtTime(long)
 or 
getFrameAtTime(long,
int)



返回值

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


参见

getFrameAtTime(long)

getFrameAtTime(long,
int)



public void release ()

引入自:API 级别10

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


public void setDataSource (FileDescriptor fd,
long offset, long length)

引入自:API 级别10

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.


参数

fdthe FileDescriptor for the file you want to play
offsetthe offset into the file where the data to be played starts, in bytes. It must be non-negative
lengththe length in bytes of the data to be played. It must be non-negative.

抛出

IllegalArgumentExceptionif the arguments are invalid


public void setDataSource (String path)

引入自:API 级别10

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.


参数

pathThe path of the input media file.

抛出

IllegalArgumentExceptionIf the path is invalid.


public void setDataSource (FileDescriptor fd)

引入自:API 级别10

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.


参数

fdthe FileDescriptor for the file you want to play

抛出

IllegalArgumentExceptionif the FileDescriptor is invalid


public void setDataSource (Context context, Uri uri)

引入自:API 级别10

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.


参数

contextthe Context to use when resolving the Uri
urithe Content URI of the data you want to play

抛出

IllegalArgumentExceptionif the Uri is invalid
SecurityExceptionif the Uri cannot be used due to lack of permission.


保护方法


protected void finalize ()

引入自:API 级别10

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override 
finalize()
 as
required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that 
finalize()
 is called at most once for any object, but it doesn't guarantee when (if at all) 
finalize()
 will
be called. For example, object B's 
finalize()
 can delay the execution of object A's 
finalize()
 method and therefore it can delay the reclamation
of A's memory. To be safe, use a 
ReferenceQueue
, because it provides more
control over the way the VM deals with references during garbage collection.


抛出

Throwable 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  实习