js-apis-media.md 89.5 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
- 音频播放([AudioPlayer](#audioplayer)
- 视频播放([VideoPlayer](#videoplayer8)
- 音频录制([AudioRecorder](#audiorecorder)
Z
zengyawen 已提交
13
- 视频录制([VideoRecorder](#videorecorder9)
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
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>

Z
zengyawen 已提交
74
createVideoPlayer(): Promise<[VideoPlayer](#videoplayer8)>
75

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
A
amr  
abc12133 已提交
125
let audiorecorder = media.createAudioRecorder();
Z
zengyawen 已提交
126
```
Z
zengyawen 已提交
127

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

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

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

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

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

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

**示例:**

```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
   }
});
```

157
## media.createVideoRecorder<sup>9+</sup>
158

159
createVideoRecorder(): Promise<[VideoRecorder](#videorecorder9)>
160

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

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

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

Z
zengyawen 已提交
167 168
| 类型                                      | 说明                                |
| ----------------------------------------- | ----------------------------------- |
169
| Promise<[VideoRecorder](#videorecorder9)> | 异步创建视频录制实例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

Z
zengyawen 已提交
231 232 233 234 235 236 237
| 名称         | 值                    | 说明                     |
| ------------ | --------------------- | ------------------------ |
| VIDEO_H263   | 'video/h263'          | 表示视频/h263类型。      |
| VIDEO_AVC    | 'video/avc'           | 表示视频/avc类型。       |
| VIDEO_MPEG2  | 'video/mpeg2'         | 表示视频/mpeg2类型。     |
| VIDEO_MPEG4  | 'video/mp4v-es'       | 表示视频/mpeg4类型。     |
| VIDEO_VP8    | 'video/x-vnd.on2.vp8' | 表示视频/vp8类型。       |
238
| AUDIO_AAC    | "audio/mp4a-latm"     | 表示音频/mp4a-latm类型。 |
Z
zengyawen 已提交
239 240
| AUDIO_VORBIS | 'audio/vorbis'        | 表示音频/vorbis类型。    |
| AUDIO_FLAC   | 'audio/flac'          | 表示音频/flac类型。      |
241 242 243

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

Z
zengyawen 已提交
244 245 246
媒体信息描述枚举。

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

W
wusongqing 已提交
248
| 名称                     | 值              | 说明                                                         |
249
| ------------------------ | --------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
250 251 252
| 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。                 |
Z
zengyawen 已提交
253 254 255 256 257
| MD_KEY_DURATION          | "duration"      | 表示媒体时长,其对应键值类型为number,单位为毫秒(ms)。     |
| MD_KEY_BITRATE           | "bitrate"       | 表示比特率,其对应键值类型为number,单位为比特率(bps)。    |
| MD_KEY_WIDTH             | "width"         | 表示视频宽度,其对应键值类型为number,单位为像素(px)。     |
| MD_KEY_HEIGHT            | "height"        | 表示视频高度,其对应键值类型为number,单位为像素(px)。     |
| MD_KEY_FRAME_RATE        | "frame_rate"    | 表示视频帧率,其对应键值类型为number,单位为100帧每秒(100fps)。 |
W
wusongqing 已提交
258
| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | 表示声道数,其对应键值类型为number。                         |
Z
zengyawen 已提交
259
| MD_KEY_AUD_SAMPLE_RATE   | "sample_rate"   | 表示采样率,其对应键值类型为number,单位为赫兹(Hz)。       |
260 261 262

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

Z
zengyawen 已提交
263 264 265
缓存事件类型枚举。

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

Z
zengyawen 已提交
267 268 269 270 271 272
| 名称              | 值   | 说明                             |
| ----------------- | ---- | -------------------------------- |
| BUFFERING_START   | 1    | 表示开始缓存。                   |
| BUFFERING_END     | 2    | 表示结束缓存。                   |
| BUFFERING_PERCENT | 3    | 表示缓存百分比。                 |
| CACHED_DURATION   | 4    | 表示缓存时长,单位为毫秒(ms)。 |
273

Z
zengyawen 已提交
274
## AudioPlayer
Z
zengyawen 已提交
275

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

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

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

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

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

292
### play<a name=audioplayer_play></a>
Z
zengyawen 已提交
293

Z
zengyawen 已提交
294
play(): void
Z
zengyawen 已提交
295

Z
zengyawen 已提交
296
开始播放音频资源,需在[dataLoad](#audioplayer_on)事件成功触发后,才能调用play方法。
Z
zengyawen 已提交
297

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

W
wusongqing 已提交
300
**示例:**
Z
zengyawen 已提交
301

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

309
### pause<a name=audioplayer_pause></a>
Z
zengyawen 已提交
310

Z
zengyawen 已提交
311
pause(): void
Z
zengyawen 已提交
312

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

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

W
wusongqing 已提交
317
**示例:**
Z
zengyawen 已提交
318

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

326
### stop<a name=audioplayer_stop></a>
Z
zengyawen 已提交
327

Z
zengyawen 已提交
328
stop(): void
Z
zengyawen 已提交
329

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

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

W
wusongqing 已提交
334
**示例:**
Z
zengyawen 已提交
335

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

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

reset(): void

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

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

W
wusongqing 已提交
351
**示例:**
352 353

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

360
### seek<a name=audioplayer_seek></a>
Z
zengyawen 已提交
361

Z
zengyawen 已提交
362
seek(timeMs: number): void
Z
zengyawen 已提交
363

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

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

W
wusongqing 已提交
368
**参数:**
B
bird_j 已提交
369

Z
zengyawen 已提交
370 371 372
| 参数名 | 类型   | 必填 | 说明                                 |
| ------ | ------ | ---- | ------------------------------------ |
| timeMs | number | 是   | 指定的跳转时间节点,单位毫秒(ms)。 |
Z
zengyawen 已提交
373

W
wusongqing 已提交
374
**示例:**
Z
zengyawen 已提交
375

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

387
### setVolume<a name=audioplayer_setvolume></a>
Z
zengyawen 已提交
388

Z
zengyawen 已提交
389
setVolume(vol: number): void
Z
zengyawen 已提交
390

W
wusongqing 已提交
391
设置音量。
B
bird_j 已提交
392

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

W
wusongqing 已提交
395
**参数:**
Z
zengyawen 已提交
396

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

W
wusongqing 已提交
401
**示例:**
Z
zengyawen 已提交
402

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

410
### release<a name=audioplayer_release></a>
Z
zengyawen 已提交
411

412
release(): void
Z
zengyawen 已提交
413

W
wusongqing 已提交
414
释放音频资源。
B
bird_j 已提交
415

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

W
wusongqing 已提交
418
**示例:**
Z
zengyawen 已提交
419

420 421 422
```js
audioPlayer.release();
audioPlayer = undefined;
Z
zengyawen 已提交
423
```
Z
zengyawen 已提交
424

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

Z
zengyawen 已提交
427
getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void
Z
zengyawen 已提交
428

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

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

W
wusongqing 已提交
433
**参数:**
B
bird_j 已提交
434

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

W
wusongqing 已提交
439
**示例:**
Z
zengyawen 已提交
440

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
```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 已提交
459
```
460 461 462

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

Z
zengyawen 已提交
463
getTrackDescription(): Promise<Array\<MediaDescription>>
464

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

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

W
wusongqing 已提交
469
**返回值:**
470

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

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

```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 已提交
502 503
```

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

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

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

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

W
wusongqing 已提交
512
**参数:**
B
bird_j 已提交
513

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

W
wusongqing 已提交
519
**示例:**
Z
zengyawen 已提交
520

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

Z
zengyawen 已提交
528
 ### on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')<a name = audioplayer_on></a>
529 530 531

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

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

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

W
wusongqing 已提交
536
**参数:**
537

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

W
wusongqing 已提交
543
**示例:**
544 545

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

// 用户选择视频设置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 已提交
598 599 600 601 602
```

### on('timeUpdate')

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

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

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

W
wusongqing 已提交
608
**参数:**
B
bird_j 已提交
609

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

W
wusongqing 已提交
615
**示例:**
Z
zengyawen 已提交
616

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

### on('error')

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

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

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

W
wusongqing 已提交
636
**参数:**
Z
zengyawen 已提交
637

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

W
wusongqing 已提交
643
**示例:**
Z
zengyawen 已提交
644

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

## AudioState
Z
zengyawen 已提交
655

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

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

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

668 669
## VideoPlayer<sup>8+</sup>

Z
zengyawen 已提交
670
视频播放管理类,用于管理和播放视频媒体。在调用VideoPlayer的方法前,需要先通过[createVideoPlayer()](#mediacreatevideoplayer8)构建一个[VideoPlayer](#videoplayer8)实例。
671

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

Z
zengyawen 已提交
674
### 属性<a name=videoplayer_属性></a>
675

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

| 名称                     | 类型                               | 可读 | 可写 | 说明                                                         |
| ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
Z
zengyawen 已提交
680
| url<sup>8+</sup>         | string                             | 是   | 是   | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。<br>**支持路径示例**<br>1. fd类型播放:fd://xx<br>![](figures/zh-cn_image_url.png)<br>2、http网络播放: http://xx<br/>3、hls网络播放路径:开发中<br/>**注意事项**<br>使用媒体素材需要获取读权限,否则无法正常播放。 |
Z
zengyawen 已提交
681 682 683 684 685 686
| 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                             | 是   | 否   | 视频高。                                                     |
687 688 689 690 691

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

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

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

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

W
wusongqing 已提交
696
**参数:**
697

W
wusongqing 已提交
698
| 参数名    | 类型     | 必填 | 说明                      |
699
| --------- | -------- | ---- | ------------------------- |
W
wusongqing 已提交
700 701
| surfaceId | string   | 是   | SurfaceId                 |
| callback  | function | 是   | 设置SurfaceId的回调方法。 |
702

W
wusongqing 已提交
703
**示例:**
704 705 706

```js
videoPlayer.setDisplaySurface(surfaceId, (err) => {
A
tab  
abc12133 已提交
707 708 709
    if (typeof (err) == 'undefined') {
        console.info('setDisplaySurface success!');
    } else {
710 711 712 713 714 715 716 717 718
        console.info('setDisplaySurface fail!');
    }
});
```

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

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

W
wusongqing 已提交
719
通过Promise方式设置SurfaceId。
720

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

W
wusongqing 已提交
723
**参数:**
B
bird_j 已提交
724

W
wusongqing 已提交
725
| 参数名    | 类型   | 必填 | 说明      |
726
| --------- | ------ | ---- | --------- |
W
wusongqing 已提交
727
| surfaceId | string | 是   | SurfaceId |
728

W
wusongqing 已提交
729
**返回值:**
730

W
wusongqing 已提交
731
| 类型          | 说明                           |
732
| ------------- | ------------------------------ |
W
wusongqing 已提交
733
| Promise<void> | 设置SurfaceId的Promise返回值。 |
734

W
wusongqing 已提交
735
**示例:**
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752

```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 已提交
753
通过回调方式准备播放视频。
B
bird_j 已提交
754

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

W
wusongqing 已提交
757
**参数:**
758

W
wusongqing 已提交
759
| 参数名   | 类型     | 必填 | 说明                     |
760
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
761
| callback | function | 是   | 准备播放视频的回调方法。 |
762

W
wusongqing 已提交
763
**示例:**
764 765 766

```js
videoPlayer.prepare((err) => {
A
tab  
abc12133 已提交
767 768 769
    if (typeof (err) == 'undefined') {
        console.info('prepare success!');
    } else {
770 771 772 773 774 775 776 777 778
        console.info('prepare fail!');
    }
});
```

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

prepare(): Promise\<void>

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

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

W
wusongqing 已提交
783
**返回值:**
B
bird_j 已提交
784

W
wusongqing 已提交
785
| 类型           | 说明                          |
786
| -------------- | ----------------------------- |
W
wusongqing 已提交
787
| Promise\<void> | 准备播放视频的Promise返回值。 |
788

W
wusongqing 已提交
789
**示例:**
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806

```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 已提交
807
通过回调方式开始播放视频。
B
bird_j 已提交
808

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

W
wusongqing 已提交
811
**参数:**
812

W
wusongqing 已提交
813
| 参数名   | 类型     | 必填 | 说明                     |
814
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
815
| callback | function | 是   | 开始播放视频的回调方法。 |
816

W
wusongqing 已提交
817
**示例:**
818 819 820

```js
videoPlayer.play((err) => {
A
tab  
abc12133 已提交
821 822 823
    if (typeof (err) == 'undefined') {
        console.info('play success!');
    } else {
824 825 826 827 828 829 830 831 832
        console.info('play fail!');
    }
});
```

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

play(): Promise\<void>;

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

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

W
wusongqing 已提交
837
**返回值:**
B
bird_j 已提交
838

W
wusongqing 已提交
839
| 类型           | 说明                          |
840
| -------------- | ----------------------------- |
W
wusongqing 已提交
841
| Promise\<void> | 开始播放视频的Promise返回值。 |
842

W
wusongqing 已提交
843
**示例:**
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860

```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 已提交
861
通过回调方式暂停播放视频。
B
bird_j 已提交
862

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

W
wusongqing 已提交
865
**参数:**
866

W
wusongqing 已提交
867
| 参数名   | 类型     | 必填 | 说明                     |
868
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
869
| callback | function | 是   | 暂停播放视频的回调方法。 |
870

W
wusongqing 已提交
871
**示例:**
872 873 874

```js
videoPlayer.pause((err) => {
A
tab  
abc12133 已提交
875 876 877
    if (typeof (err) == 'undefined') {
        console.info('pause success!');
    } else {
878 879 880 881 882 883 884 885 886
        console.info('pause fail!');
    }
});
```

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

pause(): Promise\<void>

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

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

W
wusongqing 已提交
891
**返回值:**
B
bird_j 已提交
892

W
wusongqing 已提交
893
| 类型           | 说明                          |
894
| -------------- | ----------------------------- |
W
wusongqing 已提交
895
| Promise\<void> | 暂停播放视频的Promise返回值。 |
896

W
wusongqing 已提交
897
**示例:**
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914

```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 已提交
915
通过回调方式停止播放视频。
B
bird_j 已提交
916

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

W
wusongqing 已提交
919
**参数:**
920

W
wusongqing 已提交
921
| 参数名   | 类型     | 必填 | 说明                     |
922
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
923
| callback | function | 是   | 停止播放视频的回调方法。 |
924

W
wusongqing 已提交
925
**示例:**
926 927 928

```js
videoPlayer.stop((err) => {
A
tab  
abc12133 已提交
929 930 931
    if (typeof (err) == 'undefined') {
        console.info('stop success!');
    } else {
932 933 934 935 936 937 938 939 940
        console.info('stop fail!');
    }
});
```

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

stop(): Promise\<void>

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

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

W
wusongqing 已提交
945
**返回值:**
946

W
wusongqing 已提交
947
| 类型           | 说明                          |
948
| -------------- | ----------------------------- |
W
wusongqing 已提交
949
| Promise\<void> | 停止播放视频的Promise返回值。 |
950

W
wusongqing 已提交
951
**示例:**
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968

```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 已提交
969
通过回调方式切换播放视频。
970

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

W
wusongqing 已提交
973
**参数:**
B
bird_j 已提交
974

W
wusongqing 已提交
975
| 参数名   | 类型     | 必填 | 说明                     |
976
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
977
| callback | function | 是   | 切换播放视频的回调方法。 |
978

W
wusongqing 已提交
979
**示例:**
980 981 982

```js
videoPlayer.reset((err) => {
A
tab  
abc12133 已提交
983 984 985
    if (typeof (err) == 'undefined') {
        console.info('reset success!');
    } else {
986 987 988 989 990 991 992 993 994
        console.info('reset fail!');
    }
});
```

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

reset(): Promise\<void>

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

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

W
wusongqing 已提交
999
**返回值:**
1000

W
wusongqing 已提交
1001
| 类型           | 说明                          |
1002
| -------------- | ----------------------------- |
W
wusongqing 已提交
1003
| Promise\<void> | 切换播放视频的Promise返回值。 |
1004

W
wusongqing 已提交
1005
**示例:**
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022

```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 已提交
1023
通过回调方式跳转到指定播放位置,默认跳转到指定时间点的下一个关键帧。
1024

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

W
wusongqing 已提交
1027
**参数:**
B
bird_j 已提交
1028

Z
zengyawen 已提交
1029 1030 1031 1032
| 参数名   | 类型     | 必填 | 说明                                 |
| -------- | -------- | ---- | ------------------------------------ |
| timeMs   | number   | 是   | 指定的跳转时间节点,单位毫秒(ms)。 |
| callback | function | 是   | 跳转到指定播放位置的回调方法。       |
1033

W
wusongqing 已提交
1034
**示例:**
1035 1036 1037

```js
videoPlayer.seek((seekTime, err) => {
A
tab  
abc12133 已提交
1038 1039 1040
    if (typeof (err) == 'undefined') {
        console.info('seek success!');
    } else {
1041 1042 1043 1044 1045 1046 1047 1048 1049
        console.info('seek fail!');
    }
});
```

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

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

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

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

W
wusongqing 已提交
1054
**参数:**
1055

Z
zengyawen 已提交
1056 1057 1058 1059 1060
| 参数名   | 类型                   | 必填 | 说明                                 |
| -------- | ---------------------- | ---- | ------------------------------------ |
| timeMs   | number                 | 是   | 指定的跳转时间节点,单位毫秒(ms)。 |
| mode     | [SeekMode](#seekmode8) | 是   | 跳转模式。                           |
| callback | function               | 是   | 跳转到指定播放位置的回调方法。       |
1061

W
wusongqing 已提交
1062
**示例:**
1063 1064 1065

```js
videoPlayer.seek((seekTime, seekMode, err) => {
A
tab  
abc12133 已提交
1066 1067 1068
    if (typeof (err) == 'undefined') {
        console.info('seek success!');
    } else {
1069 1070 1071 1072 1073 1074 1075 1076 1077
        console.info('seek fail!');
    }
});
```

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

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

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

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

W
wusongqing 已提交
1082
**参数:**
B
bird_j 已提交
1083

Z
zengyawen 已提交
1084 1085 1086 1087
| 参数名 | 类型                   | 必填 | 说明                                 |
| ------ | ---------------------- | ---- | ------------------------------------ |
| timeMs | number                 | 是   | 指定的跳转时间节点,单位毫秒(ms)。 |
| mode   | [SeekMode](#seekmode8) | 否   | 跳转模式。                           |
1088

W
wusongqing 已提交
1089
**返回值:**
1090

W
wusongqing 已提交
1091
| 类型           | 说明                                |
1092
| -------------- | ----------------------------------- |
W
wusongqing 已提交
1093
| Promise\<void> | 跳转到指定播放位置的Promise返回值。 |
1094

W
wusongqing 已提交
1095
**示例:**
1096 1097 1098 1099 1100 1101 1102 1103

```js
function failureCallback(error) {
    console.info(`video failureCallback, error:${error.message}`);
}
function catchCallback(error) {
    console.info(`video catchCallback, error:${error.message}`);
}
W
wusongqing 已提交
1104
await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
    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 已提交
1117
通过回调方式设置音量。
B
bird_j 已提交
1118

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

W
wusongqing 已提交
1121
**参数:**
1122

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

W
wusongqing 已提交
1128
**示例:**
1129 1130 1131

```js
videoPlayer.setVolume((vol, err) => {
A
tab  
abc12133 已提交
1132 1133 1134
    if (typeof (err) == 'undefined') {
        console.info('setVolume success!');
    } else {
1135 1136 1137 1138 1139 1140 1141 1142 1143
        console.info('setVolume fail!');
    }
});
```

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

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

W
wusongqing 已提交
1144
通过Promise方式设置音量。
1145

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

W
wusongqing 已提交
1148
**参数:**
B
bird_j 已提交
1149

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

W
wusongqing 已提交
1154
**返回值:**
1155

W
wusongqing 已提交
1156
| 类型           | 说明                      |
1157
| -------------- | ------------------------- |
W
wusongqing 已提交
1158
| Promise\<void> | 设置音量的Promise返回值。 |
1159

W
wusongqing 已提交
1160
**示例:**
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177

```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 已提交
1178
通过回调方式释放视频资源。
B
bird_j 已提交
1179

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

W
wusongqing 已提交
1182
**参数:**
1183

W
wusongqing 已提交
1184
| 参数名   | 类型     | 必填 | 说明                     |
1185
| -------- | -------- | ---- | ------------------------ |
W
wusongqing 已提交
1186
| callback | function | 是   | 释放视频资源的回调方法。 |
1187

W
wusongqing 已提交
1188
**示例:**
1189 1190 1191

```js
videoPlayer.release((err) => {
A
tab  
abc12133 已提交
1192 1193 1194
    if (typeof (err) == 'undefined') {
        console.info('release success!');
    } else {
1195 1196 1197 1198 1199 1200 1201 1202 1203
        console.info('release fail!');
    }
});
```

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

release(): Promise\<void>

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

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

W
wusongqing 已提交
1208
**返回值:**
1209

W
wusongqing 已提交
1210
| 类型           | 说明                          |
1211
| -------------- | ----------------------------- |
W
wusongqing 已提交
1212
| Promise\<void> | 释放视频资源的Promise返回值。 |
1213

W
wusongqing 已提交
1214
**示例:**
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229

```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>

Z
zengyawen 已提交
1230
getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void
1231

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

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

W
wusongqing 已提交
1236
**参数:**
B
bird_j 已提交
1237

Z
zengyawen 已提交
1238 1239 1240
| 参数名   | 类型                                                         | 必填 | 说明                       |
| -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | 是   | 获取视频轨道信息回调方法。 |
1241

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

```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>

Z
zengyawen 已提交
1266
getTrackDescription(): Promise<Array\<MediaDescription>>
1267

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

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

W
wusongqing 已提交
1272
**返回值:**
1273

Z
zengyawen 已提交
1274 1275 1276
| 类型                                                   | 说明                            |
| ------------------------------------------------------ | ------------------------------- |
| Promise<Array<[MediaDescription](#mediadescription8)>> | 获取视频轨道信息Promise返回值。 |
1277

W
wusongqing 已提交
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 1308 1309 1310 1311

```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 已提交
1312
通过回调方式设置播放速度。
1313

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

W
wusongqing 已提交
1316
**参数:**
B
bird_j 已提交
1317

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

W
wusongqing 已提交
1323
**示例:**
1324 1325 1326

```js
videoPlayer.setSpeed((speed:number, err) => {
A
tab  
abc12133 已提交
1327 1328 1329
    if (typeof (err) == 'undefined') {
        console.info('setSpeed success!');
    } else {
1330 1331 1332 1333 1334 1335 1336 1337 1338
        console.info('setSpeed fail!');
    }
});
```

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

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

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

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

W
wusongqing 已提交
1343
**参数:**
1344

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

Z
zengyawen 已提交
1349 1350 1351 1352 1353 1354
**返回值:**

| 类型             | 说明                      |
| ---------------- | ------------------------- |
| Promise\<number> | 通过Promise获取设置结果。 |

W
wusongqing 已提交
1355
**示例:**
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372

```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 已提交
1373
开始监听视频播放完成事件。
1374

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

W
wusongqing 已提交
1377
**参数:**
B
bird_j 已提交
1378

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

W
wusongqing 已提交
1384
**示例:**
1385 1386 1387

```js
videoPlayer.on('playbackCompleted', () => {
A
tab  
abc12133 已提交
1388
    console.info('playbackCompleted success!');
1389 1390 1391 1392 1393 1394 1395
});
```

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

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

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

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

W
wusongqing 已提交
1400
**参数:**
1401

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

W
wusongqing 已提交
1407
**示例:**
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

```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 已提交
1420
开始监听视频播放首帧送显上报事件。
1421

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

W
wusongqing 已提交
1424
**参数:**
B
bird_j 已提交
1425

Z
zengyawen 已提交
1426 1427 1428 1429
| 参数名   | 类型            | 必填 | 说明                                                         |
| -------- | --------------- | ---- | ------------------------------------------------------------ |
| type     | string          | 是   | 视频播放首帧送显上报事件回调类型,支持的事件:'startRenderFrame'。 |
| callback | Callback\<void> | 是   | 视频播放首帧送显上报事件回调方法。                           |
1430

W
wusongqing 已提交
1431
**示例:**
1432 1433 1434

```js
videoPlayer.on('startRenderFrame', () => {
A
tab  
abc12133 已提交
1435
    console.info('startRenderFrame success!');
1436 1437 1438 1439 1440 1441 1442
});
```

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

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

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

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

W
wusongqing 已提交
1447
**参数:**
1448

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

W
wusongqing 已提交
1454
**示例:**
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466

```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 已提交
1467
开始监听视频播放错误事件。
B
bird_j 已提交
1468

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

W
wusongqing 已提交
1471
**参数:**
1472

Z
zengyawen 已提交
1473 1474 1475 1476
| 参数名   | 类型          | 必填 | 说明                                                         |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
| type     | string        | 是   | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':视频播放中发生错误,触发该事件。 |
| callback | ErrorCallback | 是   | 播放错误事件回调方法。                                       |
1477

W
wusongqing 已提交
1478
**示例:**
1479 1480

```js
W
wusongqing 已提交
1481
videoPlayer.on('error', (error) => {      // 设置'error'事件回调
A
tab  
abc12133 已提交
1482
    console.info(`video error called, errName is ${error.name}`);      // 打印错误类型名称
W
wusongqing 已提交
1483 1484
    console.info(`video error called, errCode is ${error.code}`);      // 打印错误码
    console.info(`video error called, errMessage is ${error.message}`);// 打印错误类型详细描述
1485
});
W
wusongqing 已提交
1486
videoPlayer.setVolume(3);  //设置volume为无效值,触发'error'事件
1487 1488 1489 1490
```

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

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

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

W
wusongqing 已提交
1495 1496 1497 1498 1499 1500 1501 1502
| 名称     | 类型   | 描述           |
| -------- | ------ | -------------- |
| idle     | string | 视频播放空闲。 |
| prepared | string | 视频播放准备。 |
| playing  | string | 视频正在播放。 |
| paused   | string | 视频暂停播放。 |
| stopped  | string | 视频播放停止。 |
| error    | string | 错误状态。     |
1503 1504 1505

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

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

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

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

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

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

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

W
wusongqing 已提交
1521 1522 1523 1524 1525 1526 1527
| 名称                 | 值   | 描述                           |
| -------------------- | ---- | ------------------------------ |
| 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倍。 |
1528

1529 1530
## MediaDescription<sup>8+</sup>

Z
zengyawen 已提交
1531
### [key : string] : Object
Z
zengyawen 已提交
1532

Z
zengyawen 已提交
1533 1534 1535
通过key-value方式获取媒体信息。

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

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

W
wusongqing 已提交
1542
**示例:**
1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553

```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 已提交
1554
            printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE);  //打印出每条轨道MD_KEY_TRACK_TYPE的值
1555 1556 1557 1558 1559 1560
        }
    } else {
        console.log(`audio getTrackDescription fail, error:${error.message}`);
    }
});
```
Z
zengyawen 已提交
1561 1562 1563

## AudioRecorder

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

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

### prepare<a name=audiorecorder_prepare></a>
Z
zengyawen 已提交
1569 1570 1571

prepare(config: AudioRecorderConfig): void

W
wusongqing 已提交
1572
录音准备。
Z
zengyawen 已提交
1573

Z
zengyawen 已提交
1574 1575 1576 1577
**需要权限:** ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1578
**参数:**
B
bird_j 已提交
1579

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

W
wusongqing 已提交
1584
**示例:**
Z
zengyawen 已提交
1585

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


1603
### start<a name=audiorecorder_start></a>
Z
zengyawen 已提交
1604 1605 1606

start(): void

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

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

W
wusongqing 已提交
1611
**示例:**
Z
zengyawen 已提交
1612

1613
```js
W
wusongqing 已提交
1614
audioRecorder.on('start', () => {    //设置'start'事件回调
1615 1616 1617
    console.log('audio recorder start success');
});
audioRecorder.start();
Z
zengyawen 已提交
1618
```
1619 1620 1621 1622 1623

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

pause():void

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

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

W
wusongqing 已提交
1628
**示例:**
1629 1630

```js
W
wusongqing 已提交
1631
audioRecorder.on('pause', () => {    //设置'pause'事件回调
1632 1633 1634 1635 1636 1637 1638 1639 1640
    console.log('audio recorder pause success');
});
audioRecorder.pause();
```

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

resume():void

Z
zengyawen 已提交
1641
恢复录制,需要在[pause](#audiorecorder_on)事件成功触发后,才能调用resume方法。
B
bird_j 已提交
1642

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

W
wusongqing 已提交
1645
**示例:**
1646 1647

```js
W
wusongqing 已提交
1648
audioRecorder.on('resume', () => {    //设置'resume'事件回调
1649 1650 1651
    console.log('audio recorder resume success');
});
audioRecorder.resume();
Z
zengyawen 已提交
1652 1653
```

1654
### stop<a name=audiorecorder_stop></a>
Z
zengyawen 已提交
1655 1656 1657

stop(): void

W
wusongqing 已提交
1658
停止录音。
Z
zengyawen 已提交
1659

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

W
wusongqing 已提交
1662
**示例:**
Z
zengyawen 已提交
1663

1664
```js
W
wusongqing 已提交
1665
audioRecorder.on('stop', () => {    //设置'stop'事件回调
1666 1667 1668
    console.log('audio recorder stop success');
});
audioRecorder.stop();
Z
zengyawen 已提交
1669 1670
```

1671
### release<a name=audiorecorder_release></a>
Z
zengyawen 已提交
1672 1673 1674

release(): void

W
wusongqing 已提交
1675
释放录音资源。
B
bird_j 已提交
1676

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

W
wusongqing 已提交
1679
**示例:**
Z
zengyawen 已提交
1680

1681
```js
W
wusongqing 已提交
1682
audioRecorder.on('release', () => {    //设置'release'事件回调
B
bird_j 已提交
1683 1684
    console.log('audio recorder release success');
});
1685 1686
audioRecorder.release();
audioRecorder = undefined;
Z
zengyawen 已提交
1687 1688
```

1689
### reset<a name=audiorecorder_reset></a>
Z
zengyawen 已提交
1690 1691 1692

reset(): void

W
wusongqing 已提交
1693
重置录音。
Z
zengyawen 已提交
1694

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

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

W
wusongqing 已提交
1699
**示例:**
Z
zengyawen 已提交
1700

B
bird_j 已提交
1701
```js
W
wusongqing 已提交
1702
audioRecorder.on('reset', () => {    //设置'reset'事件回调
B
bird_j 已提交
1703 1704 1705
    console.log('audio recorder reset success');
});
audioRecorder.reset();
Z
zengyawen 已提交
1706 1707
```

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

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

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

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

W
wusongqing 已提交
1716
**参数:**
B
bird_j 已提交
1717

W
wusongqing 已提交
1718
| 参数名   | 类型     | 必填 | 说明                                                         |
Z
zengyawen 已提交
1719
| -------- | -------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1720 1721
| 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 已提交
1722

W
wusongqing 已提交
1723
**示例:**
Z
zengyawen 已提交
1724

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

### on('error')

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

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

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

W
wusongqing 已提交
1774
**参数:**
Z
zengyawen 已提交
1775

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

W
wusongqing 已提交
1781
**示例:**
1782 1783

```js
A
tab  
abc12133 已提交
1784 1785
audioRecorder.on('error', (error) => {                                  // 设置'error'事件回调
    console.info(`audio error called, errName is ${error.name}`);       // 打印错误类型名称
W
wusongqing 已提交
1786 1787
    console.info(`audio error called, errCode is ${error.code}`);       // 打印错误码
    console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述
1788
});
A
tab  
abc12133 已提交
1789
audioRecorder.prepare();                                                  // prepare不设置参数,触发'error'事件
1790
```
Z
zengyawen 已提交
1791 1792 1793

## AudioRecorderConfig

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

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

W
wusongqing 已提交
1798
| 名称                  | 参数类型                                | 必填 | 说明                                                         |
1799
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1800 1801 1802 1803
| audioEncoder          | [AudioEncoder](#audioencoder)           | 否   | 音频编码格式,默认设置为AAC_LC。                             |
| audioEncodeBitRate    | number                                  | 否   | 音频编码比特率,默认值为48000。                              |
| audioSampleRate       | number                                  | 否   | 音频采集采样率,默认值为48000。                              |
| numberOfChannels      | number                                  | 否   | 音频采集声道数,默认值为2。                                  |
A
abc 已提交
1804
| format                | [AudioOutputFormat](#audiooutputformat) | 否   | 音频输出封装格式,默认设置为MPEG_4。                         |
1805 1806
| location              | [Location](#location)                   | 否   | 音频采集的地理位置。                                         |
| uri                   | string                                  | 是   | 音频输出URI:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
Z
zengyawen 已提交
1807
| audioEncoderMime      | [CodecMimeType](#codecmimetype8)        | 否   | 音频编码格式。                                               |
Z
zengyawen 已提交
1808 1809


A
1  
abc12133 已提交
1810
## AudioEncoder<sup>(deprecated)</sup>
Z
zengyawen 已提交
1811

A
add dep  
abc12133 已提交
1812 1813 1814
> **说明:**
> 从 API Version 8 开始废弃,建议使用[CodecMimeType](#codecmimetype8)替代。

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

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

W
wusongqing 已提交
1819
| 名称    | 默认值 | 说明                                                         |
B
bird_j 已提交
1820
| ------- | ------ | ------------------------------------------------------------ |
A
abc 已提交
1821 1822 1823
| DEFAULT | 0      | 默认编码格式。<br/>仅做接口定义,暂不支持使用。 |
| AMR_NB  | 1      | AMR-NB(Adaptive Multi Rate-Narrow Band Speech Codec) 编码格式。<br/>仅做接口定义,暂不支持使用。 |
| AMR_WB  | 2      | AMR-WB(Adaptive Multi Rate-Wide Band Speech Codec) 编码格式。<br/>仅做接口定义,暂不支持使用。 |
Z
zengyawen 已提交
1824
| AAC_LC  | 3      | AAC-LC(Advanced&nbsp;Audio&nbsp;Coding&nbsp;Low&nbsp;Complexity)编码格式。 |
A
abc 已提交
1825
| HE_AAC  | 4      | HE_AAC(High-Efficiency Advanced&nbsp;Audio&nbsp;Coding)编码格式。<br/>仅做接口定义,暂不支持使用。 |
Z
zengyawen 已提交
1826 1827


A
1  
abc12133 已提交
1828
## AudioOutputFormat<sup>(deprecated)</sup>
Z
zengyawen 已提交
1829

A
add dep  
abc12133 已提交
1830 1831 1832
> **说明:**
> 从 API Version 8 开始废弃,建议使用[ContainerFormatType ](#containerformattype8)替代。

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

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

W
wusongqing 已提交
1837
| 名称     | 默认值 | 说明                                                         |
Z
zengyawen 已提交
1838
| -------- | ------ | ------------------------------------------------------------ |
A
abc 已提交
1839
| DEFAULT  | 0      | 默认封装格式。<br/>仅做接口定义,暂不支持使用。 |
Z
zengyawen 已提交
1840
| MPEG_4   | 2      | 封装为MPEG-4格式。                                           |
A
abc 已提交
1841 1842
| AMR_NB   | 3      | 封装为AMR_NB格式。<br/>仅做接口定义,暂不支持使用。 |
| AMR_WB   | 4      | 封装为AMR_WB格式。<br/>仅做接口定义,暂不支持使用。 |
Z
zengyawen 已提交
1843
| AAC_ADTS | 6      | 封装为ADTS(Audio&nbsp;Data&nbsp;Transport&nbsp;Stream)格式,是AAC音频的传输流格式。 |
1844

1845
## VideoRecorder<sup>9+</sup>
1846

1847
视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorder()](#mediacreatevideorecorder9)构建一个[VideoRecorder](#videorecorder9)实例。
1848

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

W
wusongqing 已提交
1851
### 属性
1852

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

| 名称               | 类型                                   | 可读 | 可写 | 说明             |
| ------------------ | -------------------------------------- | ---- | ---- | ---------------- |
1857
| state<sup>8+</sup> | [VideoRecordState](#videorecordstate9) | 是   | 否   | 视频录制的状态。 |
1858

1859
### prepare<sup>9+</sup><a name=videorecorder_prepare1></a>
1860 1861 1862

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

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

A
1  
abc12133 已提交
1865
**需要权限:** ohos.permission.MICROPHONE
Z
zengyawen 已提交
1866 1867 1868

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

W
wusongqing 已提交
1869
**参数:**
B
bird_j 已提交
1870

1871 1872
| 参数名   | 类型                                         | 必填 | 说明                                |
| -------- | -------------------------------------------- | ---- | ----------------------------------- |
1873
| config   | [VideoRecorderConfig](#videorecorderconfig9) | 是   | 配置视频录制的相关参数。            |
1874
| callback | AsyncCallback\<void>                         | 是   | 异步视频录制prepare方法的回调方法。 |
1875

W
wusongqing 已提交
1876
**示例:**
1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895

```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 已提交
1896
    url : 'fd://xx',   // 文件需先由调用者创建,并给予适当的权限
1897 1898 1899 1900 1901 1902 1903
    orientationHint : 0,
    location : { latitude : 30, longitude : 130 },
}

// asyncallback
let videoRecorder = null;
let events = require('events');
A
amr  
abc12133 已提交
1904
let eventEmitter = new events.EventEmitter();
1905 1906 1907 1908

eventEmitter.on('prepare', () => {
    videoRecorder.prepare(videoConfig, (err) => {
        if (typeof (err) == 'undefined') {
B
bird_j 已提交
1909
            console.info('prepare success');
1910
        } else {
B
bird_j 已提交
1911
            console.info('prepare failed and error is ' + err.message);
1912 1913 1914 1915 1916 1917
        }
    });
});

media.createVideoRecorder((err, recorder) => {
    if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') {
B
bird_j 已提交
1918 1919
        videoRecorder = recorder;
        console.info('createVideoRecorder success');
W
wusongqing 已提交
1920
        eventEmitter.emit('prepare');                                        // prepare事件触发
1921
    } else {
B
bird_j 已提交
1922
        console.info('createVideoRecorder failed and error is ' + err.message);
1923 1924 1925 1926
    }
});
```

1927
### prepare<sup>9+</sup><a name=videorecorder_prepare2></a>
1928 1929 1930

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

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

Z
zengyawen 已提交
1933
**需要权限:** ohos.permission.MICROPHONE,ohos.permission.CAMERA
Z
zengyawen 已提交
1934 1935 1936

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

W
wusongqing 已提交
1937
**参数:**
1938

1939 1940
| 参数名 | 类型                                         | 必填 | 说明                     |
| ------ | -------------------------------------------- | ---- | ------------------------ |
1941
| config | [VideoRecorderConfig](#videorecorderconfig9) | 是   | 配置视频录制的相关参数。 |
1942

W
wusongqing 已提交
1943
**返回值:**
1944

W
wusongqing 已提交
1945
| 类型           | 说明                                     |
1946
| -------------- | ---------------------------------------- |
W
wusongqing 已提交
1947
| Promise\<void> | 异步视频录制prepare方法的Promise返回值。 |
1948

W
wusongqing 已提交
1949
**示例:**
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968

```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 已提交
1969
    url : 'fd://xx',   // 文件需先由调用者创建,并给予适当的权限
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
    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);
});
```

1998
### getInputSurface<sup>9+</sup>
1999 2000 2001

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

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

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

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

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

W
wusongqing 已提交
2010
**参数:**
B
bird_j 已提交
2011

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

W
wusongqing 已提交
2016
**示例:**
2017 2018 2019

```js
// asyncallback
A
tab  
abc12133 已提交
2020
let surfaceID = null;                                               // 传递给外界的surfaceID
B
bird_j 已提交
2021 2022 2023
videoRecorder.getInputSurface((err, surfaceId) => {
    if (typeof (err) == 'undefined') {
        console.info('getInputSurface success');
B
bird_j 已提交
2024
        surfaceID = surfaceId;
B
bird_j 已提交
2025 2026 2027
    } else {
        console.info('getInputSurface failed and error is ' + err.message);
    }
2028 2029 2030
});
```

2031
### getInputSurface<sup>9+</sup>
2032 2033 2034

getInputSurface(): Promise\<string>;

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

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

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

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

W
wusongqing 已提交
2043
**返回值:**
2044

W
wusongqing 已提交
2045
| 类型             | 说明                             |
2046
| ---------------- | -------------------------------- |
W
wusongqing 已提交
2047
| Promise\<string> | 异步获得surface的Promise返回值。 |
2048

W
wusongqing 已提交
2049
**示例:**
2050 2051 2052

```js
// promise
A
tab  
abc12133 已提交
2053
let surfaceID = null;                                               // 传递给外界的surfaceID
B
bird_j 已提交
2054
await videoRecorder.getInputSurface().then((surfaceId) => {
2055
    console.info('getInputSurface success');
B
bird_j 已提交
2056
    surfaceID = surfaceId;
2057 2058 2059 2060 2061 2062 2063
}, (err) => {
    console.info('getInputSurface failed and error is ' + err.message);
}).catch((err) => {
    console.info('getInputSurface failed and catch error is ' + err.message);
});
```

2064
### start<sup>9+</sup><a name=videorecorder_start1></a>
2065 2066 2067

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

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

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

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

W
wusongqing 已提交
2074
**参数:**
2075

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

W
wusongqing 已提交
2080
**示例:**
2081 2082 2083

```js
// asyncallback
B
bird_j 已提交
2084 2085 2086 2087 2088 2089
videoRecorder.start((err) => {
    if (typeof (err) == 'undefined') {
        console.info('start videorecorder success');
    } else {
        console.info('start videorecorder failed and error is ' + err.message);
    }
2090 2091 2092
});
```

2093
### start<sup>9+</sup><a name=videorecorder_start2></a>
2094 2095 2096

start(): Promise\<void>;

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

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

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

W
wusongqing 已提交
2103
**返回值:**
B
bird_j 已提交
2104

W
wusongqing 已提交
2105
| 类型           | 说明                                  |
2106
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2107
| Promise\<void> | 异步开始视频录制方法的Promise返回值。 |
2108

W
wusongqing 已提交
2109
**示例:**
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121

```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);
});
```

2122
### pause<sup>9+</sup><a name=videorecorder_pause1></a>
2123 2124 2125

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

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

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

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

W
wusongqing 已提交
2132
**参数:**
2133

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

W
wusongqing 已提交
2138
**示例:**
2139 2140 2141

```js
// asyncallback
B
bird_j 已提交
2142 2143 2144 2145 2146 2147
videoRecorder.pause((err) => {
    if (typeof (err) == 'undefined') {
        console.info('pause videorecorder success');
    } else {
        console.info('pause videorecorder failed and error is ' + err.message);
    }
2148 2149 2150
});
```

2151
### pause<sup>9+</sup><a name=videorecorder_pause2></a>
2152 2153 2154

pause(): Promise\<void>;

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

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

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

W
wusongqing 已提交
2161
**返回值:**
B
bird_j 已提交
2162

W
wusongqing 已提交
2163
| 类型           | 说明                                  |
2164
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2165
| Promise\<void> | 异步暂停视频录制方法的Promise返回值。 |
2166

W
wusongqing 已提交
2167
**示例:**
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179

```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);
});
```

2180
### resume<sup>9+</sup><a name=videorecorder_resume1></a>
2181 2182 2183

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

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

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

W
wusongqing 已提交
2188
**参数:**
2189

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

W
wusongqing 已提交
2194
**示例:**
2195 2196 2197

```js
// asyncallback
B
bird_j 已提交
2198 2199 2200 2201 2202 2203
videoRecorder.resume((err) => {
    if (typeof (err) == 'undefined') {
        console.info('resume videorecorder success');
    } else {
        console.info('resume videorecorder failed and error is ' + err.message);
    }
2204 2205 2206
});
```

2207
### resume<sup>9+</sup><a name=videorecorder_resume2></a>
2208 2209 2210

resume(): Promise\<void>;

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

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

W
wusongqing 已提交
2215
**返回值:**
B
bird_j 已提交
2216

W
wusongqing 已提交
2217
| 类型           | 说明                                  |
2218
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2219
| Promise\<void> | 异步恢复视频录制方法的Promise返回值。 |
2220

W
wusongqing 已提交
2221
**示例:**
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233

```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);
});
```

2234
### stop<sup>9+</sup><a name=videorecorder_stop1></a>
2235 2236 2237

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

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

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

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

W
wusongqing 已提交
2244
**参数:**
2245

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

W
wusongqing 已提交
2250
**示例:**
2251 2252 2253

```js
// asyncallback
B
bird_j 已提交
2254 2255 2256 2257 2258 2259
videoRecorder.stop((err) => {
    if (typeof (err) == 'undefined') {
        console.info('stop videorecorder success');
    } else {
        console.info('stop videorecorder failed and error is ' + err.message);
    }
2260 2261 2262
});
```

2263
### stop<sup>9+</sup><a name=videorecorder_stop2></a>
2264 2265 2266

stop(): Promise\<void>;

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

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

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

W
wusongqing 已提交
2273
**返回值:**
B
bird_j 已提交
2274

W
wusongqing 已提交
2275
| 类型           | 说明                                  |
2276
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2277
| Promise\<void> | 异步停止视频录制方法的Promise返回值。 |
2278

W
wusongqing 已提交
2279
**示例:**
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291

```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);
});
```

2292
### release<sup>9+</sup><a name=videorecorder_release1></a>
2293 2294 2295

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

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

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

W
wusongqing 已提交
2300
**参数:**
2301

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

W
wusongqing 已提交
2306
**示例:**
2307 2308 2309

```js
// asyncallback
B
bird_j 已提交
2310 2311 2312 2313 2314 2315
videoRecorder.release((err) => {
    if (typeof (err) == 'undefined') {
        console.info('release videorecorder success');
    } else {
        console.info('release videorecorder failed and error is ' + err.message);
    }
2316 2317 2318
});
```

2319
### release<sup>9+</sup><a name=videorecorder_release2></a>
2320 2321 2322

release(): Promise\<void>;

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

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

W
wusongqing 已提交
2327
**返回值:**
2328

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

W
wusongqing 已提交
2333
**示例:**
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345

```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);
});
```

2346
### reset<sup>9+</sup><a name=videorecorder_reset1></a>
2347 2348 2349

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

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

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

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

W
wusongqing 已提交
2356
**参数:**
B
bird_j 已提交
2357

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

W
wusongqing 已提交
2362
**示例:**
2363 2364 2365

```js
// asyncallback
B
bird_j 已提交
2366 2367 2368 2369 2370 2371
videoRecorder.reset((err) => {
    if (typeof (err) == 'undefined') {
        console.info('reset videorecorder success');
    } else {
        console.info('reset videorecorder failed and error is ' + err.message);
    }
2372 2373 2374
});
```

2375
### reset<sup>9+</sup><a name=videorecorder_reset2></a>
2376 2377 2378

reset(): Promise\<void>;

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

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

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

W
wusongqing 已提交
2385
**返回值:**
2386

W
wusongqing 已提交
2387
| 类型           | 说明                                  |
2388
| -------------- | ------------------------------------- |
W
wusongqing 已提交
2389
| Promise\<void> | 异步重置视频录制方法的Promise返回值。 |
2390

W
wusongqing 已提交
2391
**示例:**
2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403

```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);
});
```

2404
### on('error')<sup>9+</sup>
2405 2406 2407

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

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

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

W
wusongqing 已提交
2412
**参数:**
B
bird_j 已提交
2413

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

W
wusongqing 已提交
2419
**示例:**
2420 2421

```js
A
tab  
abc12133 已提交
2422 2423
videoRecorder.on('error', (error) => {                                  // 设置'error'事件回调
    console.info(`audio error called, errName is ${error.name}`);       // 打印错误类型名称
W
wusongqing 已提交
2424 2425
    console.info(`audio error called, errCode is ${error.code}`);       // 打印错误码
    console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述
2426
});
W
wusongqing 已提交
2427
// 当获取videoRecordState接口出错时通过此订阅事件上报
2428 2429
```

2430
## VideoRecordState<sup>9+</sup>
2431

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

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

W
wusongqing 已提交
2436 2437 2438 2439 2440 2441 2442 2443
| 名称     | 类型   | 描述                   |
| -------- | ------ | ---------------------- |
| idle     | string | 视频录制空闲。         |
| prepared | string | 视频录制参数设置完成。 |
| playing  | string | 视频正在录制。         |
| paused   | string | 视频暂停录制。         |
| stopped  | string | 视频录制停止。         |
| error    | string | 错误状态。             |
2444

2445
## VideoRecorderConfig<sup>9+</sup>
2446

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

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

Z
zengyawen 已提交
2451 2452
| 名称            | 参数类型                                       | 必填 | 说明                                                         |
| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
2453 2454 2455
| audioSourceType | [AudioSourceType](#audiosourcetype9)           | 是   | 视频录制的音频源类型。                                       |
| videoSourceType | [VideoSourceType](#videosourcetype9)           | 是   | 视频录制的视频源类型。                                       |
| profile         | [VideoRecorderProfile](#videorecorderprofile9) | 是   | 视频录制的profile。                                          |
Z
zengyawen 已提交
2456
| rotation        | number                                         | 否   | 录制视频的旋转角度。                                         |
2457
| location        | [Location](#location)                          | 否   | 录制视频的地理位置。                                         |
Z
zengyawen 已提交
2458
| url             | string                                         | 是   | 视频输出URL:fd://xx&nbsp;(fd&nbsp;number)<br/>![](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。 |
2459

2460
## AudioSourceType<sup>9+</sup>
2461

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

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

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

2471
## VideoSourceType<sup>9+</sup>
2472

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

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

W
wusongqing 已提交
2477 2478 2479 2480
| 名称                          | 值   | 说明                            |
| ----------------------------- | ---- | ------------------------------- |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0    | 输入surface中携带的是raw data。 |
| VIDEO_SOURCE_TYPE_SURFACE_ES  | 1    | 输入surface中携带的是ES data。  |
2481

2482
## VideoRecorderProfile<sup>9+</sup>
2483

W
wusongqing 已提交
2484
视频录制的配置文件。
2485

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

W
wusongqing 已提交
2488 2489 2490 2491
| 名称             | 参数类型                                     | 必填 | 说明             |
| ---------------- | -------------------------------------------- | ---- | ---------------- |
| audioBitrate     | number                                       | 是   | 音频编码比特率。 |
| audioChannels    | number                                       | 是   | 音频采集声道数。 |
Z
zengyawen 已提交
2492
| audioCodec       | [CodecMimeType](#codecmimetype8)             | 是   | 音频编码格式。   |
W
wusongqing 已提交
2493 2494
| audioSampleRate  | number                                       | 是   | 音频采样率。     |
| fileFormat       | [ContainerFormatType](#containerformattype8) | 是   | 文件的容器格式。 |
2495
| videoBitrate     | number                                       | 是   | 视频编码比特率。 |
Z
zengyawen 已提交
2496
| videoCodec       | [CodecMimeType](#codecmimetype8)             | 是   | 视频编码格式。   |
W
wusongqing 已提交
2497 2498
| videoFrameWidth  | number                                       | 是   | 录制视频帧的宽。 |
| videoFrameHeight | number                                       | 是   | 录制视频帧的高。 |
2499
| videoFrameRate   | number                                       | 是   | 录制视频帧率。   |
2500 2501 2502

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

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

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

W
wusongqing 已提交
2507 2508 2509 2510
| 名称        | 值    | 说明                  |
| ----------- | ----- | --------------------- |
| CFT_MPEG_4  | "mp4" | 视频的容器格式,MP4。 |
| CFT_MPEG_4A | "m4a" | 音频的容器格式,M4A。 |
2511

2512
## Location
2513

W
wusongqing 已提交
2514
视频录制的地理位置。
2515

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

W
wusongqing 已提交
2518 2519 2520 2521
| 名称      | 参数类型 | 必填 | 说明             |
| --------- | -------- | ---- | ---------------- |
| latitude  | number   | 是   | 地理位置的纬度。 |
| longitude | number   | 是   | 地理位置的经度。 |