新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS媒體元數(shù)據(jù)獲取開發(fā)指導(dǎo)
場(chǎng)景介紹

為棗強(qiáng)等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及棗強(qiáng)網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、棗強(qiáng)網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
媒體元數(shù)據(jù)是描述多媒體數(shù)據(jù)的數(shù)據(jù),例如媒體標(biāo)題、媒體時(shí)長(zhǎng)、媒體的幀數(shù)據(jù)等。
接口說(shuō)明
| 接口名 | 描述 |
|---|---|
| setSource(String path) | 讀取指定路徑的媒體文件,將其設(shè)置為媒體源。 |
| setSource(FileDescriptor fd) | 讀取指定的媒體文件描述符,設(shè)置媒體源。 |
| setSource(FileDescriptor fd, long offset, long length) | 讀取指定的媒體文件描述符,讀取數(shù)據(jù)的起始位置的偏移量以及讀取的數(shù)據(jù)長(zhǎng)度,設(shè)置媒體源。 |
| setSource(String uri, Map | 讀取指定的媒體文件 Uri,設(shè)置媒體源。 |
| setSource(Context context, Uri uri) | 讀取指定的媒體的 Uri 和上下文,設(shè)置媒體源。 |
| resolveMetadata(int keyCode) | 獲取媒體元數(shù)據(jù)中指定 keyCode 對(duì)應(yīng)的值。 |
| fetchVideoScaledPixelMapByTime(long timeUs, int option, int dstWidth, int dstHeight) | 根據(jù)視頻源中時(shí)間戳、獲取選項(xiàng)以及圖像幀縮放大小,獲取幀數(shù)據(jù)。 |
| fetchVideoPixelMapByTime(long timeUs, int option) | 根據(jù)視頻源中時(shí)間戳和獲取選項(xiàng),獲取幀數(shù)據(jù)。 |
| fetchVideoPixelMapByTime(long timeUs) | 根據(jù)視頻源中時(shí)間戳,獲取最靠近時(shí)間戳的幀的數(shù)據(jù)。 |
| fetchVideoPixelMapByTime() | 隨機(jī)獲取數(shù)據(jù)源中某一幀的數(shù)據(jù)。 |
| resolveImage() | 獲取音頻源中包含的圖像數(shù)據(jù),比如專輯封面,如果有多個(gè)圖像,返回任意一個(gè)圖像的數(shù)據(jù)。 |
| fetchVideoPixelMapByIndex(int frameIndex, PixelMapConfigs configs) | 根據(jù)指定的圖像像素格式選項(xiàng),獲取視頻源中指定一幀的數(shù)據(jù)。 |
| fetchVideoPixelMapByIndex(int frameIndex) | 獲取視頻源中指定一幀的數(shù)據(jù)。 |
| fetchVideoPixelMapByIndex(int frameIndex, int numFrames, PixelMapConfigs configs) | 根據(jù)指定的圖像像素格式選項(xiàng),獲取視頻源中指定的連續(xù)多幀的數(shù)據(jù)。 |
| fetchVideoPixelMapByIndex(int frameIndex, int numFrames) | 獲取視頻源中指定的連續(xù)多幀的數(shù)據(jù)。 |
| fetchImagePixelMapByIndex(int imageIndex, PixelMapConfigs configs) | 根據(jù)指定的圖像像素格式選項(xiàng),獲取源圖像中指定的圖像。 |
| fetchImagePixelMapByIndex(int imageIndex) | 獲取源圖像中指定的圖像。 |
| fetchImagePrimaryPixelMap(PixelMapConfigs configs) | 據(jù)指定的圖像像素格式選項(xiàng),獲取源圖像中默認(rèn)圖像。 |
| fetchImagePrimaryPixelMap() | 獲取源圖像中默認(rèn)圖像。 |
| release() | 釋放讀取的媒體資源。 |
獲取幀數(shù)據(jù)的開發(fā)步驟
- 創(chuàng)建媒體數(shù)據(jù)管理 AVMetadataHelper 對(duì)象,可以通過(guò) setSource 設(shè)置要讀取的媒體文件,如果不設(shè)置或設(shè)置不正確,則無(wú)法進(jìn)行后續(xù)操作。
AVMetadataHelper avMetadataHelper = new AVMetadataHelper ();
avMetadataHelper.setSource("/path/short_video.mp4");
- 指定獲取幀數(shù)據(jù)的選項(xiàng),以及獲取幀的時(shí)間,獲取媒體源的幀數(shù)據(jù)。
PixelMap pixelMap = avMetadataHelper.fetchVideoPixelMapByTime(1000L, 0x00);
- 獲取到 PixelMap 對(duì)象后,調(diào)用 release()函數(shù)釋放讀取的媒體資源。
avMetadataHelper.release();
獲取媒體元數(shù)據(jù)的開發(fā)步驟
- 創(chuàng)建媒體數(shù)據(jù)管理 AVMetadataHelper 對(duì)象,可以通過(guò) setSource 設(shè)置要讀取的媒體文件,如果不設(shè)置或設(shè)置不正確,則無(wú)法進(jìn)行后續(xù)操作。
AVMetadataHelper avMetadataHelper= new AVMetadataHelper();
avMetadataHelper.setSource("/path/short_video.mp4");
- 指定要獲取的媒體元數(shù)據(jù)的 key,獲取媒體元數(shù)據(jù)。如下代碼獲取媒體的時(shí)長(zhǎng)信息:
String result = avMetadataHelper.resolveMetadata(AVMetadataHelper.AV_KEY_DURATION);
- 獲取到媒體元數(shù)據(jù)后,調(diào)用 release()函數(shù)釋放讀取的媒體資源。
avMetadataHelper.release();
獲取音頻的圖像數(shù)據(jù)的開發(fā)步驟
- 創(chuàng)建媒體數(shù)據(jù)管理 AVMetadataHelper 對(duì)象,可以通過(guò) setSource 設(shè)置要讀取的音頻媒體文件,如果不設(shè)置或設(shè)置不正確,則無(wú)法進(jìn)行后續(xù)操作。
AVMetadataHelper avMetadataHelper= new AVMetadataHelper();avMetadataHelper.setSource("/path/short_video.mp4");
- 獲取音頻的圖像數(shù)據(jù)。
byte[] data = avMetadataHelper.resolveImage();
- 獲取到圖像數(shù)據(jù)后,調(diào)用 release()函數(shù)釋放讀取的媒體資源。
avMetadataHelper.release(); 分享標(biāo)題:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS媒體元數(shù)據(jù)獲取開發(fā)指導(dǎo)
標(biāo)題路徑:http://www.fisionsoft.com.cn/article/dpcpieo.html


咨詢
建站咨詢
