js-apis-media.md 88.6 KB
Newer Older
W
wusongqing 已提交
1
# 媒体服务
2

Z
zengyawen 已提交
3 4 5
> **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

W
wusongqing 已提交
6
媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。
Z
zengyawen 已提交
7

W
wusongqing 已提交
8
媒体子系统包含了音视频相关媒体业务,提供以下常用功能:
9

W
wusongqing 已提交
10 11 12 13
- 音频播放([AudioPlayer](#audioplayer)
- 视频播放([VideoPlayer](#videoplayer8)
- 音频录制([AudioRecorder](#audiorecorder)
- 视频录制([VideoRecorder](#VideoRecorder<sup>8+</sup>))
14

W
wusongqing 已提交
15
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。
16

W
wusongqing 已提交
17
## 导入模块
Z
zengyawen 已提交
18

19
```js
Z
zengyawen 已提交
20 21 22
import media from '@ohos.multimedia.media';
```

23
##  media.createAudioPlayer
Z
zengyawen 已提交
24

25
createAudioPlayer(): [AudioPlayer](#audioplayer)
Z
zengyawen 已提交
26

W
wusongqing 已提交
27 28
同步方式创建音频播放实例。

Z
zengyawen 已提交
29
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer
30

W
wusongqing 已提交
31
**返回值:**
Z
zengyawen 已提交
32

W
wusongqing 已提交
33
| 类型                        | 说明                                                         |
34
| --------------------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
35
| [AudioPlayer](#audioplayer) | 返回AudioPlayer类实例,失败时返回null。可用于音频播放、暂停、停止等操作。 |
Z
zengyawen 已提交
36

W
wusongqing 已提交
37
**示例:**
Z
zengyawen 已提交
38

39
```js
Z
zengyawen 已提交
40
let audioPlayer = media.createAudioPlayer();
Z
zengyawen 已提交
41
```
42

43 44 45 46
## media.createVideoPlayer<sup>8+</sup>

createVideoPlayer(callback: AsyncCallback\<[VideoPlayer](#videoplayer8)>): void

W
wusongqing 已提交
47
异步方式创建视频播放实例,通过注册回调函数获取返回值。
48

Z
zengyawen 已提交
49 50
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
51
**参数:**
Z
zengyawen 已提交
52

W
wusongqing 已提交
53
| 参数名   | 类型                                        | 必填 | 说明                           |
Z
zengyawen 已提交
54
| -------- | ------------------------------------------- | ---- | ------------------------------ |
W
wusongqing 已提交
55
| callback | AsyncCallback<[VideoPlayer](#videoplayer8)> | 是   | 异步创建视频播放实例回调方法。 |
56

W
wusongqing 已提交
57
**示例:**
58 59

```js
Z
zengyawen 已提交
60 61
let videoPlayer

62 63 64 65 66 67 68 69 70 71 72 73 74 75
media.createVideoPlayer((error, video) => {
   if (typeof(video) != 'undefined') {
       videoPlayer = video;
       console.info('video createVideoPlayer success');
   } else {
       console.info(`video createVideoPlayer fail, error:${error.message}`);
   }
});
```

## media.createVideoPlayer<sup>8+</sup>

createVideoPlayer: Promise<[VideoPlayer](#videoplayer8)>

W
wusongqing 已提交
76
异步方式创建视频播放实例,通过Promise获取返回值。
77

Z
zengyawen 已提交
78 79
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
80
**返回值:**
Z
zengyawen 已提交
81

W
wusongqing 已提交
82
| 类型                                  | 说明                                |
Z
zengyawen 已提交
83
| ------------------------------------- | ----------------------------------- |
W
wusongqing 已提交
84
| Promise<[VideoPlayer](#videoplayer8)> | 异步创建视频播放实例Promise返回值。 |
85

W
wusongqing 已提交
86
**示例:**
87 88

```js
Z
zengyawen 已提交
89 90
let videoPlayer

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}

await media.createVideoPlayer.then((video) => {
    if (typeof(video) != 'undefined') {
       videoPlayer = video;
       console.info('video createVideoPlayer success');
   } else {
       console.info('video createVideoPlayer fail');
   }
}, failureCallback).catch(catchCallback);
```

Z
zengyawen 已提交
108
## media.createAudioRecorder
109

Z
zengyawen 已提交
110
createAudioRecorder(): AudioRecorder
Z
zengyawen 已提交
111

W
wusongqing 已提交
112
创建音频录制的实例来控制音频的录制。
Z
zengyawen 已提交
113

Z
zengyawen 已提交
114 115
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
116
**返回值:**
Z
zengyawen 已提交
117

W
wusongqing 已提交
118
| 类型                            | 说明                                      |
Z
zengyawen 已提交
119
| ------------------------------- | ----------------------------------------- |
W
wusongqing 已提交
120
| [AudioRecorder](#audiorecorder) | 返回AudioRecorder类实例,失败时返回null。 |
Z
zengyawen 已提交
121

W
wusongqing 已提交
122
**示例:**
123

124
```js
B
bird_j 已提交
125
let audiorecorder = media.createAudioRecorder(); 
Z
zengyawen 已提交
126
```
Z
zengyawen 已提交
127

Z
zengyawen 已提交
128
## media.createVideoRecorder<sup>8+</sup>
W
wusongqing 已提交
129

Z
zengyawen 已提交
130
createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder8)>): void
W
wusongqing 已提交
131 132 133

异步方式创建视频录制实例。通过注册回调函数获取返回值。

Z
zengyawen 已提交
134 135
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
136 137
**参数:**

Z
zengyawen 已提交
138 139
| 参数名   | 类型                                            | 必填 | 说明                           |
| -------- | ----------------------------------------------- | ---- | ------------------------------ |
W
wusongqing 已提交
140 141 142 143 144
| callback | AsyncCallback<[VideoRecorder](#videorecorder8)> | 是   | 异步创建视频录制实例回调方法。 |

**示例:**

```js
Z
zengyawen 已提交
145 146 147
let videoRecorder

media.createVideoRecorder((error, video) => {
148 149
   if (typeof(video) != 'undefined') {
       videoRecorder = video;
Z
zengyawen 已提交
150
       console.info('video createVideoRecorder success');
151
   } else {
Z
zengyawen 已提交
152
       console.info(`video createVideoRecorder fail, error:${error.message}`);
153 154 155 156
   }
});
```

Z
zengyawen 已提交
157
## media.createVideoRecorder<sup>8+</sup>
158

Z
zengyawen 已提交
159
createVideoRecorder: Promise<[VideoRecorder](#videorecorder8)>
160

W
wusongqing 已提交
161
异步方式创建视频录制实例。通过Promise获取返回值。
Z
zengyawen 已提交
162

Z
zengyawen 已提交
163 164
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
165
**返回值:**
166

Z
zengyawen 已提交
167 168
| 类型                                      | 说明                                |
| ----------------------------------------- | ----------------------------------- |
W
wusongqing 已提交
169
| Promise<[VideoRecorder](#videorecorder8)> | 异步创建视频录制实例Promise返回值。 |
170

W
wusongqing 已提交
171
**示例:**
172 173

```js
Z
zengyawen 已提交
174 175
let videoRecorder

176 177 178 179 180 181 182
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}

Z
zengyawen 已提交
183
await media.createVideoRecorder.then((video) => {
184 185
    if (typeof(video) != 'undefined') {
       videoRecorder = video;
Z
zengyawen 已提交
186
       console.info('video createVideoRecorder success');
187
   } else {
Z
zengyawen 已提交
188
       console.info('video createVideoRecorder fail');
189 190 191 192 193 194
   }
}, failureCallback).catch(catchCallback);
```



195 196
## MediaErrorCode<sup>8+</sup>

Z
zengyawen 已提交
197 198 199
媒体服务错误类型枚举。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
W
wusongqing 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212

| 名称                       | 值   | 说明                                   |
| -------------------------- | ---- | -------------------------------------- |
| MSERR_OK                   | 0    | 表示操作成功。                         |
| MSERR_NO_MEMORY            | 1    | 表示申请内存失败,系统可能无可用内存。 |
| MSERR_OPERATION_NOT_PERMIT | 2    | 表示无权限执行此操作。                 |
| MSERR_INVALID_VAL          | 3    | 表示传入入参无效。                     |
| MSERR_IO                   | 4    | 表示发生IO错误。                       |
| MSERR_TIMEOUT              | 5    | 表示操作超时。                         |
| MSERR_UNKNOWN              | 6    | 表示未知错误。                         |
| MSERR_SERVICE_DIED         | 7    | 表示服务端失效。                       |
| MSERR_INVALID_STATE        | 8    | 表示在当前状态下,不允许执行此操作。   |
| MSERR_UNSUPPORTED          | 9    | 表示在当前版本下,不支持此操作。       |
213 214 215

## MediaType<sup>8+</sup>

Z
zengyawen 已提交
216 217 218
媒体类型枚举。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
219

Z
zengyawen 已提交
220 221 222 223
| 名称           | 值   | 说明       |
| -------------- | ---- | ---------- |
| MEDIA_TYPE_AUD | 0    | 表示音频。 |
| MEDIA_TYPE_VID | 1    | 表示视频。 |
224 225 226

## CodecMimeType<sup>8+</sup>

Z
zengyawen 已提交
227 228 229
Codec MIME类型枚举。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
230

W
wusongqing 已提交
231 232 233 234 235 236
| 名称         | 值                | 说明                     |
| ------------ | ----------------- | ------------------------ |
| VIDEO_MPEG4  | ”video/mp4v-es“   | 表示视频/mpeg4类型。     |
| AUDIO_AAC    | "audio/mp4a-latm" | 表示音频/mp4a-latm类型。 |
| AUDIO_VORBIS | "audio/vorbis"    | 表示音频/vorbis类型。    |
| AUDIO_FLAC   | "audio/flac"      | 表示音频/flac类型。      |
237 238 239

## MediaDescriptionKey<sup>8+</sup>

Z
zengyawen 已提交
240 241 242
媒体信息描述枚举。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
243

W
wusongqing 已提交
244
| 名称                     | 值              | 说明                                                         |
245
| ------------------------ | --------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
246 247 248 249 250 251 252 253 254 255
| MD_KEY_TRACK_INDEX       | "track_index"   | 表示轨道序号,其对应键值类型为number。                       |
| MD_KEY_TRACK_TYPE        | "track_type"    | 表示轨道类型,其对应键值类型为number,参考[MediaType](#mediatype8)。 |
| MD_KEY_CODEC_MIME        | "codec_mime"    | 表示codec_mime类型,其对应键值类型为string。                 |
| MD_KEY_DURATION          | "duration"      | 表示媒体时长,其对应键值类型为number,单位为ms。             |
| MD_KEY_BITRATE           | "bitrate"       | 表示比特率,其对应键值类型为number,单位为bps。              |
| MD_KEY_WIDTH             | "width"         | 表示视频宽度,其对应键值类型为number,单位为像素。           |
| MD_KEY_HEIGHT            | "height"        | 表示视频高度,其对应键值类型为number,单位为像素。           |
| MD_KEY_FRAME_RATE        | "frame_rate"    | 表示视频帧率,其对应键值类型为number,单位为100fps。         |
| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | 表示声道数,其对应键值类型为number。                         |
| MD_KEY_AUD_SAMPLE_RATE   | "sample_rate"   | 表示采样率,其对应键值类型为number,单位为HZ。               |
256 257 258

## BufferingInfoType<sup>8+</sup>

Z
zengyawen 已提交
259 260 261
缓存事件类型枚举。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
262

W
wusongqing 已提交
263 264 265 266 267 268
| 名称              | 值   | 说明                       |
| ----------------- | ---- | -------------------------- |
| BUFFERING_START   | 1    | 表示开始缓存。             |
| BUFFERING_END     | 2    | 表示结束缓存。             |
| BUFFERING_PERCENT | 3    | 表示缓存百分比。           |
| CACHED_DURATION   | 4    | 表示缓存时长,单位为毫秒。 |
269

Z
zengyawen 已提交
270
## AudioPlayer
Z
zengyawen 已提交
271

Z
zengyawen 已提交
272
音频播放管理类,用于管理和播放音频媒体。在调用AudioPlayer的方法前,需要先通过[createAudioPlayer()](#mediacreateaudioplayer)构建一个[AudioPlayer](#audioplayer)实例。
Z
zengyawen 已提交
273

W
wusongqing 已提交
274
音频播放demo可参考:[音频播放开发指导](../../media/audio-playback.md)
Z
zengyawen 已提交
275

W
wusongqing 已提交
276
### 属性<a name=audioplayer_属性></a>
Z
zengyawen 已提交
277

Z
zengyawen 已提交
278 279
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.AudioPlayer。

W
wusongqing 已提交
280
| 名称        | 类型                      | 可读 | 可写 | 说明                                                         |
281
| ----------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ |
Z
zengyawen 已提交
282 283 284 285 286
| src         | string                    | 是   | 是   | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。<br>**支持路径示例**<br>1、fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>2、http网络播放路径:开发中<br>3、hls网络播放路径:开发中<br>**注意事项**<br>使用媒体素材需要获取读权限,否则无法正常播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer |
| loop        | boolean                   | 是   | 是   | 音频循环播放属性,设置为'true'表示循环播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer |
| currentTime | number                    | 是   | 否   | 音频的当前播放位置。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer |
| duration    | number                    | 是   | 否   | 音频时长。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer |
| state       | [AudioState](#audiostate) | 是   | 否   | 音频播放的状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer |
Z
zengyawen 已提交
287

288
### play<a name=audioplayer_play></a>
Z
zengyawen 已提交
289

Z
zengyawen 已提交
290
play(): void
Z
zengyawen 已提交
291

W
wusongqing 已提交
292
开始播放音频资源,需在[dataLoad](#on('play' | 'pause' | 'stop' | 'reset' | 'dataload' | 'finish' | 'volumechange'))事件成功触发后,才能调用play方法。
Z
zengyawen 已提交
293

Z
zengyawen 已提交
294 295
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
296
**示例:**
Z
zengyawen 已提交
297

298
```js
W
wusongqing 已提交
299
audioPlayer.on('play', () => {    //设置'play'事件回调
300
    console.log('audio play success');
Z
zengyawen 已提交
301
});
302
audioPlayer.play();
Z
zengyawen 已提交
303
```
Z
zengyawen 已提交
304

305
### pause<a name=audioplayer_pause></a>
Z
zengyawen 已提交
306

Z
zengyawen 已提交
307
pause(): void
Z
zengyawen 已提交
308

W
wusongqing 已提交
309
暂停播放音频资源。
B
bird_j 已提交
310

Z
zengyawen 已提交
311 312
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
313
**示例:**
Z
zengyawen 已提交
314

315
```js
W
wusongqing 已提交
316
audioPlayer.on('pause', () => {    //设置'pause'事件回调
317
    console.log('audio pause success');
Z
zengyawen 已提交
318
});
319
audioPlayer.pause();
Z
zengyawen 已提交
320
```
Z
zengyawen 已提交
321

322
### stop<a name=audioplayer_stop></a>
Z
zengyawen 已提交
323

Z
zengyawen 已提交
324
stop(): void
Z
zengyawen 已提交
325

W
wusongqing 已提交
326
停止播放音频资源。
Z
zengyawen 已提交
327

Z
zengyawen 已提交
328 329
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
330
**示例:**
Z
zengyawen 已提交
331

332
```js
W
wusongqing 已提交
333
audioPlayer.on('stop', () => {    //设置'stop'事件回调
334 335 336
    console.log('audio stop success');
});
audioPlayer.stop();
Z
zengyawen 已提交
337
```
338 339 340 341 342

### reset<sup>7+</sup><a name=audioplayer_reset></a>

reset(): void

W
wusongqing 已提交
343
切换播放音频资源。
B
bird_j 已提交
344

Z
zengyawen 已提交
345 346
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
347
**示例:**
348 349

```js
W
wusongqing 已提交
350
audioPlayer.on('reset', () => {    //设置'reset'事件回调
351
    console.log('audio reset success');
Z
zengyawen 已提交
352
});
353
audioPlayer.reset();
Z
zengyawen 已提交
354
```
Z
zengyawen 已提交
355

356
### seek<a name=audioplayer_seek></a>
Z
zengyawen 已提交
357

Z
zengyawen 已提交
358
seek(timeMs: number): void
Z
zengyawen 已提交
359

W
wusongqing 已提交
360
跳转到指定播放位置。
Z
zengyawen 已提交
361

Z
zengyawen 已提交
362 363
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
364
**参数:**
B
bird_j 已提交
365

W
wusongqing 已提交
366
| 参数名 | 类型   | 必填 | 说明                           |
367
| ------ | ------ | ---- | ------------------------------ |
W
wusongqing 已提交
368
| timeMs | number | 是   | 指定的跳转时间节点,单位毫秒。 |
Z
zengyawen 已提交
369

W
wusongqing 已提交
370
**示例:**
Z
zengyawen 已提交
371

372
```js
W
wusongqing 已提交
373
audioPlayer.on('timeUpdate', (seekDoneTime) => {    //设置'timeUpdate'事件回调
374 375 376 377 378
    if (typeof (seekDoneTime) == 'undefined') {
        console.info('audio seek fail');
        return;
    }
    console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
Z
zengyawen 已提交
379
});
W
wusongqing 已提交
380
audioPlayer.seek(30000);    //seek到30000ms的位置
Z
zengyawen 已提交
381
```
Z
zengyawen 已提交
382

383
### setVolume<a name=audioplayer_setvolume></a>
Z
zengyawen 已提交
384

Z
zengyawen 已提交
385
setVolume(vol: number): void
Z
zengyawen 已提交
386

W
wusongqing 已提交
387
设置音量。
B
bird_j 已提交
388

Z
zengyawen 已提交
389 390
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
391
**参数:**
Z
zengyawen 已提交
392

W
wusongqing 已提交
393
| 参数名 | 类型   | 必填 | 说明                                                         |
394
| ------ | ------ | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
395
| vol    | number | 是   | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 |
Z
zengyawen 已提交
396

W
wusongqing 已提交
397
**示例:**
Z
zengyawen 已提交
398

399
```js
W
wusongqing 已提交
400
audioPlayer.on('volumeChange', () => {    //设置'volumeChange'事件回调
401
    console.log('audio volumeChange success');
Z
zengyawen 已提交
402
});
W
wusongqing 已提交
403
audioPlayer.setVolume(1);    //设置音量到100%
Z
zengyawen 已提交
404
```
Z
zengyawen 已提交
405

406
### release<a name=audioplayer_release></a>
Z
zengyawen 已提交
407

408
release(): void
Z
zengyawen 已提交
409

W
wusongqing 已提交
410
释放音频资源。
B
bird_j 已提交
411

Z
zengyawen 已提交
412 413
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
414
**示例:**
Z
zengyawen 已提交
415

416 417 418
```js
audioPlayer.release();
audioPlayer = undefined;
Z
zengyawen 已提交
419
```
Z
zengyawen 已提交
420

421
### getTrackDescription<sup>8+</sup><a name=audioplayer_gettrackdescription1></a>
Z
zengyawen 已提交
422

423
getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8)>>): void
Z
zengyawen 已提交
424

W
wusongqing 已提交
425
通过回调方式获取音频轨道信息。
426

Z
zengyawen 已提交
427 428
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
429
**参数:**
B
bird_j 已提交
430

W
wusongqing 已提交
431
| 参数名   | 类型                                                         | 必填 | 说明                       |
432
| -------- | ------------------------------------------------------------ | ---- | -------------------------- |
W
wusongqing 已提交
433
| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | 是   | 获取音频轨道信息回调方法。 |
Z
zengyawen 已提交
434

W
wusongqing 已提交
435
**示例:**
Z
zengyawen 已提交
436

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
```js
function printfDescription(obj) {
    for (let item in obj) {
        let property = obj[item];
        console.info('audio key is ' + item);
        console.info('audio value is ' + property);
    }
}

audioPlayer.getTrackDescription((error, arrlist) => {
    if (typeof (arrlist) != 'undefined') {
        for (let i = 0; i < arrlist.length; i++) {
            printfDescription(arrlist[i]);
        }
    } else {
        console.log(`audio getTrackDescription fail, error:${error.message}`);
    }
});
Z
zengyawen 已提交
455
```
456 457 458 459 460

### getTrackDescription<sup>8+</sup><a name=audioplayer_gettrackdescription2></a>

getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8)>>

W
wusongqing 已提交
461
通过Promise方式获取音频轨道信息。
B
bird_j 已提交
462

Z
zengyawen 已提交
463 464
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
465
**返回值:**
466

W
wusongqing 已提交
467
| 类型                                                   | 说明                            |
468
| ------------------------------------------------------ | ------------------------------- |
W
wusongqing 已提交
469
| Promise<Array<[MediaDescription](#mediadescription8)>> | 获取音频轨道信息Promise返回值。 |
470

W
wusongqing 已提交
471
**示例:**
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497

```js
function printfDescription(obj) {
    for (let item in obj) {
        let property = obj[item];
        console.info('audio key is ' + item);
        console.info('audio value is ' + property);
    }
}
function failureCallback(error) {
    console.info(`audio failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`audio catchCallback, error:${error.message}`);
}

await audioPlayer.getTrackDescription.then((arrlist) => {
    if (typeof (arrlist) != 'undefined') {
        arrayDescription = arrlist;
    } else {
        console.log('audio getTrackDescription fail');
    }
}, failureCallback).catch(catchCallback);
for (let i = 0; i < arrayDescription.length; i++) {
    printfDescription(arrayDescription[i]);
}
Z
zengyawen 已提交
498 499
```

500
### on('bufferingUpdate')<sup>8+</sup>
Z
zengyawen 已提交
501

502
on(type: 'bufferingUpdate', callback: (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void): void
Z
zengyawen 已提交
503

W
wusongqing 已提交
504
开始订阅音频缓存更新事件。
Z
zengyawen 已提交
505

Z
zengyawen 已提交
506 507
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
508
**参数:**
B
bird_j 已提交
509

W
wusongqing 已提交
510
| 参数名   | 类型                                                         | 必填 | 说明                                                         |
511
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
512 513
| type     | string                                                       | 是   | 音频缓存事件回调类型,支持的事件:'bufferingUpdate'。        |
| callback | (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void | 是   | 音频缓存事件回调方法。<br>[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 |
Z
zengyawen 已提交
514

W
wusongqing 已提交
515
**示例:**
Z
zengyawen 已提交
516

517 518 519 520 521
```js
audioPlayer.on('bufferingUpdate', (infoType, value) => {
    console.log('audio bufferingInfo type: ' + infoType);
    console.log('audio bufferingInfo value: ' + value);
});
Z
zengyawen 已提交
522
```
523 524 525 526 527

 ### on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')

on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void

W
wusongqing 已提交
528
开始订阅音频播放事件。
B
bird_j 已提交
529

Z
zengyawen 已提交
530 531
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
532
**参数:**
533

W
wusongqing 已提交
534
| 参数名   | 类型       | 必填 | 说明                                                         |
535
| -------- | ---------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
536 537
| type     | string     | 是   | 播放事件回调类型,支持的事件包括:'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'。<br>- 'play':完成[play()](#play)调用,音频开始播放,触发该事件。<br>- 'pause':完成[pause()](#pause)调用,音频暂停播放,触发该事件。<br>- 'stop':完成[stop()](#stop)调用,音频停止播放,触发该事件。<br>- 'reset':完成[reset()](#reset7)调用,播放器重置,触发该事件。<br>- 'dataLoad':完成音频数据加载后触发该事件,即src属性设置完成后触发该事件。<br>- 'finish':完成音频播放后触发该事件。<br>- 'volumeChange':完成[setVolume()](#setvolume)调用,播放音量改变后触发该事件。 |
| callback | () => void | 是   | 播放事件回调方法。                                           |
538

W
wusongqing 已提交
539
**示例:**
540 541

```js
W
wusongqing 已提交
542 543
let audioPlayer = media.createAudioPlayer();  //创建一个音频播放实例
audioPlayer.on('dataLoad', () => {            //设置'dataLoad'事件回调,src属性设置成功后,触发此回调
544
	console.info('audio set source success');
W
wusongqing 已提交
545
    audioPlayer.play();                       //开始播放,并触发'play'事件回调
546
});
W
wusongqing 已提交
547
audioPlayer.on('play', () => {                //设置'play'事件回调
548
	console.info('audio play success');
W
wusongqing 已提交
549
    audioPlayer.seek(30000);                  //调用seek方法,并触发'timeUpdate'事件回调
550
});
W
wusongqing 已提交
551
audioPlayer.on('pause', () => {               //设置'pause'事件回调
552
	console.info('audio pause success');
W
wusongqing 已提交
553
    audioPlayer.stop();                       //停止播放,并触发'stop'事件回调
554
});
W
wusongqing 已提交
555
audioPlayer.on('reset', () => {               //设置'reset'事件回调
556
	console.info('audio reset success');
W
wusongqing 已提交
557
    audioPlayer.release();                    //释放播放实例资源
558 559
    audioPlayer = undefined;
});
W
wusongqing 已提交
560
audioPlayer.on('timeUpdate', (seekDoneTime) => {  //设置'timeUpdate'事件回调
561 562 563 564 565
	if (typeof(seekDoneTime) == "undefined") {
        console.info('audio seek fail');
        return;
    }
    console.info('audio seek success, and seek time is ' + seekDoneTime);
W
wusongqing 已提交
566
    audioPlayer.setVolume(0.5);                //设置音量为50%,并触发'volumeChange'事件回调
567
});
W
wusongqing 已提交
568
audioPlayer.on('volumeChange', () => {         //设置'volumeChange'事件回调
569
	console.info('audio volumeChange success');
W
wusongqing 已提交
570
    audioPlayer.pause();                       //暂停播放,并触发'pause'事件回调
571
});
W
wusongqing 已提交
572
audioPlayer.on('finish', () => {               //设置'finish'事件回调
573
	console.info('audio play finish');
W
wusongqing 已提交
574
    audioPlayer.stop();                        //停止播放,并触发'stop'事件回调
575
});
W
wusongqing 已提交
576
audioPlayer.on('error', (error) => {           //设置'error'事件回调
577 578 579
	console.info(`audio error called, errName is ${error.name}`);
    console.info(`audio error called, errCode is ${error.code}`);
    console.info(`audio error called, errMessage is ${error.message}`);
Z
zengyawen 已提交
580
});
Z
zengyawen 已提交
581 582 583 584 585 586 587 588 589 590 591 592 593

// 用户选择视频设置fd(本地播放)
let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => {
   fdPath = fdPath + '' + fdNumber;
   console.info('open fd sucess fd is' + fdPath);
}, (err) => {
   console.info('open fd failed err is' + err);
}),catch((err) => {
   console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath;  //设置src属性,并触发'dataLoad'事件回调
Z
zengyawen 已提交
594 595 596 597 598
```

### on('timeUpdate')

on(type: 'timeUpdate', callback: Callback\<number>): void
Z
zengyawen 已提交
599

W
wusongqing 已提交
600
开始订阅音频播放[seek()](#seek)时间更新事件。
Z
zengyawen 已提交
601

Z
zengyawen 已提交
602 603
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
604
**参数:**
B
bird_j 已提交
605

W
wusongqing 已提交
606
| 参数名   | 类型              | 必填 | 说明                                                         |
607
| -------- | ----------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
608 609
| type     | string            | 是   | 播放事件回调类型,支持的事件包括:'timeUpdate'。<br>- 'timeUpdate':[seek()](#seek)调用完成,触发该事件。 |
| callback | Callback\<number> | 是   | 播放事件回调方法。回调方法入参为成功seek的时间。             |
Z
zengyawen 已提交
610

W
wusongqing 已提交
611
**示例:**
Z
zengyawen 已提交
612

613
```js
W
wusongqing 已提交
614
audioPlayer.on('timeUpdate', (seekDoneTime) => {    //设置'timeUpdate'事件回调
615 616 617 618 619
    if (typeof (seekDoneTime) == 'undefined') {
        console.info('audio seek fail');
        return;
    }
    console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
Z
zengyawen 已提交
620
});
W
wusongqing 已提交
621
audioPlayer.seek(30000);    //seek到30000ms的位置
Z
zengyawen 已提交
622 623 624 625 626
```

### on('error')

on(type: 'error', callback: ErrorCallback): void
Z
zengyawen 已提交
627

W
wusongqing 已提交
628
开始订阅音频播放错误事件。
B
bird_j 已提交
629

Z
zengyawen 已提交
630 631
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
632
**参数:**
Z
zengyawen 已提交
633

W
wusongqing 已提交
634
| 参数名   | 类型          | 必填 | 说明                                                         |
635
| -------- | ------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
636 637
| type     | string        | 是   | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':音频播放中发生错误,触发该事件。 |
| callback | ErrorCallback | 是   | 播放错误事件回调方法。                                       |
Z
zengyawen 已提交
638

W
wusongqing 已提交
639
**示例:**
Z
zengyawen 已提交
640

641
```js
W
wusongqing 已提交
642 643 644 645
audioPlayer.on('error', (error) => {      //设置'error'事件回调
	console.info(`audio error called, errName is ${error.name}`);      //打印错误类型名称
    console.info(`audio error called, errCode is ${error.code}`);      //打印错误码
    console.info(`audio error called, errMessage is ${error.message}`);//打印错误类型详细描述
Z
zengyawen 已提交
646
});
W
wusongqing 已提交
647
audioPlayer.setVolume(3);  //设置volume为无效值,触发'error'事件
Z
zengyawen 已提交
648 649 650
```

## AudioState
Z
zengyawen 已提交
651

W
wusongqing 已提交
652
音频播放的状态机。可通过state属性获取当前状态。
653

Z
zengyawen 已提交
654 655
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.AudioPlayer。

W
wusongqing 已提交
656 657 658 659 660 661 662
| 名称               | 类型   | 描述           |
| ------------------ | ------ | -------------- |
| idle               | string | 音频播放空闲。 |
| playing            | string | 音频正在播放。 |
| paused             | string | 音频暂停播放。 |
| stopped            | string | 音频播放停止。 |
| error<sup>8+</sup> | string | 错误状态。     |
663

664 665
## VideoPlayer<sup>8+</sup>

W
wusongqing 已提交
666
视频播放管理类,用于管理和播放视频媒体。在调用VideoPlayer的方法前,需要先通过[createVideoPlayer()](#media.createvideoplayer8)构建一个[VideoPlayer](#videoplayer8)实例。
667

W
wusongqing 已提交
668
视频播放demo可参考:[视频播放开发指导](../../media/video-playback.md)
669

Z
zengyawen 已提交
670
### 属性<a name=videoplayer_属性></a>
671

Z
zengyawen 已提交
672 673 674 675 676 677 678 679 680 681 682
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoPlayer。

| 名称                     | 类型                               | 可读 | 可写 | 说明                                                         |
| ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| url<sup>8+</sup>         | string                             | 是   | 是   | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。<br>**支持路径示例**<br>1. fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>**注意事项**<br>使用媒体素材需要获取读权限,否则无法正常播放。 |
| loop<sup>8+</sup>        | boolean                            | 是   | 是   | 视频循环播放属性,设置为'true'表示循环播放。                 |
| currentTime<sup>8+</sup> | number                             | 是   | 否   | 视频的当前播放位置。                                         |
| duration<sup>8+</sup>    | number                             | 是   | 否   | 视频时长,返回-1表示直播模式。                               |
| state<sup>8+</sup>       | [VideoPlayState](#videoplaystate8) | 是   | 否   | 视频播放的状态。                                             |
| width<sup>8+</sup>       | number                             | 是   | 否   | 视频宽。                                                     |
| height<sup>8+</sup>      | number                             | 是   | 否   | 视频高。                                                     |
683 684 685 686 687

### setDisplaySurface<sup>8+</sup>

setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void

W
wusongqing 已提交
688
通过回调方式设置SurfaceId。
B
bird_j 已提交
689

Z
zengyawen 已提交
690 691
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
692
**参数:**
693

W
wusongqing 已提交
694
| 参数名    | 类型     | 必填 | 说明                      |
695
| --------- | -------- | ---- | ------------------------- |
W
wusongqing 已提交
696 697
| surfaceId | string   | 是   | SurfaceId                 |
| callback  | function | 是   | 设置SurfaceId的回调方法。 |
698

W
wusongqing 已提交
699
**示例:**
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

```js
videoPlayer.setDisplaySurface(surfaceId, (err) => {
	if (typeof (err) == 'undefined') {
		console.info('setDisplaySurface success!');
	} else {
        console.info('setDisplaySurface fail!');
    }
});
```

### setDisplaySurface<sup>8+</sup>

setDisplaySurface(surfaceId: string): Promise\<void>

W
wusongqing 已提交
715
通过Promise方式设置SurfaceId。
716

Z
zengyawen 已提交
717 718
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
719
**参数:**
B
bird_j 已提交
720

W
wusongqing 已提交
721
| 参数名    | 类型   | 必填 | 说明      |
722
| --------- | ------ | ---- | --------- |
W
wusongqing 已提交
723
| surfaceId | string | 是   | SurfaceId |
724

W
wusongqing 已提交
725
**返回值:**
726

W
wusongqing 已提交
727
| 类型          | 说明                           |
728
| ------------- | ------------------------------ |
W
wusongqing 已提交
729
| Promise<void> | 设置SurfaceId的Promise返回值。 |
730

W
wusongqing 已提交
731
**示例:**
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setDisplaySurface(surfaceId).then(() => {
    console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback);
```

### prepare<sup>8+</sup>

prepare(callback: AsyncCallback\<void>): void

W
wusongqing 已提交
749
通过回调方式准备播放视频。
B
bird_j 已提交
750

Z
zengyawen 已提交
751 752
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
753
**参数:**
754

W
wusongqing 已提交
755
| 参数名   | 类型     | 必填 | 说明                     |
756
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
757
| callback | function | 是   | 准备播放视频的回调方法。 |
758

W
wusongqing 已提交
759
**示例:**
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774

```js
videoPlayer.prepare((err) => {
	if (typeof (err) == 'undefined') {
		console.info('prepare success!');
	} else {
        console.info('prepare fail!');
    }
});
```

### prepare<sup>8+</sup>

prepare(): Promise\<void>

W
wusongqing 已提交
775
通过Promise方式准备播放视频。
776

Z
zengyawen 已提交
777 778
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
779
**返回值:**
B
bird_j 已提交
780

W
wusongqing 已提交
781
| 类型           | 说明                          |
782
| -------------- | ----------------------------- |
W
wusongqing 已提交
783
| Promise\<void> | 准备播放视频的Promise返回值。 |
784

W
wusongqing 已提交
785
**示例:**
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.prepare().then(() => {
    console.info('prepare success');
}, failureCallback).catch(catchCallback);
```

### play<sup>8+</sup>

play(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
803
通过回调方式开始播放视频。
B
bird_j 已提交
804

Z
zengyawen 已提交
805 806
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
807
**参数:**
808

W
wusongqing 已提交
809
| 参数名   | 类型     | 必填 | 说明                     |
810
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
811
| callback | function | 是   | 开始播放视频的回调方法。 |
812

W
wusongqing 已提交
813
**示例:**
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828

```js
videoPlayer.play((err) => {
	if (typeof (err) == 'undefined') {
		console.info('play success!');
	} else {
        console.info('play fail!');
    }
});
```

### play<sup>8+</sup>

play(): Promise\<void>;

W
wusongqing 已提交
829
通过Promise方式开始播放视频。
830

Z
zengyawen 已提交
831 832
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
833
**返回值:**
B
bird_j 已提交
834

W
wusongqing 已提交
835
| 类型           | 说明                          |
836
| -------------- | ----------------------------- |
W
wusongqing 已提交
837
| Promise\<void> | 开始播放视频的Promise返回值。 |
838

W
wusongqing 已提交
839
**示例:**
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.play().then(() => {
    console.info('play success');
}, failureCallback).catch(catchCallback);
```

### pause<sup>8+</sup>

pause(callback: AsyncCallback\<void>): void

W
wusongqing 已提交
857
通过回调方式暂停播放视频。
B
bird_j 已提交
858

Z
zengyawen 已提交
859 860
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
861
**参数:**
862

W
wusongqing 已提交
863
| 参数名   | 类型     | 必填 | 说明                     |
864
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
865
| callback | function | 是   | 暂停播放视频的回调方法。 |
866

W
wusongqing 已提交
867
**示例:**
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882

```js
videoPlayer.pause((err) => {
	if (typeof (err) == 'undefined') {
		console.info('pause success!');
	} else {
        console.info('pause fail!');
    }
});
```

### pause<sup>8+</sup>

pause(): Promise\<void>

W
wusongqing 已提交
883
通过Promise方式暂停播放视频。
884

Z
zengyawen 已提交
885 886
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
887
**返回值:**
B
bird_j 已提交
888

W
wusongqing 已提交
889
| 类型           | 说明                          |
890
| -------------- | ----------------------------- |
W
wusongqing 已提交
891
| Promise\<void> | 暂停播放视频的Promise返回值。 |
892

W
wusongqing 已提交
893
**示例:**
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.pause().then(() => {
    console.info('pause success');
}, failureCallback).catch(catchCallback);
```

### stop<sup>8+</sup>

stop(callback: AsyncCallback\<void>): void

W
wusongqing 已提交
911
通过回调方式停止播放视频。
B
bird_j 已提交
912

Z
zengyawen 已提交
913 914
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
915
**参数:**
916

W
wusongqing 已提交
917
| 参数名   | 类型     | 必填 | 说明                     |
918
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
919
| callback | function | 是   | 停止播放视频的回调方法。 |
920

W
wusongqing 已提交
921
**示例:**
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936

```js
videoPlayer.stop((err) => {
	if (typeof (err) == 'undefined') {
		console.info('stop success!');
	} else {
        console.info('stop fail!');
    }
});
```

### stop<sup>8+</sup>

stop(): Promise\<void>

W
wusongqing 已提交
937
通过Promise方式停止播放视频。
B
bird_j 已提交
938

Z
zengyawen 已提交
939 940
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
941
**返回值:**
942

W
wusongqing 已提交
943
| 类型           | 说明                          |
944
| -------------- | ----------------------------- |
W
wusongqing 已提交
945
| Promise\<void> | 停止播放视频的Promise返回值。 |
946

W
wusongqing 已提交
947
**示例:**
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.stop().then(() => {
    console.info('stop success');
}, failureCallback).catch(catchCallback);
```

### reset<sup>8+</sup>

reset(callback: AsyncCallback\<void>): void

W
wusongqing 已提交
965
通过回调方式切换播放视频。
966

Z
zengyawen 已提交
967 968
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
969
**参数:**
B
bird_j 已提交
970

W
wusongqing 已提交
971
| 参数名   | 类型     | 必填 | 说明                     |
972
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
973
| callback | function | 是   | 切换播放视频的回调方法。 |
974

W
wusongqing 已提交
975
**示例:**
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990

```js
videoPlayer.reset((err) => {
	if (typeof (err) == 'undefined') {
		console.info('reset success!');
	} else {
        console.info('reset fail!');
    }
});
```

### reset<sup>8+</sup>

reset(): Promise\<void>

W
wusongqing 已提交
991
通过Promise方式切换播放视频。
B
bird_j 已提交
992

Z
zengyawen 已提交
993 994
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
995
**返回值:**
996

W
wusongqing 已提交
997
| 类型           | 说明                          |
998
| -------------- | ----------------------------- |
W
wusongqing 已提交
999
| Promise\<void> | 切换播放视频的Promise返回值。 |
1000

W
wusongqing 已提交
1001
**示例:**
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.reset().then(() => {
    console.info('reset success');
}, failureCallback).catch(catchCallback);
```

### seek<sup>8+</sup>

seek(timeMs: number, callback: AsyncCallback\<number>): void

W
wusongqing 已提交
1019
通过回调方式跳转到指定播放位置,默认跳转到指定时间点的下一个关键帧。
1020

Z
zengyawen 已提交
1021 1022
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1023
**参数:**
B
bird_j 已提交
1024

W
wusongqing 已提交
1025
| 参数名   | 类型     | 必填 | 说明                           |
1026
| -------- | -------- | ---- | ------------------------------ |
W
wusongqing 已提交
1027 1028
| timeMs   | number   | 是   | 指定的跳转时间节点,单位毫秒。 |
| callback | function | 是   | 跳转到指定播放位置的回调方法。 |
1029

W
wusongqing 已提交
1030
**示例:**
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045

```js
videoPlayer.seek((seekTime, err) => {
	if (typeof (err) == 'undefined') {
		console.info('seek success!');
	} else {
        console.info('seek fail!');
    }
});
```

### seek<sup>8+</sup>

seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void

W
wusongqing 已提交
1046
通过回调方式跳转到指定播放位置。
B
bird_j 已提交
1047

Z
zengyawen 已提交
1048 1049
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1050
**参数:**
1051

W
wusongqing 已提交
1052
| 参数名   | 类型     | 必填 | 说明                                     |
1053
| -------- | -------- | ---- | ---------------------------------------- |
W
wusongqing 已提交
1054 1055 1056
| timeMs   | number   | 是   | 指定的跳转时间节点,单位毫秒。           |
| mode     | SeekMode | 是   | 跳转模式,具体见[SeekMode](#seekmode8)。 |
| callback | function | 是   | 跳转到指定播放位置的回调方法。           |
1057

W
wusongqing 已提交
1058
**示例:**
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073

```js
videoPlayer.seek((seekTime, seekMode, err) => {
	if (typeof (err) == 'undefined') {
		console.info('seek success!');
	} else {
        console.info('seek fail!');
    }
});
```

### seek<sup>8+</sup>

seek(timeMs: number, mode?:SeekMode): Promise\<number>

W
wusongqing 已提交
1074
通过Promise方式跳转到指定播放位置,如果没有设置mode则跳转到指定时间点的下一个关键帧。
1075

Z
zengyawen 已提交
1076 1077
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1078
**参数:**
B
bird_j 已提交
1079

W
wusongqing 已提交
1080
| 参数名 | 类型     | 必填 | 说明                                   |
1081
| ------ | -------- | ---- | -------------------------------------- |
W
wusongqing 已提交
1082 1083
| timeMs | number   | 是   | 指定的跳转时间节点,单位毫秒。         |
| mode   | SeekMode | 否   | 跳转模式,具体见[SeekMode](#seekmode8) |
1084

W
wusongqing 已提交
1085
**返回值:**
1086

W
wusongqing 已提交
1087
| 类型           | 说明                                |
1088
| -------------- | ----------------------------------- |
W
wusongqing 已提交
1089
| Promise\<void> | 跳转到指定播放位置的Promise返回值。 |
1090

W
wusongqing 已提交
1091
**示例:**
1092 1093 1094 1095 1096 1097 1098 1099

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
W
wusongqing 已提交
1100
await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
    console.info('seek success');
}, failureCallback).catch(catchCallback);

await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => {
    console.info('seek success');
}, failureCallback).catch(catchCallback);
```

### setVolume<sup>8+</sup>

setVolume(vol: number, callback: AsyncCallback\<void>): void

W
wusongqing 已提交
1113
通过回调方式设置音量。
B
bird_j 已提交
1114

Z
zengyawen 已提交
1115 1116
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1117
**参数:**
1118

W
wusongqing 已提交
1119
| 参数名   | 类型     | 必填 | 说明                                                         |
1120
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1121 1122
| vol      | number   | 是   | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 |
| callback | function | 是   | 设置音量的回调方法。                                         |
1123

W
wusongqing 已提交
1124
**示例:**
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139

```js
videoPlayer.setVolume((vol, err) => {
	if (typeof (err) == 'undefined') {
		console.info('setVolume success!');
	} else {
        console.info('setVolume fail!');
    }
});
```

### setVolume<sup>8+</sup>

setVolume(vol: number): Promise\<void>

W
wusongqing 已提交
1140
通过Promise方式设置音量。
1141

Z
zengyawen 已提交
1142 1143
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1144
**参数:**
B
bird_j 已提交
1145

W
wusongqing 已提交
1146
| 参数名 | 类型   | 必填 | 说明                                                         |
1147
| ------ | ------ | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1148
| vol    | number | 是   | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 |
1149

W
wusongqing 已提交
1150
**返回值:**
1151

W
wusongqing 已提交
1152
| 类型           | 说明                      |
1153
| -------------- | ------------------------- |
W
wusongqing 已提交
1154
| Promise\<void> | 设置音量的Promise返回值。 |
1155

W
wusongqing 已提交
1156
**示例:**
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setVolume(vol).then() => {
    console.info('setVolume success');
}, failureCallback).catch(catchCallback);
```

### release<sup>8+</sup>

release(callback: AsyncCallback\<void>): void

W
wusongqing 已提交
1174
通过回调方式释放视频资源。
B
bird_j 已提交
1175

Z
zengyawen 已提交
1176 1177
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1178
**参数:**
1179

W
wusongqing 已提交
1180
| 参数名   | 类型     | 必填 | 说明                     |
1181
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
1182
| callback | function | 是   | 释放视频资源的回调方法。 |
1183

W
wusongqing 已提交
1184
**示例:**
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199

```js
videoPlayer.release((err) => {
	if (typeof (err) == 'undefined') {
		console.info('release success!');
	} else {
        console.info('release fail!');
    }
});
```

### release<sup>8+</sup>

release(): Promise\<void>

W
wusongqing 已提交
1200
通过Promise方式释放视频资源。
B
bird_j 已提交
1201

Z
zengyawen 已提交
1202 1203
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1204
**返回值:**
1205

W
wusongqing 已提交
1206
| 类型           | 说明                          |
1207
| -------------- | ----------------------------- |
W
wusongqing 已提交
1208
| Promise\<void> | 释放视频资源的Promise返回值。 |
1209

W
wusongqing 已提交
1210
**示例:**
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.release().then() => {
    console.info('release success');
}, failureCallback).catch(catchCallback);
```

### getTrackDescription<sup>8+</sup>

getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8>>)>>): void

W
wusongqing 已提交
1228
通过回调方式获取视频轨道信息。
1229

Z
zengyawen 已提交
1230 1231
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1232
**参数:**
B
bird_j 已提交
1233

W
wusongqing 已提交
1234
| 参数名   | 类型     | 必填 | 说明                       |
1235
| -------- | -------- | ---- | -------------------------- |
W
wusongqing 已提交
1236
| callback | function | 是   | 获取视频轨道信息回调方法。 |
1237

W
wusongqing 已提交
1238
**示例:**
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263

```js
function printfDescription(obj) {
    for (let item in obj) {
        let property = obj[item];
        console.info('video key is ' + item);
        console.info('video value is ' + property);
    }
}

videoPlayer.getTrackDescription((error, arrlist) => {
    if (typeof (arrlist) != 'undefined') {
        for (let i = 0; i < arrlist.length; i++) {
            printfDescription(arrlist[i]);
        }
    } else {
        console.log(`video getTrackDescription fail, error:${error.message}`);
    }
});
```

### getTrackDescription<sup>8+</sup>

getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8>>)>>

W
wusongqing 已提交
1264
通过Promise方式获取视频轨道信息。
B
bird_j 已提交
1265

Z
zengyawen 已提交
1266 1267
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1268
**返回值:**
1269

W
wusongqing 已提交
1270
| 类型                                                     | 说明                            |
1271
| -------------------------------------------------------- | ------------------------------- |
W
wusongqing 已提交
1272
| Promise<Array<[MediaDescription](#mediadescription8>>)>> | 获取视频轨道信息Promise返回值。 |
1273

W
wusongqing 已提交
1274
**示例:**
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307

```js
function printfDescription(obj) {
    for (let item in obj) {
        let property = obj[item];
        console.info('video key is ' + item);
        console.info('video value is ' + property);
    }
}
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}

let arrayDescription;
await videoPlayer.getTrackDescription().then((arrlist) => {
    if (typeof (arrlist) != 'undefined') {
        arrayDescription = arrlist;
    } else {
        console.log('video getTrackDescription fail');
    }
}, failureCallback).catch(catchCallback);
for (let i = 0; i < arrayDescription.length; i++) {
    printfDescription(arrayDescription[i]);
}
```

### setSpeed<sup>8+</sup>

setSpeed(speed:number, callback: AsyncCallback\<number>): void

W
wusongqing 已提交
1308
通过回调方式设置播放速度。
1309

Z
zengyawen 已提交
1310 1311
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1312
**参数:**
B
bird_j 已提交
1313

W
wusongqing 已提交
1314
| 参数名   | 类型     | 必填 | 说明                                                       |
1315
| -------- | -------- | ---- | ---------------------------------------------------------- |
W
wusongqing 已提交
1316 1317
| speed    | number   | 是   | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)。 |
| callback | function | 是   | 设置播放速度的回调方法。                                   |
1318

W
wusongqing 已提交
1319
**示例:**
1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334

```js
videoPlayer.setSpeed((speed:number, err) => {
	if (typeof (err) == 'undefined') {
		console.info('setSpeed success!');
	} else {
        console.info('setSpeed fail!');
    }
});
```

### setSpeed<sup>8+</sup>

setSpeed(speed:number): Promise\<number>

W
wusongqing 已提交
1335
通过Promise方式设置播放速度。
B
bird_j 已提交
1336

Z
zengyawen 已提交
1337 1338
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1339
**参数:**
1340

W
wusongqing 已提交
1341
| 参数名 | 类型   | 必填 | 说明                                                       |
1342
| ------ | ------ | ---- | ---------------------------------------------------------- |
W
wusongqing 已提交
1343
| speed  | number | 是   | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)。 |
1344

W
wusongqing 已提交
1345
**示例:**
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
await videoPlayer.setSpeed(speed).then() => {
    console.info('setSpeed success');
}, failureCallback).catch(catchCallback);
```

### on('playbackCompleted')<sup>8+</sup>

on(type: 'playbackCompleted', callback: Callback\<void>): void

W
wusongqing 已提交
1363
开始监听视频播放完成事件。
1364

Z
zengyawen 已提交
1365 1366
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1367
**参数:**
B
bird_j 已提交
1368

W
wusongqing 已提交
1369
| 参数名   | 类型     | 必填 | 说明                                                        |
1370
| -------- | -------- | ---- | ----------------------------------------------------------- |
W
wusongqing 已提交
1371 1372
| type     | string   | 是   | 视频播放完成事件回调类型,支持的事件:'playbackCompleted'。 |
| callback | function | 是   | 视频播放完成事件回调方法。                                  |
1373

W
wusongqing 已提交
1374
**示例:**
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385

```js
videoPlayer.on('playbackCompleted', () => {
	console.info('playbackCompleted success!');
});
```

### on('bufferingUpdate')<sup>8+</sup>

on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void

W
wusongqing 已提交
1386
开始监听视频缓存更新事件。
B
bird_j 已提交
1387

Z
zengyawen 已提交
1388 1389
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1390
**参数:**
1391

W
wusongqing 已提交
1392
| 参数名   | 类型     | 必填 | 说明                                                         |
1393
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1394 1395
| type     | string   | 是   | 视频缓存事件回调类型,支持的事件:'bufferingUpdate'。        |
| callback | function | 是   | 视频缓存事件回调方法。<br>[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 |
1396

W
wusongqing 已提交
1397
**示例:**
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409

```js
videoPlayer.on('bufferingUpdate', (infoType, value) => {
    console.log('video bufferingInfo type: ' + infoType);
    console.log('video bufferingInfo value: ' + value);
});
```

### on('startRenderFrame')<sup>8+</sup>

on(type: 'startRenderFrame', callback: Callback\<void>): void

W
wusongqing 已提交
1410
开始监听视频播放首帧送显上报事件。
1411

Z
zengyawen 已提交
1412 1413
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1414
**参数:**
B
bird_j 已提交
1415

W
wusongqing 已提交
1416
| 参数名   | 类型     | 必填 | 说明                                                         |
1417
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1418 1419
| type     | string   | 是   | 视频播放首帧送显上报事件回调类型,支持的事件:'startRenderFrame'。 |
| callback | function | 是   | 视频播放首帧送显上报事件回调方法。                           |
1420

W
wusongqing 已提交
1421
**示例:**
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432

```js
videoPlayer.on('startRenderFrame', () => {
	console.info('startRenderFrame success!');
});
```

### on('videoSizeChanged')<sup>8+</sup>

on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void

W
wusongqing 已提交
1433
开始监听视频播放宽高变化事件。
B
bird_j 已提交
1434

Z
zengyawen 已提交
1435 1436
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1437
**参数:**
1438

W
wusongqing 已提交
1439
| 参数名   | 类型     | 必填 | 说明                                                         |
1440
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1441 1442
| type     | string   | 是   | 视频播放宽高变化事件回调类型,支持的事件:'videoSizeChanged'。 |
| callback | function | 是   | 视频播放宽高变化事件回调方法,width表示宽,height表示高。    |
1443

W
wusongqing 已提交
1444
**示例:**
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456

```js
videoPlayer.on('videoSizeChanged', (width, height) => {
    console.log('video width is: ' + width);
    console.log('video height is: ' + height);
});
```

### on('error')<sup>8+</sup>

on(type: 'error', callback: ErrorCallback): void

W
wusongqing 已提交
1457
开始监听视频播放错误事件。
B
bird_j 已提交
1458

Z
zengyawen 已提交
1459 1460
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
1461
**参数:**
1462

W
wusongqing 已提交
1463
| 参数名   | 类型     | 必填 | 说明                                                         |
1464
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1465 1466
| type     | string   | 是   | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':视频播放中发生错误,触发该事件。 |
| callback | function | 是   | 播放错误事件回调方法。                                       |
1467

W
wusongqing 已提交
1468
**示例:**
1469 1470

```js
W
wusongqing 已提交
1471 1472 1473 1474
videoPlayer.on('error', (error) => {      // 设置'error'事件回调
	console.info(`video error called, errName is ${error.name}`);      // 打印错误类型名称
    console.info(`video error called, errCode is ${error.code}`);      // 打印错误码
    console.info(`video error called, errMessage is ${error.message}`);// 打印错误类型详细描述
1475
});
W
wusongqing 已提交
1476
videoPlayer.setVolume(3);  //设置volume为无效值,触发'error'事件
1477 1478 1479 1480
```

## VideoPlayState<sup>8+</sup>

W
wusongqing 已提交
1481
视频播放的状态机,可通过state属性获取当前状态。
1482

Z
zengyawen 已提交
1483 1484
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoPlayer。

W
wusongqing 已提交
1485 1486 1487 1488 1489 1490 1491 1492
| 名称     | 类型   | 描述           |
| -------- | ------ | -------------- |
| idle     | string | 视频播放空闲。 |
| prepared | string | 视频播放准备。 |
| playing  | string | 视频正在播放。 |
| paused   | string | 视频暂停播放。 |
| stopped  | string | 视频播放停止。 |
| error    | string | 错误状态。     |
1493 1494 1495

## SeekMode<sup>8+</sup>

W
wusongqing 已提交
1496
视频播放的Seek模式枚举,可通过seek方法作为参数传递下去。
1497

Z
zengyawen 已提交
1498 1499 1500 1501 1502 1503
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。

| 名称           | 值   | 描述                                                         |
| -------------- | ---- | ------------------------------------------------------------ |
| SEEK_NEXT_SYNC | 0    | 表示跳转到指定时间点的下一个关键帧,建议向后快进的时候用这个枚举值。 |
| SEEK_PREV_SYNC | 1    | 表示跳转到指定时间点的上一个关键帧,建议向前快进的时候用这个枚举值。 |
1504 1505 1506

## PlaybackSpeed<sup>8+</sup>

W
wusongqing 已提交
1507
视频播放的倍速枚举,可通过setSpeed方法作为参数传递下去。
1508

Z
zengyawen 已提交
1509 1510
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoPlayer。

W
wusongqing 已提交
1511 1512 1513 1514 1515 1516 1517
| 名称                 | 值   | 描述                           |
| -------------------- | ---- | ------------------------------ |
| SPEED_FORWARD_0_75_X | 0    | 表示视频播放正常播速的0.75倍。 |
| SPEED_FORWARD_1_00_X | 1    | 表示视频播放正常播速。         |
| SPEED_FORWARD_1_25_X | 2    | 表示视频播放正常播速的1.25倍。 |
| SPEED_FORWARD_1_75_X | 3    | 表示视频播放正常播速的1.75倍。 |
| SPEED_FORWARD_2_00_X | 4    | 表示视频播放正常播速的2.00倍。 |
1518

1519 1520 1521
## MediaDescription<sup>8+</sup>

### [key : string] : any
Z
zengyawen 已提交
1522

Z
zengyawen 已提交
1523 1524 1525
通过key-value方式获取媒体信息。

**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。
1526

W
wusongqing 已提交
1527
| 名称  | 类型   | 说明                                                         |
1528
| ----- | ------ | ------------------------------------------------------------ |
W
wusongqing 已提交
1529 1530
| key   | string | 通过key值获取对应的value。key值具体可见[MediaDescriptionKey](#mediadescriptionkey8)。 |
| value | any    | 对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey](#mediadescriptionkey8)的描述信息。 |
1531

W
wusongqing 已提交
1532
**示例:**
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543

```js
function printfItemDescription(obj, key) {
    let property = obj[key];
    console.info('audio key is ' + key);
    console.info('audio value is ' + property);
}

audioPlayer.getTrackDescription((error, arrlist) => {
    if (typeof (arrlist) != 'undefined') {
        for (let i = 0; i < arrlist.length; i++) {
W
wusongqing 已提交
1544
            printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE);  //打印出每条轨道MD_KEY_TRACK_TYPE的值
1545 1546 1547 1548 1549 1550
        }
    } else {
        console.log(`audio getTrackDescription fail, error:${error.message}`);
    }
});
```
Z
zengyawen 已提交
1551 1552 1553

## AudioRecorder

Z
zengyawen 已提交
1554
音频录制管理类,用于录制音频媒体。在调用AudioRecorder的方法前,需要先通过[createAudioRecorder()](#media.createaudiorecorder) 构建一个[AudioRecorder](#audiorecorder)实例。
Z
zengyawen 已提交
1555

W
wusongqing 已提交
1556
音频录制demo可参考:[音频录制开发指导](../../media/audio-recorder.md)
1557 1558

### prepare<a name=audiorecorder_prepare></a>
Z
zengyawen 已提交
1559 1560 1561

prepare(config: AudioRecorderConfig): void

W
wusongqing 已提交
1562
录音准备。
Z
zengyawen 已提交
1563

Z
zengyawen 已提交
1564 1565 1566 1567
**需要权限:** ohos.permission.MICROPHONE

**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1568
**参数:**
B
bird_j 已提交
1569

W
wusongqing 已提交
1570
| 参数名 | 类型                                        | 必填 | 说明                                                         |
Z
zengyawen 已提交
1571
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1572
| config | [AudioRecorderConfig](#audiorecorderconfig) | 是   | 配置录音的相关参数,包括音频输出URI、[编码格式](#audioencoder)、采样率、声道数、[输出格式](#audiooutputformat)等。 |
Z
zengyawen 已提交
1573

W
wusongqing 已提交
1574
**示例:**
Z
zengyawen 已提交
1575

1576
```js
Z
zengyawen 已提交
1577
let audioRecorderConfig = {
1578
    audioEncoder : media.AudioEncoder.AAC_LC,
Z
zengyawen 已提交
1579 1580 1581
    audioEncodeBitRate : 22050,
    audioSampleRate : 22050,
    numberOfChannels : 2,
1582
    format : media.AudioOutputFormat.AAC_ADTS,
Z
zengyawen 已提交
1583
    uri : 'fd://1',       // 文件需先由调用者创建,并给予适当的权限
1584
    location : { latitude : 30, longitude : 130},
Z
zengyawen 已提交
1585
}
W
wusongqing 已提交
1586
audioRecorder.on('prepare', () => {    //设置'prepare'事件回调
1587 1588
    console.log('prepare success');
});
B
bird_j 已提交
1589
audioRecorder.prepare(audioRecorderConfig);
Z
zengyawen 已提交
1590 1591 1592
```


1593
### start<a name=audiorecorder_start></a>
Z
zengyawen 已提交
1594 1595 1596

start(): void

W
wusongqing 已提交
1597
开始录制,需在[prepare](#audiorecorder_on)事件成功触发后,才能调用start方法。
B
bird_j 已提交
1598

Z
zengyawen 已提交
1599 1600
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1601
**示例:**
Z
zengyawen 已提交
1602

1603
```js
W
wusongqing 已提交
1604
audioRecorder.on('start', () => {    //设置'start'事件回调
1605 1606 1607
    console.log('audio recorder start success');
});
audioRecorder.start();
Z
zengyawen 已提交
1608
```
1609 1610 1611 1612 1613

### pause<a name=audiorecorder_pause></a>

pause():void

W
wusongqing 已提交
1614
暂停录制,需要在[start](#audiorecorder_on)事件成功触发后,才能调用pause方法。
1615

Z
zengyawen 已提交
1616 1617
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1618
**示例:**
1619 1620

```js
W
wusongqing 已提交
1621
audioRecorder.on('pause', () => {    //设置'pause'事件回调
1622 1623 1624 1625 1626 1627 1628 1629 1630
    console.log('audio recorder pause success');
});
audioRecorder.pause();
```

### resume<a name=audiorecorder_resume></a>

resume():void

W
wusongqing 已提交
1631
暂停录制,需要在[pause](#audiorecorder_on)事件成功触发后,才能调用resume方法。
B
bird_j 已提交
1632

Z
zengyawen 已提交
1633 1634
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1635
**示例:**
1636 1637

```js
W
wusongqing 已提交
1638
audioRecorder.on('resume', () => {    //设置'resume'事件回调
1639 1640 1641
    console.log('audio recorder resume success');
});
audioRecorder.resume();
Z
zengyawen 已提交
1642 1643
```

1644
### stop<a name=audiorecorder_stop></a>
Z
zengyawen 已提交
1645 1646 1647

stop(): void

W
wusongqing 已提交
1648
停止录音。
Z
zengyawen 已提交
1649

Z
zengyawen 已提交
1650 1651
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1652
**示例:**
Z
zengyawen 已提交
1653

1654
```js
W
wusongqing 已提交
1655
audioRecorder.on('stop', () => {    //设置'stop'事件回调
1656 1657 1658
    console.log('audio recorder stop success');
});
audioRecorder.stop();
Z
zengyawen 已提交
1659 1660
```

1661
### release<a name=audiorecorder_release></a>
Z
zengyawen 已提交
1662 1663 1664

release(): void

W
wusongqing 已提交
1665
释放录音资源。
B
bird_j 已提交
1666

Z
zengyawen 已提交
1667 1668
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1669
**示例:**
Z
zengyawen 已提交
1670

1671
```js
W
wusongqing 已提交
1672
audioRecorder.on('release', () => {    //设置'release'事件回调
B
bird_j 已提交
1673 1674
    console.log('audio recorder release success');
});
1675 1676
audioRecorder.release();
audioRecorder = undefined;
Z
zengyawen 已提交
1677 1678
```

1679
### reset<a name=audiorecorder_reset></a>
Z
zengyawen 已提交
1680 1681 1682

reset(): void

W
wusongqing 已提交
1683
重置录音。
Z
zengyawen 已提交
1684

W
wusongqing 已提交
1685
进行重置录音之前,需要先调用[stop()](#audiorecorder_stop)停止录音。重置录音之后,需要调用[prepare()](#audiorecorder_prepare)设置录音参数项,才能再次进行录音。
B
bird_j 已提交
1686

Z
zengyawen 已提交
1687 1688
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1689
**示例:**
Z
zengyawen 已提交
1690

B
bird_j 已提交
1691
```js
W
wusongqing 已提交
1692
audioRecorder.on('reset', () => {    //设置'reset'事件回调
B
bird_j 已提交
1693 1694 1695
    console.log('audio recorder reset success');
});
audioRecorder.reset();
Z
zengyawen 已提交
1696 1697
```

B
bird_j 已提交
1698
### on('prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset')<a name=audiorecorder_on></a>
Z
zengyawen 已提交
1699

1700
on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void
Z
zengyawen 已提交
1701

W
wusongqing 已提交
1702
开始订阅音频录制事件。
Z
zengyawen 已提交
1703

Z
zengyawen 已提交
1704 1705
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1706
**参数:**
B
bird_j 已提交
1707

W
wusongqing 已提交
1708
| 参数名   | 类型     | 必填 | 说明                                                         |
Z
zengyawen 已提交
1709
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1710 1711
| type     | string   | 是   | 录制事件回调类型,支持的事件包括:'prepare'&nbsp;\|&nbsp;'start'&nbsp;\|  'pause' \| ’resume‘ \|&nbsp;'stop'&nbsp;\|&nbsp;'release'&nbsp;\|&nbsp;'reset'。<br/>-&nbsp;'prepare'&nbsp;:完成[prepare](#audiorecorder_prepare)调用,音频录制参数设置完成,触发该事件。<br/>-&nbsp;'start'&nbsp;:完成[start](#audiorecorder_start)调用,音频录制开始,触发该事件。<br/>-&nbsp;'pause': 完成[pause](#audiorecorder_pause)调用,音频暂停录制,触发该事件。<br/>-&nbsp;'resume': 完成[resume](#audiorecorder_resume)调用,音频恢复录制,触发该事件。<br/>-&nbsp;'stop'&nbsp;:完成[stop](#audiorecorder_stop)调用,音频停止录制,触发该事件。<br/>-&nbsp;'release'&nbsp;:完成[release](#audiorecorder_release)调用,音频释放录制资源,触发该事件。<br/>-&nbsp;'reset':完成[reset](#audiorecorder_reset)调用,音频重置为初始状态,触发该事件。 |
| callback | ()=>void | 是   | 录制事件回调方法。                                           |
Z
zengyawen 已提交
1712

W
wusongqing 已提交
1713
**示例:**
Z
zengyawen 已提交
1714

1715
```js
W
wusongqing 已提交
1716
let audiorecorder = media.createAudioRecorder();  								// 创建一个音频录制实例
1717 1718 1719 1720 1721 1722
let audioRecorderConfig = {
    audioEncoder : media.AudioEncoder.AAC_LC, ,
    audioEncodeBitRate : 22050,
    audioSampleRate : 22050,
    numberOfChannels : 2,
    format : media.AudioOutputFormat.AAC_ADTS,
Z
zengyawen 已提交
1723
    uri : 'fd://xx',                                                            // 文件需先由调用者创建,并给予适当的权限
1724 1725
    location : { latitude : 30, longitude : 130},
}
W
wusongqing 已提交
1726
audioRecorder.on('error', (error) => {             								// 设置'error'事件回调
1727 1728 1729 1730
	console.info(`audio error called, errName is ${error.name}`);
    console.info(`audio error called, errCode is ${error.code}`);
    console.info(`audio error called, errMessage is ${error.message}`);
});
W
wusongqing 已提交
1731
audioRecorder.on('prepare', () => {              								// 设置'prepare'事件回调
1732
    console.log('prepare success');
W
wusongqing 已提交
1733
    audioRecorder.start();                       								// 开始录制,并触发'start'事件回调
1734
});
W
wusongqing 已提交
1735
audioRecorder.on('start', () => {    		     								// 设置'start'事件回调
1736 1737
    console.log('audio recorder start success');
});
W
wusongqing 已提交
1738
audioRecorder.on('pause', () => {    		     								// 设置'pause'事件回调
1739 1740
    console.log('audio recorder pause success');
});
W
wusongqing 已提交
1741
audioRecorder.on('resume', () => {    		     								// 设置'resume'事件回调
1742 1743
    console.log('audio recorder resume success');
});
W
wusongqing 已提交
1744
audioRecorder.on('stop', () => {    		     								// 设置'stop'事件回调
1745 1746
    console.log('audio recorder stop success');
});
W
wusongqing 已提交
1747
audioRecorder.on('release', () => {    		     								// 设置'release'事件回调
1748 1749
    console.log('audio recorder release success');
});
W
wusongqing 已提交
1750
audioRecorder.on('reset', () => {    		     								// 设置'reset'事件回调
1751
    console.log('audio recorder reset success');
Z
zengyawen 已提交
1752
});
W
wusongqing 已提交
1753
audioRecorder.prepare(audioRecorderConfig)       								// 设置录制参数 ,并触发'prepare'事件回调
Z
zengyawen 已提交
1754 1755 1756 1757 1758 1759
```

### on('error')

on(type: 'error', callback: ErrorCallback): void

W
wusongqing 已提交
1760
开始订阅音频录制错误事件。
B
bird_j 已提交
1761

Z
zengyawen 已提交
1762 1763
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1764
**参数:**
Z
zengyawen 已提交
1765

W
wusongqing 已提交
1766
| 参数名   | 类型          | 必填 | 说明                                                         |
Z
zengyawen 已提交
1767
| -------- | ------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1768 1769
| type     | string        | 是   | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':音频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | 是   | 录制错误事件回调方法。                                       |
Z
zengyawen 已提交
1770

W
wusongqing 已提交
1771
**示例:**
1772 1773

```js
W
wusongqing 已提交
1774 1775 1776 1777
audioRecorder.on('error', (error) => {      							// 设置'error'事件回调
	console.info(`audio error called, errName is ${error.name}`);       // 打印错误类型名称
    console.info(`audio error called, errCode is ${error.code}`);       // 打印错误码
    console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述
1778
});
W
wusongqing 已提交
1779
audioRecorder.prepare();  												// prepare不设置参数,触发'error'事件
1780
```
Z
zengyawen 已提交
1781 1782 1783

## AudioRecorderConfig

W
wusongqing 已提交
1784
表示音频的录音配置。
Z
zengyawen 已提交
1785

Z
zengyawen 已提交
1786 1787
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.AudioRecorder。

W
wusongqing 已提交
1788
| 名称                  | 参数类型                                | 必填 | 说明                                                         |
1789
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1790 1791 1792 1793 1794 1795
| audioEncoder          | [AudioEncoder](#audioencoder)           | 否   | 音频编码格式,默认设置为AAC_LC。                             |
| audioEncodeBitRate    | number                                  | 否   | 音频编码比特率,默认值为48000。                              |
| audioSampleRate       | number                                  | 否   | 音频采集采样率,默认值为48000。                              |
| numberOfChannels      | number                                  | 否   | 音频采集声道数,默认值为2。                                  |
| format                | [AudioOutputFormat](#audiooutputformat) | 否   | 音量输出封装格式,默认设置为MPEG_4。                         |
| location<sup>8+</sup> | [Location](#location8)                  | 否   | 音频采集的地理位置。                                         |
Z
zengyawen 已提交
1796
| uri                   | string                                  | 是   | 视频输出URI:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
Z
zengyawen 已提交
1797 1798 1799 1800


## AudioEncoder

W
wusongqing 已提交
1801
表示音频编码格式的枚举。
Z
zengyawen 已提交
1802

Z
zengyawen 已提交
1803 1804
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.AudioRecorder。

W
wusongqing 已提交
1805
| 名称    | 默认值 | 说明                                                         |
B
bird_j 已提交
1806
| ------- | ------ | ------------------------------------------------------------ |
Z
zengyawen 已提交
1807 1808 1809 1810 1811
| DEFAULT | 0      | Default audio encoding format is AMR_NB。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AMR_NB  | 1      | AMR-NB(Adaptive Multi Rate-Narrow Band Speech Codec) 编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AMR_WB  | 2      | AMR-WB(Adaptive Multi Rate-Wide Band Speech Codec) 编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AAC_LC  | 3      | AAC-LC(Advanced&nbsp;Audio&nbsp;Coding&nbsp;Low&nbsp;Complexity)编码格式。 |
| HE_AAC  | 4      | HE_AAC(High-Efficiency Advanced&nbsp;Audio&nbsp;Coding)编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
Z
zengyawen 已提交
1812 1813 1814 1815


## AudioOutputFormat

W
wusongqing 已提交
1816
表示音频封装格式的枚举。
Z
zengyawen 已提交
1817

Z
zengyawen 已提交
1818 1819
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.AudioRecorder。

W
wusongqing 已提交
1820
| 名称     | 默认值 | 说明                                                         |
Z
zengyawen 已提交
1821
| -------- | ------ | ------------------------------------------------------------ |
Z
zengyawen 已提交
1822 1823 1824 1825 1826
| DEFAULT  | 0      | 默认封装格式为MPEG-4。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| MPEG_4   | 2      | 封装为MPEG-4格式。                                           |
| AMR_NB   | 3      | 封装为AMR_NB格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AMR_WB   | 4      | 封装为AMR_WB格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AAC_ADTS | 6      | 封装为ADTS(Audio&nbsp;Data&nbsp;Transport&nbsp;Stream)格式,是AAC音频的传输流格式。 |
1827 1828 1829

## VideoRecorder<sup>8+</sup>

Z
zengyawen 已提交
1830
视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorder()](#media.createvideorecorder8)构建一个[VideoRecorder](#videorecorder8)实例。
1831

W
wusongqing 已提交
1832
视频录制demo可参考:[视频录制开发指导](../../media/video-recorder.md)
1833

W
wusongqing 已提交
1834
### 属性
1835

Z
zengyawen 已提交
1836 1837 1838
| 名称               | 类型                                  | 可读 | 可写 | 说明             |
| ------------------ | ------------------------------------- | ---- | ---- | ---------------- |
| state<sup>8+</sup> | [VideoRecordState](#videorecordstate) | 是   | 否   | 视频录制的状态。 |
1839

Z
zengyawen 已提交
1840
### prepare<sup>8+</sup><a name=videorecorder_prepare1></a>
1841 1842 1843

prepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
1844
异步方式进行视频录制的参数设置。通过注册回调函数获取返回值。
1845

Z
zengyawen 已提交
1846 1847 1848 1849
**需要权限:** ohos.permission.MICROPHONE ohos.permission.CAMERA

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
1850
**参数:**
B
bird_j 已提交
1851

W
wusongqing 已提交
1852
| 参数名   | 类型                                        | 必填 | 说明                                |
1853
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
W
wusongqing 已提交
1854 1855
| config   | [VideoRecorderConfig](#videorecorderconfig) | 是   | 配置视频录制的相关参数。            |
| callback | AsyncCallback\<void>                        | 是   | 异步视频录制prepare方法的回调方法。 |
1856

W
wusongqing 已提交
1857
**示例:**
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876

```js
let videoProfile = {
    audioBitrate : 48000,
    audioChannels : 2,
    audioCodec : 'audio/mp4a-latm',
    audioSampleRate : 48000,
    fileFormat : 'mp4',
    videoBitrate : 48000,
    videoCodec : 'video/mp4v-es',
    videoFrameWidth : 640,
    videoFrameHeight : 480,
    videoFrameRate : 30
}

let videoConfig = {
    audioSourceType : 1,
    videoSourceType : 0,
    profile : videoProfile,
Z
zengyawen 已提交
1877
    url : 'fd://xx',   // 文件需先由调用者创建,并给予适当的权限
1878 1879 1880 1881 1882 1883 1884
    orientationHint : 0,
    location : { latitude : 30, longitude : 130 },
}

// asyncallback
let videoRecorder = null;
let events = require('events');
B
bird_j 已提交
1885
let eventEmitter = new events.EventEmitter();                              
1886 1887 1888 1889

eventEmitter.on('prepare', () => {
    videoRecorder.prepare(videoConfig, (err) => {
        if (typeof (err) == 'undefined') {
B
bird_j 已提交
1890
            console.info('prepare success');
1891
        } else {
B
bird_j 已提交
1892
            console.info('prepare failed and error is ' + err.message);
1893 1894 1895 1896 1897 1898
        }
    });
});

media.createVideoRecorder((err, recorder) => {
    if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') {
B
bird_j 已提交
1899 1900
        videoRecorder = recorder;
        console.info('createVideoRecorder success');
W
wusongqing 已提交
1901
        eventEmitter.emit('prepare');                                        // prepare事件触发
1902
    } else {
B
bird_j 已提交
1903
        console.info('createVideoRecorder failed and error is ' + err.message);
1904 1905 1906 1907
    }
});
```

Z
zengyawen 已提交
1908
### prepare<sup>8+</sup><a name=videorecorder_prepare2></a>
1909 1910 1911

prepare(config: VideoRecorderConfig): Promise\<void>;

W
wusongqing 已提交
1912
异步方式进行视频录制的参数设置。通过Promise获取返回值。
B
bird_j 已提交
1913

Z
zengyawen 已提交
1914 1915 1916 1917
**需要权限:** ohos.permission.MICROPHONE ohos.permission.CAMERA

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
1918
**参数:**
1919

W
wusongqing 已提交
1920
| 参数名 | 类型                                        | 必填 | 说明                     |
1921
| ------ | ------------------------------------------- | ---- | ------------------------ |
W
wusongqing 已提交
1922
| config | [VideoRecorderConfig](#videorecorderconfig) | 是   | 配置视频录制的相关参数。 |
1923

W
wusongqing 已提交
1924
**返回值:**
1925

W
wusongqing 已提交
1926
| 类型           | 说明                                     |
1927
| -------------- | ---------------------------------------- |
W
wusongqing 已提交
1928
| Promise\<void> | 异步视频录制prepare方法的Promise返回值。 |
1929

W
wusongqing 已提交
1930
**示例:**
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949

```js
let videoProfile = {
    audioBitrate : 48000,
    audioChannels : 2,
    audioCodec : 'audio/mp4a-latm',
    audioSampleRate : 48000,
    fileFormat : 'mp4',
    videoBitrate : 48000,
    videoCodec : 'video/mp4v-es',
    videoFrameWidth : 640,
    videoFrameHeight : 480,
    videoFrameRate : 30
}

let videoConfig = {
    audioSourceType : 1,
    videoSourceType : 0,
    profile : videoProfile,
Z
zengyawen 已提交
1950
    url : 'fd://xx',   // 文件需先由调用者创建,并给予适当的权限
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
    orientationHint : 0,
    location : { latitude : 30, longitude : 130 },
}

// promise
let videoRecorder = null;
await media.createVideoRecorder().then((recorder) => {
    if (typeof (recorder) != 'undefined') {
        videoRecorder = recorder;
        console.info('createVideoRecorder success');
    } else {
        console.info('createVideoRecorder failed');
    }
}, (err) => {
    console.info('error hanppend message is ' + err.message);
}).catch((err) => {
    console.info('catch err error message is ' + err.message);
});

await videoRecorder.prepare(videoConfig).then(() => {
    console.info('prepare success');
}, (err) => {
    console.info('prepare failed and error is ' + err.message);
}).catch((err) => {
    console.info('prepare failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
1979
### getInputSurface<sup>8+</sup>
1980 1981 1982

getInputSurface(callback: AsyncCallback\<string>): void;

W
wusongqing 已提交
1983
异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。
1984

W
wusongqing 已提交
1985
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。
1986

W
wusongqing 已提交
1987
只能在[prepare()](#videorecorder_prepare1)接口调用后调用。
1988

Z
zengyawen 已提交
1989 1990
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
1991
**参数:**
B
bird_j 已提交
1992

W
wusongqing 已提交
1993
| 参数名   | 类型                   | 必填 | 说明                        |
1994
| -------- | ---------------------- | ---- | --------------------------- |
W
wusongqing 已提交
1995
| callback | AsyncCallback\<string> | 是   | 异步获得surface的回调方法。 |
1996

W
wusongqing 已提交
1997
**示例:**
1998 1999 2000

```js
// asyncallback
W
wusongqing 已提交
2001
let surfaceID = null;   											// 传递给外界的surfaceID
B
bird_j 已提交
2002 2003 2004
videoRecorder.getInputSurface((err, surfaceId) => {
    if (typeof (err) == 'undefined') {
        console.info('getInputSurface success');
B
bird_j 已提交
2005
        surfaceID = surfaceId;
B
bird_j 已提交
2006 2007 2008
    } else {
        console.info('getInputSurface failed and error is ' + err.message);
    }
2009 2010 2011
});
```

Z
zengyawen 已提交
2012
### getInputSurface<sup>8+</sup>
2013 2014 2015

getInputSurface(): Promise\<string>;

W
wusongqing 已提交
2016
 异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。
2017

W
wusongqing 已提交
2018
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。
2019

W
wusongqing 已提交
2020
只能在[prepare()](#videorecorder_prepare1)接口调用后调用。
B
bird_j 已提交
2021

Z
zengyawen 已提交
2022 2023
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2024
**返回值:**
2025

W
wusongqing 已提交
2026
| 类型             | 说明                             |
2027
| ---------------- | -------------------------------- |
W
wusongqing 已提交
2028
| Promise\<string> | 异步获得surface的Promise返回值。 |
2029

W
wusongqing 已提交
2030
**示例:**
2031 2032 2033

```js
// promise
W
wusongqing 已提交
2034
let surfaceID = null;   											// 传递给外界的surfaceID
B
bird_j 已提交
2035
await videoRecorder.getInputSurface().then((surfaceId) => {
2036
    console.info('getInputSurface success');
B
bird_j 已提交
2037
    surfaceID = surfaceId;
2038 2039 2040 2041 2042 2043 2044
}, (err) => {
    console.info('getInputSurface failed and error is ' + err.message);
}).catch((err) => {
    console.info('getInputSurface failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2045
### start<sup>8+</sup><a name=videorecorder_start1></a>
2046 2047 2048

start(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2049
异步方式开始视频录制。通过注册回调函数获取返回值。
2050

Z
zengyawen 已提交
2051 2052 2053
[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
B
bird_j 已提交
2054

W
wusongqing 已提交
2055
**参数:**
2056

W
wusongqing 已提交
2057
| 参数名   | 类型                 | 必填 | 说明                         |
2058
| -------- | -------------------- | ---- | ---------------------------- |
W
wusongqing 已提交
2059
| callback | AsyncCallback\<void> | 是   | 异步开始视频录制的回调方法。 |
2060

W
wusongqing 已提交
2061
**示例:**
2062 2063 2064

```js
// asyncallback
B
bird_j 已提交
2065 2066 2067 2068 2069 2070
videoRecorder.start((err) => {
    if (typeof (err) == 'undefined') {
        console.info('start videorecorder success');
    } else {
        console.info('start videorecorder failed and error is ' + err.message);
    }
2071 2072 2073
});
```

Z
zengyawen 已提交
2074
### start<sup>8+</sup><a name=videorecorder_start2></a>
2075 2076 2077

start(): Promise\<void>;

W
wusongqing 已提交
2078
异步方式开始视频录制。通过Promise获取返回值。
2079

Z
zengyawen 已提交
2080 2081 2082
[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
2083

W
wusongqing 已提交
2084
**返回值:**
B
bird_j 已提交
2085

W
wusongqing 已提交
2086
| 类型           | 说明                                  |
2087
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2088
| Promise\<void> | 异步开始视频录制方法的Promise返回值。 |
2089

W
wusongqing 已提交
2090
**示例:**
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102

```js
// promise
await videoRecorder.start().then(() => {
    console.info('start videorecorder success');
}, (err) => {
    console.info('start videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('start videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2103
### pause<sup>8+</sup><a name=videorecorder_pause1></a>
2104 2105 2106

pause(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2107
异步方式暂停视频录制。通过注册回调函数获取返回值。
2108

W
wusongqing 已提交
2109
[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。
B
bird_j 已提交
2110

Z
zengyawen 已提交
2111 2112
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2113
**参数:**
2114

W
wusongqing 已提交
2115
| 参数名   | 类型                 | 必填 | 说明                         |
2116
| -------- | -------------------- | ---- | ---------------------------- |
W
wusongqing 已提交
2117
| callback | AsyncCallback\<void> | 是   | 异步暂停视频录制的回调方法。 |
2118

W
wusongqing 已提交
2119
**示例:**
2120 2121 2122

```js
// asyncallback
B
bird_j 已提交
2123 2124 2125 2126 2127 2128
videoRecorder.pause((err) => {
    if (typeof (err) == 'undefined') {
        console.info('pause videorecorder success');
    } else {
        console.info('pause videorecorder failed and error is ' + err.message);
    }
2129 2130 2131
});
```

Z
zengyawen 已提交
2132
### pause<sup>8+</sup><a name=videorecorder_pause2></a>
2133 2134 2135

pause(): Promise\<void>;

W
wusongqing 已提交
2136
异步方式暂停视频录制。通过Promise获取返回值。
2137

W
wusongqing 已提交
2138
[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。
2139

Z
zengyawen 已提交
2140 2141
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2142
**返回值:**
B
bird_j 已提交
2143

W
wusongqing 已提交
2144
| 类型           | 说明                                  |
2145
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2146
| Promise\<void> | 异步暂停视频录制方法的Promise返回值。 |
2147

W
wusongqing 已提交
2148
**示例:**
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160

```js
// promise
await videoRecorder.pause().then(() => {
    console.info('pause videorecorder success');
}, (err) => {
    console.info('pause videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('pause videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2161
### resume<sup>8+</sup><a name=videorecorder_resume1></a>
2162 2163 2164

resume(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2165
异步方式恢复视频录制。通过注册回调函数获取返回值。
B
bird_j 已提交
2166

Z
zengyawen 已提交
2167 2168
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2169
**参数:**
2170

W
wusongqing 已提交
2171
| 参数名   | 类型                 | 必填 | 说明                         |
2172
| -------- | -------------------- | ---- | ---------------------------- |
W
wusongqing 已提交
2173
| callback | AsyncCallback\<void> | 是   | 异步恢复视频录制的回调方法。 |
2174

W
wusongqing 已提交
2175
**示例:**
2176 2177 2178

```js
// asyncallback
B
bird_j 已提交
2179 2180 2181 2182 2183 2184
videoRecorder.resume((err) => {
    if (typeof (err) == 'undefined') {
        console.info('resume videorecorder success');
    } else {
        console.info('resume videorecorder failed and error is ' + err.message);
    }
2185 2186 2187
});
```

Z
zengyawen 已提交
2188
### resume<sup>8+</sup><a name=videorecorder_resume2></a>
2189 2190 2191

resume(): Promise\<void>;

W
wusongqing 已提交
2192
异步方式恢复视频录制。通过Promise获取返回值。
2193

Z
zengyawen 已提交
2194 2195
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2196
**返回值:**
B
bird_j 已提交
2197

W
wusongqing 已提交
2198
| 类型           | 说明                                  |
2199
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2200
| Promise\<void> | 异步恢复视频录制方法的Promise返回值。 |
2201

W
wusongqing 已提交
2202
**示例:**
2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214

```js
// promise
await videoRecorder.resume().then(() => {
    console.info('resume videorecorder success');
}, (err) => {
    console.info('resume videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('resume videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2215
### stop<sup>8+</sup><a name=videorecorder_stop1></a>
2216 2217 2218

stop(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2219
异步方式停止视频录制。通过注册回调函数获取返回值。
2220

Z
zengyawen 已提交
2221 2222 2223
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
B
bird_j 已提交
2224

W
wusongqing 已提交
2225
**参数:**
2226

W
wusongqing 已提交
2227
| 参数名   | 类型                 | 必填 | 说明                         |
2228
| -------- | -------------------- | ---- | ---------------------------- |
W
wusongqing 已提交
2229
| callback | AsyncCallback\<void> | 是   | 异步停止视频录制的回调方法。 |
2230

W
wusongqing 已提交
2231
**示例:**
2232 2233 2234

```js
// asyncallback
B
bird_j 已提交
2235 2236 2237 2238 2239 2240
videoRecorder.stop((err) => {
    if (typeof (err) == 'undefined') {
        console.info('stop videorecorder success');
    } else {
        console.info('stop videorecorder failed and error is ' + err.message);
    }
2241 2242 2243
});
```

Z
zengyawen 已提交
2244
### stop<sup>8+</sup><a name=videorecorder_stop2></a>
2245 2246 2247

stop(): Promise\<void>;

W
wusongqing 已提交
2248
异步方式停止视频录制。通过Promise获取返回值。
2249

Z
zengyawen 已提交
2250 2251 2252
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
2253

W
wusongqing 已提交
2254
**返回值:**
B
bird_j 已提交
2255

W
wusongqing 已提交
2256
| 类型           | 说明                                  |
2257
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2258
| Promise\<void> | 异步停止视频录制方法的Promise返回值。 |
2259

W
wusongqing 已提交
2260
**示例:**
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272

```js
// promise
await videoRecorder.stop().then(() => {
    console.info('stop videorecorder success');
}, (err) => {
    console.info('stop videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('stop videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2273
### release<sup>8+</sup><a name=videorecorder_release1></a>
2274 2275 2276

release(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2277
异步方式释放视频录制资源。通过注册回调函数获取返回值。
B
bird_j 已提交
2278

Z
zengyawen 已提交
2279 2280
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2281
**参数:**
2282

W
wusongqing 已提交
2283
| 参数名   | 类型                 | 必填 | 说明                             |
2284
| -------- | -------------------- | ---- | -------------------------------- |
W
wusongqing 已提交
2285
| callback | AsyncCallback\<void> | 是   | 异步释放视频录制资源的回调方法。 |
2286

W
wusongqing 已提交
2287
**示例:**
2288 2289 2290

```js
// asyncallback
B
bird_j 已提交
2291 2292 2293 2294 2295 2296
videoRecorder.release((err) => {
    if (typeof (err) == 'undefined') {
        console.info('release videorecorder success');
    } else {
        console.info('release videorecorder failed and error is ' + err.message);
    }
2297 2298 2299
});
```

Z
zengyawen 已提交
2300
### release<sup>8+</sup><a name=videorecorder_release2></a>
2301 2302 2303

release(): Promise\<void>;

W
wusongqing 已提交
2304
异步方式释放视频录制资源。通过Promise获取返回值。
B
bird_j 已提交
2305

Z
zengyawen 已提交
2306 2307
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2308
**返回值:**
2309

W
wusongqing 已提交
2310
| 类型           | 说明                                      |
2311
| -------------- | ----------------------------------------- |
W
wusongqing 已提交
2312
| Promise\<void> | 异步释放视频录制资源方法的Promise返回值。 |
2313

W
wusongqing 已提交
2314
**示例:**
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326

```js
// promise
await videoRecorder.release().then(() => {
    console.info('release videorecorder success');
}, (err) => {
    console.info('release videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('release videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2327
### reset<sup>8+</sup><a name=videorecorder_reset1></a>
2328 2329 2330

reset(callback: AsyncCallback\<void>): void;

W
wusongqing 已提交
2331
异步方式重置视频录制。通过注册回调函数获取返回值。
2332

Z
zengyawen 已提交
2333 2334 2335
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
2336

W
wusongqing 已提交
2337
**参数:**
B
bird_j 已提交
2338

W
wusongqing 已提交
2339
| 参数名   | 类型                 | 必填 | 说明                         |
2340
| -------- | -------------------- | ---- | ---------------------------- |
W
wusongqing 已提交
2341
| callback | AsyncCallback\<void> | 是   | 异步重置视频录制的回调方法。 |
2342

W
wusongqing 已提交
2343
**示例:**
2344 2345 2346

```js
// asyncallback
B
bird_j 已提交
2347 2348 2349 2350 2351 2352
videoRecorder.reset((err) => {
    if (typeof (err) == 'undefined') {
        console.info('reset videorecorder success');
    } else {
        console.info('reset videorecorder failed and error is ' + err.message);
    }
2353 2354 2355
});
```

Z
zengyawen 已提交
2356
### reset<sup>8+</sup><a name=videorecorder_reset2></a>
2357 2358 2359

reset(): Promise\<void>;

W
wusongqing 已提交
2360
异步方式重置视频录制。通过Promise获取返回值。
2361

Z
zengyawen 已提交
2362 2363 2364
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。

**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder
B
bird_j 已提交
2365

W
wusongqing 已提交
2366
**返回值:**
2367

W
wusongqing 已提交
2368
| 类型           | 说明                                  |
2369
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2370
| Promise\<void> | 异步重置视频录制方法的Promise返回值。 |
2371

W
wusongqing 已提交
2372
**示例:**
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384

```js
// promise
await videoRecorder.reset().then(() => {
    console.info('reset videorecorder success');
}, (err) => {
    console.info('reset videorecorder failed and error is ' + err.message);
}).catch((err) => {
    console.info('reset videorecorder failed and catch error is ' + err.message);
});
```

Z
zengyawen 已提交
2385
### on('error')<sup>8+</sup>
2386 2387 2388

on(type: 'error', callback: ErrorCallback): void

W
wusongqing 已提交
2389
开始订阅视频录制错误事件。
2390

Z
zengyawen 已提交
2391 2392
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2393
**参数:**
B
bird_j 已提交
2394

W
wusongqing 已提交
2395
| 参数名   | 类型          | 必填 | 说明                                                         |
2396
| -------- | ------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
2397 2398
| type     | string        | 是   | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':音频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | 是   | 录制错误事件回调方法。                                       |
2399

W
wusongqing 已提交
2400
**示例:**
2401 2402

```js
W
wusongqing 已提交
2403 2404 2405 2406
videoRecorder.on('error', (error) => {      							// 设置'error'事件回调
	console.info(`audio error called, errName is ${error.name}`);       // 打印错误类型名称
    console.info(`audio error called, errCode is ${error.code}`);       // 打印错误码
    console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述
2407
});
W
wusongqing 已提交
2408
// 当获取videoRecordState接口出错时通过此订阅事件上报
2409 2410 2411 2412
```

## VideoRecordState<sup>8+</sup>

W
wusongqing 已提交
2413
视频录制的状态机。可通过state属性获取当前状态。
2414

Z
zengyawen 已提交
2415 2416
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。

W
wusongqing 已提交
2417 2418 2419 2420 2421 2422 2423 2424
| 名称     | 类型   | 描述                   |
| -------- | ------ | ---------------------- |
| idle     | string | 视频录制空闲。         |
| prepared | string | 视频录制参数设置完成。 |
| playing  | string | 视频正在录制。         |
| paused   | string | 视频暂停录制。         |
| stopped  | string | 视频录制停止。         |
| error    | string | 错误状态。             |
2425 2426 2427

## VideoRecorderConfig<sup>8+</sup>

W
wusongqing 已提交
2428
表示视频录制的参数设置。
2429

Z
zengyawen 已提交
2430 2431
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。

W
wusongqing 已提交
2432
| 名称            | 参数类型                                                   | 必填 | 说明                                                         |
2433
| --------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
2434 2435 2436 2437 2438
| audioSourceType | [AudioSourceType](#audiosourcetype<sup>8+</sup>)           | 是   | 视频录制的音频源类型。                                       |
| videoSourceType | [VideoSourceType](#videosourcetype<sup>8+</sup>)           | 是   | 视频录制的视频源类型。                                       |
| profile         | [VideoRecorderProfile](#videorecorderprofile<sup>8+</sup>) | 是   | 视频录制的profile。                                          |
| orientationHint | number                                                     | 否   | 录制视频的旋转角度。                                         |
| location        | [Location](#location8)                                     | 否   | 录制视频的地理位置。                                         |
Z
zengyawen 已提交
2439
| url             | string                                                     | 是   | 视频输出URL:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
2440 2441 2442

## AudioSourceType<sup>8+</sup>

W
wusongqing 已提交
2443
表示视频录制中音频源类型的枚举。
2444

Z
zengyawen 已提交
2445 2446 2447 2448 2449 2450
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。

| 名称                      | 值   | 说明                   |
| ------------------------- | ---- | ---------------------- |
| AUDIO_SOURCE_TYPE_DEFAULT | 0    | 默认的音频输入源类型。 |
| AUDIO_SOURCE_TYPE_MIC     | 1    | 表示MIC的音频输入源。  |
2451 2452 2453

## VideoSourceType<sup>8+</sup>

W
wusongqing 已提交
2454
表示视频录制中视频源类型的枚举。
2455

Z
zengyawen 已提交
2456 2457
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。

W
wusongqing 已提交
2458 2459 2460 2461
| 名称                          | 值   | 说明                            |
| ----------------------------- | ---- | ------------------------------- |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0    | 输入surface中携带的是raw data。 |
| VIDEO_SOURCE_TYPE_SURFACE_ES  | 1    | 输入surface中携带的是ES data。  |
2462 2463 2464

## VideoRecorderProfile<sup>8+</sup>

W
wusongqing 已提交
2465
视频录制的配置文件。
2466

Z
zengyawen 已提交
2467 2468
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。

W
wusongqing 已提交
2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
| 名称             | 参数类型                                     | 必填 | 说明             |
| ---------------- | -------------------------------------------- | ---- | ---------------- |
| audioBitrate     | number                                       | 是   | 音频编码比特率。 |
| audioChannels    | number                                       | 是   | 音频采集声道数。 |
| audioCodec       | [CodecMimeType](#CodecMimeType8)             | 是   | 音频编码格式。   |
| audioSampleRate  | number                                       | 是   | 音频采样率。     |
| fileFormat       | [ContainerFormatType](#containerformattype8) | 是   | 文件的容器格式。 |
| videoCodec       | [CodecMimeType](#CodecMimeType8)             | 是   | 视频编码格式。   |
| videoFrameWidth  | number                                       | 是   | 录制视频帧的宽。 |
| videoFrameHeight | number                                       | 是   | 录制视频帧的高。 |
2479 2480 2481

## ContainerFormatType<sup>8+</sup>

W
wusongqing 已提交
2482
表示容器格式类型的枚举,缩写为CFT。
2483

Z
zengyawen 已提交
2484 2485
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。

W
wusongqing 已提交
2486 2487 2488 2489
| 名称        | 值    | 说明                  |
| ----------- | ----- | --------------------- |
| CFT_MPEG_4  | "mp4" | 视频的容器格式,MP4。 |
| CFT_MPEG_4A | "m4a" | 音频的容器格式,M4A。 |
2490 2491 2492

## Location<sup>8+</sup>

W
wusongqing 已提交
2493
视频录制的地理位置。
2494

Z
zengyawen 已提交
2495 2496
**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.Core。

W
wusongqing 已提交
2497 2498 2499 2500
| 名称      | 参数类型 | 必填 | 说明             |
| --------- | -------- | ---- | ---------------- |
| latitude  | number   | 是   | 地理位置的纬度。 |
| longitude | number   | 是   | 地理位置的经度。 |