AutoCloseablepublic class AVMetadataHelper extends Object implements AutoCloseable
SystemCapability.Multimedia#MEDIA_LIBRARY| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
AV_KEY_ALBUM |
Indicates the key to get the album title information of the media source.
|
static int |
AV_KEY_ALBUMARTIST |
Indicates the key to get the player or artist information related to the media source.
|
static int |
AV_KEY_ARTIST |
Indicates the key to get the artist information of the media source.
|
static int |
AV_KEY_AUTHOR |
Indicates the key to get the author information of the media source.
|
static int |
AV_KEY_BITRATE |
Indicates the key to get the average bit rate (in bit/s) of the media source.
|
static int |
AV_KEY_BITS_PER_SAMPLE |
Indicates the key to get the bit depth of the media source.
|
static int |
AV_KEY_CAPTURE_FRAMERATE |
Indicates the key to get the original frame rate of the media source.
|
static int |
AV_KEY_CD_TRACK_NUMBER |
Indicates the key to get the original audio recording sequence of the media source.
|
static int |
AV_KEY_COLOR_RANGE |
Indicates the key to get the color range of the media source.
|
static int |
AV_KEY_COLOR_STANDARD |
Indicates the key to get the color standard of the media source.
|
static int |
AV_KEY_COLOR_TRANSFER |
Indicates the key to get the color transfer of the media source.
|
static int |
AV_KEY_COMPILATION |
Indicates the key to get the album compilation status of the media source.
|
static int |
AV_KEY_COMPOSER |
Indicates the key to get the composer information of the media source.
|
static int |
AV_KEY_DATE |
Indicates the key to get the date when the media source is created or updated.
|
static int |
AV_KEY_DISC_NUMBER |
Indicates the key to get the position of audio data in the media source set.
|
static int |
AV_KEY_DURATION |
Indicates the key to get the playback duration of the media source.
|
static int |
AV_KEY_EXIF_LENGTH |
Indicates the key to get the Exif data size in the media source.
|
static int |
AV_KEY_EXIF_OFFSET |
Indicates the key to get the offset where the Exif data starts in the media source.
|
static int |
AV_KEY_GENRE |
Indicates the key to get the genre of the media source.
|
static int |
AV_KEY_HAS_AUDIO |
Indicates the key to get whether the media source contains audio content.
|
static int |
AV_KEY_HAS_IMAGE |
Indicates the key to get whether the media source contains static images.
|
static int |
AV_KEY_HAS_VIDEO |
Indicates the key to get whether the media source contains video content.
|
static int |
AV_KEY_IMAGE_COUNT |
Indicates the key to get the number of static images contained in the media source.
|
static int |
AV_KEY_IMAGE_HEIGHT |
Indicates the key to get the static image height in the media source.
|
static int |
AV_KEY_IMAGE_PRIMARY |
Indicates the key to get the main image sequence number in the media source.
|
static int |
AV_KEY_IMAGE_ROTATION |
Indicates the key to get the rotation angle of the static image in the media source.
|
static int |
AV_KEY_IMAGE_WIDTH |
Indicates the key to get the static image width in the media source.
|
static int |
AV_KEY_IS_DRM |
Indicates the key to get whether the media source is protected by digital rights management (DRM).
|
static int |
AV_KEY_LOCATION |
Indicates the key to get media source location information.
|
static int |
AV_KEY_MIMETYPE |
Indicates the key to get the MIME type of the media source.
|
static int |
AV_KEY_NUM_TRACKS |
Indicates the key to get the number of tracks in the media source.
|
static int |
AV_KEY_SAMPLERATE |
Indicates the key to get the sampling rate of the media source.
|
static int |
AV_KEY_TIMED_TEXT_LANGUAGES |
Indicates the key to get the language specific to text tracks of the media source.
|
static int |
AV_KEY_TITLE |
Indicates the key to get the media source title.
|
static int |
AV_KEY_VIDEO_FRAME_COUNT |
Indicates the key to get the total number of video frames in the media source.
|
static int |
AV_KEY_VIDEO_HEIGHT |
Indicates the key to get the frame height of the video in the media source.
|
static int |
AV_KEY_VIDEO_ROTATION |
Indicates the key to get the video rotation angle of the media source.
|
static int |
AV_KEY_VIDEO_WIDTH |
Indicates the key to get the frame width of the video in the media source.
|
static int |
AV_KEY_WRITER |
Indicates the key to get the writer (for example, lyricist) of the media source.
|
static int |
AV_KEY_YEAR |
Indicates the key to get the year when the media source is created or updated.
|
static int |
QUERY_OPTION_ARGB8888 |
Indicates a query option to get the ARGB8888 frame closest to the specified timestamp.
|
static int |
QUERY_OPTION_CLOSEST |
Indicates a query option to get the frame closest to the specified timestamp.
|
static int |
QUERY_OPTION_CLOSEST_SYNC |
Indicates a query option to get the keyframe closest to the specified timestamp.
|
static int |
QUERY_OPTION_NEXT_SYNC |
Indicates a query option to get the next keyframe closest to the specified timestamp.
|
static int |
QUERY_OPTION_PREVIOUS_SYNC |
Indicates a query option to get the previous keyframe closest to the specified timestamp.
|
| 构造器 | 说明 |
|---|---|
AVMetadataHelper() |
Default constructor used to create an
AVMetadataHelper instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
close() |
Closes this resource, relinquishing any underlying resources.
|
PixelMap |
fetchImagePixelMapByIndex(int imageIndex) |
Obtains the specified image from the image source.
|
PixelMap |
fetchImagePixelMapByIndex(int imageIndex,
PixelMapConfigs configs) |
Obtains the specified image from the image source based on the given pixel format options.
|
PixelMap |
fetchImagePrimaryPixelMap() |
Obtains the default image from the image source.
|
PixelMap |
fetchImagePrimaryPixelMap(PixelMapConfigs configs) |
Obtains the default image from the image source based on the given pixel format options.
|
PixelMap |
fetchVideoPixelMapByIndex(int frameIndex) |
Obtains a specified frame from the video source.
|
PixelMap |
fetchVideoPixelMapByIndex(int frameIndex,
PixelMapConfigs configs) |
Obtains a specified frame from the video source based on the given pixel format options.
|
PixelMap |
fetchVideoPixelMapByTime() |
Obtains the
PixelMap of a frame from the video source. |
PixelMap |
fetchVideoPixelMapByTime(long timeUs) |
Obtains the
PixelMap of the frame that is the closest to the specified video source timestamp. |
PixelMap |
fetchVideoPixelMapByTime(long timeUs,
int option) |
Obtains the
PixelMap of a frame based on the video source timestamp and query option. |
List<PixelMap> |
fetchVideoPixelMapsByIndex(int frameIndex,
int numFrames) |
Obtains specified consecutive frames from the video source.
|
List<PixelMap> |
fetchVideoPixelMapsByIndex(int frameIndex,
int numFrames,
PixelMapConfigs configs) |
Obtains specified consecutive frames from the video source based on the given pixel format options.
|
PixelMap |
fetchVideoScaledPixelMapByTime(long timeUs,
int option,
int dstWidth,
int dstHeight) |
Obtains the
PixelMap of a frame based on the specified video source timestamp, query option, and target
frame size. |
void |
release() |
Releases the media resources that have been read.
|
byte[] |
resolveImage() |
Obtains the image data from the audio source, for example, album cover image.
|
String |
resolveMetadata(int keyCode) |
Obtains the value matching the specified key in the media metadata.
|
boolean |
setSource(FileDescriptor fd) |
Sets the specified file descriptor as the source to read the media file.
|
boolean |
setSource(FileDescriptor fd,
long offset,
long length) |
Sets the media source described by the specified the file descriptor, offset, and data size for data reading.
|
boolean |
setSource(String path) |
Sets the specified path as the source to read the media file.
|
boolean |
setSource(String uri,
Map<String,String> headers) |
Sets the specified URI as the source to read the media file.
|
boolean |
setSource(Context context,
Uri uri) |
Sets the specified URI and context as the source to read the media file.
|
public static final int AV_KEY_ALBUM
public static final int AV_KEY_ALBUMARTIST
public static final int AV_KEY_ARTIST
public static final int AV_KEY_AUTHOR
public static final int AV_KEY_BITRATE
public static final int AV_KEY_BITS_PER_SAMPLE
public static final int AV_KEY_CAPTURE_FRAMERATE
public static final int AV_KEY_CD_TRACK_NUMBER
public static final int AV_KEY_COLOR_RANGE
public static final int AV_KEY_COLOR_STANDARD
public static final int AV_KEY_COLOR_TRANSFER
public static final int AV_KEY_COMPILATION
public static final int AV_KEY_COMPOSER
public static final int AV_KEY_DATE
public static final int AV_KEY_DISC_NUMBER
public static final int AV_KEY_DURATION
public static final int AV_KEY_EXIF_LENGTH
public static final int AV_KEY_EXIF_OFFSET
public static final int AV_KEY_GENRE
public static final int AV_KEY_HAS_AUDIO
public static final int AV_KEY_HAS_IMAGE
public static final int AV_KEY_HAS_VIDEO
public static final int AV_KEY_IMAGE_COUNT
public static final int AV_KEY_IMAGE_HEIGHT
public static final int AV_KEY_IMAGE_PRIMARY
public static final int AV_KEY_IMAGE_ROTATION
The value can be 0, 90, 180, or 270 degrees.
public static final int AV_KEY_IMAGE_WIDTH
public static final int AV_KEY_IS_DRM
public static final int AV_KEY_LOCATION
public static final int AV_KEY_MIMETYPE
public static final int AV_KEY_NUM_TRACKS
public static final int AV_KEY_SAMPLERATE
public static final int AV_KEY_TIMED_TEXT_LANGUAGES
public static final int AV_KEY_TITLE
public static final int AV_KEY_VIDEO_FRAME_COUNT
public static final int AV_KEY_VIDEO_HEIGHT
public static final int AV_KEY_VIDEO_ROTATION
The value can be 0, 90, 180, or 270 degrees.
public static final int AV_KEY_VIDEO_WIDTH
public static final int AV_KEY_WRITER
public static final int AV_KEY_YEAR
public static final int QUERY_OPTION_ARGB8888
public static final int QUERY_OPTION_CLOSEST
public static final int QUERY_OPTION_CLOSEST_SYNC
public static final int QUERY_OPTION_NEXT_SYNC
public static final int QUERY_OPTION_PREVIOUS_SYNC
public AVMetadataHelper()
AVMetadataHelper instance.public boolean setSource(String path)
path - Indicates the path for reading the media file.true if the operation is successful; returns false otherwise.public boolean setSource(FileDescriptor fd)
fd - Indicates the media file descriptor.true if the operation is successful; returns false otherwise.public boolean setSource(FileDescriptor fd, long offset, long length)
fd - Indicates the file descriptor of the media source.offset - Indicates the offset (in bytes) from where the media data will be read.length - Indicates the size (in bytes) of the media data to be read.true if the operation is successful; returns false otherwise.public boolean setSource(String uri, Map<String,String> headers)
uri - Indicates the URI of the media file to read.headers - Indicates the header used for accessing the URI.true if the operation is successful; returns false otherwise.public boolean setSource(Context context, Uri uri)
context - Indicates the context used for parsing the URI.uri - Indicates the URI of the media file.true if the operation is successful; returns false otherwise.public String resolveMetadata(int keyCode)
keyCode - Indicates the key in the media metadata.null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public PixelMap fetchVideoScaledPixelMapByTime(long timeUs, int option, int dstWidth, int dstHeight)
PixelMap of a frame based on the specified video source timestamp, query option, and target
frame size.timeUs - Indicates a timestamp in the video source.option - Indicates the frame query option, which can be QUERY_OPTION_PREVIOUS_SYNC, QUERY_OPTION_NEXT_SYNC, QUERY_OPTION_CLOSEST_SYNC, or QUERY_OPTION_CLOSEST.dstWidth - Indicates the expected width of the frame. The actual width may be changed based on the video
dimensions, and does not exceed the dstWidth value.dstHeight - Indicates the expected height of the frame. The actual height may be changed based on the video
dimensions, and does not exceed the dstHeight value.PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public PixelMap fetchVideoPixelMapByTime(long timeUs, int option)
PixelMap of a frame based on the video source timestamp and query option.timeUs - Indicates a timestamp in the video source.option - Indicates the frame query option, which can be QUERY_OPTION_NEXT_SYNC, QUERY_OPTION_CLOSEST_SYNC, QUERY_OPTION_CLOSEST, or QUERY_OPTION_ARGB8888.PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public PixelMap fetchVideoPixelMapByTime(long timeUs)
PixelMap of the frame that is the closest to the specified video source timestamp.timeUs - Indicates a timestamp in the video source.PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public PixelMap fetchVideoPixelMapByTime()
PixelMap of a frame from the video source.PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public byte[] resolveImage()
null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released.public PixelMap fetchVideoPixelMapByIndex(int frameIndex, PixelMapConfigs configs)
frameIndex - Indicates the frame index, which starts from 0.configs - Indicates the pixel format options.PixelMap if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if frameIndex is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no frame in the video source.public PixelMap fetchVideoPixelMapByIndex(int frameIndex)
frameIndex - Indicates the frame index, which starts from 0.PixelMap if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if frameIndex is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no frame in the video source.public List<PixelMap> fetchVideoPixelMapsByIndex(int frameIndex, int numFrames, PixelMapConfigs configs)
frameIndex - Indicates the index from which the consecutive frames start. The frame index starts from
0.numFrames - Indicates the number of consecutive frames to be obtained.configs - Indicates the pixel format options.PixelMap instances if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if frameIndex or numFrames is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no frame in the video source.public List<PixelMap> fetchVideoPixelMapsByIndex(int frameIndex, int numFrames)
frameIndex - Indicates the index from which the consecutive frames start. The frame index starts from
0.numFrames - Indicates the number of consecutive frames to be obtained.PixelMap instances if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if frameIndex or numFrames is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no frame in the video source.public PixelMap fetchImagePixelMapByIndex(int imageIndex, PixelMapConfigs configs)
imageIndex - Indicates the image index, which starts from 0.configs - Indicates the pixel format options.PixelMap if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if imageIndex is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no image in the image source.public PixelMap fetchImagePixelMapByIndex(int imageIndex)
imageIndex - Indicates the image index, which starts from 0.PixelMap if obtained; returns null otherwise.IllegalArgumentException - Throws this exception if imageIndex is invalid.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no image in the image source.public PixelMap fetchImagePrimaryPixelMap(PixelMapConfigs configs)
configs - Indicates the pixel format options.PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no image in the image source.public PixelMap fetchImagePrimaryPixelMap()
PixelMap if obtained; returns null otherwise.IllegalStateException - Throws this exception if resources associated with the AVMetadataHelper
are released, or there is no image in the image source.public void release()
public void close()
AutoCloseabletry-with-resources statement.
While this interface method is declared to throw
Exception, implementers are strongly encouraged to
declare concrete implementations of the close method to
throw more specific exceptions, or to throw no exception at all
if the close operation cannot fail.
Cases where the close operation may fail require careful
attention by implementers. It is strongly advised to relinquish
the underlying resources and to internally mark the
resource as closed, prior to throwing the exception. The
close method is unlikely to be invoked more than once and so
this ensures that the resources are released in a timely manner.
Furthermore it reduces problems that could arise when the resource
wraps, or is wrapped, by another resource.
Implementers of this interface are also strongly advised
to not have the close method throw InterruptedException.
This exception interacts with a thread's interrupted status,
and runtime misbehavior is likely to occur if an
InterruptedException is Throwable#addSuppressed.
More generally, if it would cause problems for an
exception to be suppressed, the AutoCloseable.close
method should not throw it.
Note that unlike the close
method of Closeable, this close method
is not required to be idempotent. In other words,
calling this close method more than once may have some
visible side effect, unlike Closeable.close which is
required to have no effect if called more than once.
However, implementers of this interface are strongly encouraged
to make their close methods idempotent.
close 在接口中 AutoCloseable