js-apis-media.md 97.7 KB
Newer Older
W
wusongqing 已提交
1 2
# Media

W
wusongqing 已提交
3
> **NOTE**
W
wusongqing 已提交
4
>
W
wusongqing 已提交
5 6
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.

W
wusongqing 已提交
7 8 9 10 11
The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources.

This subsystem offers various media services covering audio and video, which provide the following capabilities:

- Audio playback ([AudioPlayer](#audioplayer))
W
wusongqing 已提交
12
- Video playback ([VideoPlayer](#videoplayer8))
W
wusongqing 已提交
13
- Audio recording ([AudioRecorder](#audiorecorder))
W
wusongqing 已提交
14
- Video recording ([VideoRecorder](#videorecorder9))
W
wusongqing 已提交
15

W
wusongqing 已提交
16
The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query.
Z
zengyawen 已提交
17 18 19

## Modules to Import

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

W
wusongqing 已提交
24
##  media.createAudioPlayer
Z
zengyawen 已提交
25

W
wusongqing 已提交
26
createAudioPlayer(): [AudioPlayer](#audioplayer)
Z
zengyawen 已提交
27

W
wusongqing 已提交
28
Creates an **AudioPlayer** instance in synchronous mode.
Z
zengyawen 已提交
29

W
wusongqing 已提交
30 31
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
32
**Return value**
Z
zengyawen 已提交
33

W
wusongqing 已提交
34
| Type                       | Description                                                        |
Z
zengyawen 已提交
35
| --------------------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
36 37 38 39 40
| [AudioPlayer](#audioplayer) | Returns the **AudioPlayer** instance if the operation is successful; returns **null** otherwise. After the instance is created, you can start, pause, or stop audio playback.|

**Example**

```js
W
wusongqing 已提交
41
let audioPlayer = media.createAudioPlayer();
W
wusongqing 已提交
42 43
```

W
wusongqing 已提交
44
## media.createVideoPlayer<sup>8+</sup>
W
wusongqing 已提交
45

W
wusongqing 已提交
46
createVideoPlayer(callback: AsyncCallback\<[VideoPlayer](#videoplayer8)>): void
W
wusongqing 已提交
47

W
wusongqing 已提交
48 49 50
Creates a **VideoPlayer** instance in asynchronous mode. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
W
wusongqing 已提交
51 52 53

**Parameters**

W
wusongqing 已提交
54 55 56
| Name  | Type                                       | Mandatory| Description                          |
| -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[VideoPlayer](#videoplayer8)> | Yes  | Callback used to return the **VideoPlayer** instance created.|
Z
zengyawen 已提交
57 58 59

**Example**

W
wusongqing 已提交
60
```js
W
wusongqing 已提交
61 62 63 64 65 66
let videoPlayer

media.createVideoPlayer((error, video) => {
   if (typeof(video) != 'undefined') {
       videoPlayer = video;
       console.info('video createVideoPlayer success');
W
wusongqing 已提交
67
   } else {
W
wusongqing 已提交
68
       console.info(`video createVideoPlayer fail, error:${error.message}`);
W
wusongqing 已提交
69 70
   }
});
Z
zengyawen 已提交
71
```
W
wusongqing 已提交
72

W
wusongqing 已提交
73
## media.createVideoPlayer<sup>8+</sup>
W
wusongqing 已提交
74

W
wusongqing 已提交
75
createVideoPlayer(): Promise<[VideoPlayer](#videoplayer8)>
W
wusongqing 已提交
76

W
wusongqing 已提交
77 78 79
Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
W
wusongqing 已提交
80

W
wusongqing 已提交
81
**Return value**
W
wusongqing 已提交
82

W
wusongqing 已提交
83 84 85
| Type                                 | Description                               |
| ------------------------------------- | ----------------------------------- |
| Promise<[VideoPlayer](#videoplayer8)> | Promise used to return the **VideoPlayer** instance created.|
W
wusongqing 已提交
86 87 88 89

**Example**

```js
W
wusongqing 已提交
90 91
let videoPlayer

W
wusongqing 已提交
92 93
media.createVideoPlayer().then((video) => {
   if (typeof(video) != 'undefined') {
W
wusongqing 已提交
94 95
       videoPlayer = video;
       console.info('video createVideoPlayer success');
W
wusongqing 已提交
96
   } else {
W
wusongqing 已提交
97
       console.info('video createVideoPlayer fail');
W
wusongqing 已提交
98
   }
W
wusongqing 已提交
99 100 101
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
102 103 104
```

## media.createAudioRecorder
W
wusongqing 已提交
105

Z
zengyawen 已提交
106 107
createAudioRecorder(): AudioRecorder

W
wusongqing 已提交
108
Creates an **AudioRecorder** instance to control audio recording.
109
Only one **AudioRecorder** instance can be created per device.
Z
zengyawen 已提交
110

W
wusongqing 已提交
111 112
**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
113
**Return value**
Z
zengyawen 已提交
114

W
wusongqing 已提交
115
| Type                           | Description                                     |
W
wusongqing 已提交
116 117
| ------------------------------- | ----------------------------------------- |
| [AudioRecorder](#audiorecorder) | Returns the **AudioRecorder** instance if the operation is successful; returns **null** otherwise.|
Z
zengyawen 已提交
118 119 120

**Example**

W
wusongqing 已提交
121
```js
W
wusongqing 已提交
122
let audioRecorder = media.createAudioRecorder();
W
wusongqing 已提交
123 124
```

W
wusongqing 已提交
125
## media.createVideoRecorder<sup>9+</sup>
W
wusongqing 已提交
126

W
wusongqing 已提交
127
createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder9)>): void
W
wusongqing 已提交
128 129

Creates a **VideoRecorder** instance in asynchronous mode. This API uses a callback to return the result.
130
Only one **AudioRecorder** instance can be created per device.
W
wusongqing 已提交
131 132 133 134 135 136 137

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                                           | Mandatory| Description                          |
| -------- | ----------------------------------------------- | ---- | ------------------------------ |
W
wusongqing 已提交
138
| callback | AsyncCallback<[VideoRecorder](#videorecorder9)> | Yes  | Callback used to return the **VideoRecorder** instance created.|
W
wusongqing 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152

**Example**

```js
let videoRecorder

media.createVideoRecorder((error, video) => {
   if (typeof(video) != 'undefined') {
       videoRecorder = video;
       console.info('video createVideoRecorder success');
   } else {
       console.info(`video createVideoRecorder fail, error:${error.message}`);
   }
});
Z
zengyawen 已提交
153
```
W
wusongqing 已提交
154

W
wusongqing 已提交
155
## media.createVideoRecorder<sup>9+</sup>
W
wusongqing 已提交
156

W
wusongqing 已提交
157
createVideoRecorder(): Promise<[VideoRecorder](#videorecorder9)>
W
wusongqing 已提交
158 159

Creates a **VideoRecorder** instance in asynchronous mode. This API uses a promise to return the result.
160
Only one **AudioRecorder** instance can be created per device.
W
wusongqing 已提交
161 162 163 164 165 166 167

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type                                     | Description                               |
| ----------------------------------------- | ----------------------------------- |
W
wusongqing 已提交
168
| Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the **VideoRecorder** instance created.|
W
wusongqing 已提交
169 170 171 172 173 174

**Example**

```js
let videoRecorder

W
wusongqing 已提交
175
media.createVideoRecorder().then((video) => {
W
wusongqing 已提交
176 177 178 179 180 181
    if (typeof(video) != 'undefined') {
       videoRecorder = video;
       console.info('video createVideoRecorder success');
   } else {
       console.info('video createVideoRecorder fail');
   }
W
wusongqing 已提交
182 183 184
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
185 186
```

W
wusongqing 已提交
187 188


W
wusongqing 已提交
189 190 191 192
## MediaErrorCode<sup>8+</sup>

Enumerates the media error codes.

W
wusongqing 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206
**System capability**: SystemCapability.Multimedia.Media.Core

| Name                      | Value  | Description                                  |
| -------------------------- | ---- | -------------------------------------- |
| MSERR_OK                   | 0    | The operation is successful.                        |
| MSERR_NO_MEMORY            | 1    | Failed to allocate memory. The system may have no available memory.|
| MSERR_OPERATION_NOT_PERMIT | 2    | No permission to perform this operation.                |
| MSERR_INVALID_VAL          | 3    | Invalid input parameter.                    |
| MSERR_IO                   | 4    | An I/O error occurs.                      |
| MSERR_TIMEOUT              | 5    | The operation times out.                        |
| MSERR_UNKNOWN              | 6    | An unknown error occurs.                        |
| MSERR_SERVICE_DIED         | 7    | Invalid server.                      |
| MSERR_INVALID_STATE        | 8    | The operation is not allowed in the current state.  |
| MSERR_UNSUPPORTED          | 9    | The operation is not supported in the current version.      |
W
wusongqing 已提交
207 208 209 210 211

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

Enumerates the media types.

W
wusongqing 已提交
212 213 214 215 216 217
**System capability**: SystemCapability.Multimedia.Media.Core

| Name          | Value  | Description      |
| -------------- | ---- | ---------- |
| MEDIA_TYPE_AUD | 0    | Media.|
| MEDIA_TYPE_VID | 1    | Video.|
W
wusongqing 已提交
218 219 220 221 222

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

Enumerates the codec MIME types.

W
wusongqing 已提交
223 224
**System capability**: SystemCapability.Multimedia.Media.Core

W
wusongqing 已提交
225 226 227 228 229 230 231
| Name        | Value                   | Description                    |
| ------------ | --------------------- | ------------------------ |
| VIDEO_H263   | 'video/h263'          | Video in H.263 format.     |
| VIDEO_AVC    | 'video/avc'           | Video in AVC format.      |
| VIDEO_MPEG2  | 'video/mpeg2'         | Video in MPEG-2 format.    |
| VIDEO_MPEG4  | 'video/mp4v-es'       | Video in MPEG-4 format.    |
| VIDEO_VP8    | 'video/x-vnd.on2.vp8' | Video in VP8 format.      |
W
wusongqing 已提交
232
| AUDIO_AAC    | "audio/mp4a-latm"     | Audio in MP4A-LATM format.|
W
wusongqing 已提交
233 234
| AUDIO_VORBIS | 'audio/vorbis'        | Audio in Vorbis format.   |
| AUDIO_FLAC   | 'audio/flac'          | Audio in FLAC format.     |
W
wusongqing 已提交
235 236 237 238 239

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

Enumerates the media description keys.

W
wusongqing 已提交
240 241
**System capability**: SystemCapability.Multimedia.Media.Core

W
wusongqing 已提交
242
| Name                    | Value             | Description                                                        |
W
wusongqing 已提交
243
| ------------------------ | --------------- | ------------------------------------------------------------ |
W
wusongqing 已提交
244 245 246
| MD_KEY_TRACK_INDEX       | "track_index"   | Track index, which is a number.                      |
| MD_KEY_TRACK_TYPE        | "track_type"    | Track type, which is a number. For details, see [MediaType](#mediatype8).|
| MD_KEY_CODEC_MIME        | "codec_mime"    | Codec MIME type, which is a string.                |
W
wusongqing 已提交
247 248 249 250 251
| MD_KEY_DURATION          | "duration"      | Media duration, which is a number, in units of ms.    |
| MD_KEY_BITRATE           | "bitrate"       | Bit rate, which is a number, in units of bit/s.   |
| MD_KEY_WIDTH             | "width"         | Video width, which is a number, in units of pixel.    |
| MD_KEY_HEIGHT            | "height"        | Video height, which is a number, in units of pixel.    |
| MD_KEY_FRAME_RATE        | "frame_rate"    | Video frame rate, which is a number, in units of 100 fps.|
W
wusongqing 已提交
252
| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | Number of audio channels, which is a number.                        |
W
wusongqing 已提交
253
| MD_KEY_AUD_SAMPLE_RATE   | "sample_rate"   | Sampling rate, which is a number, in units of Hz.      |
W
wusongqing 已提交
254 255 256 257 258

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

Enumerates the buffering event types.

W
wusongqing 已提交
259 260
**System capability**: SystemCapability.Multimedia.Media.Core

W
wusongqing 已提交
261 262 263 264 265
| Name             | Value  | Description                            |
| ----------------- | ---- | -------------------------------- |
| BUFFERING_START   | 1    | Buffering starts.                  |
| BUFFERING_END     | 2    | Buffering ends.                  |
| BUFFERING_PERCENT | 3    | Buffering progress, in percent.                |
W
wusongqing 已提交
266
| CACHED_DURATION   | 4    | Cache duration, in milliseconds.|
W
wusongqing 已提交
267

Z
zengyawen 已提交
268 269
## AudioPlayer

W
wusongqing 已提交
270
Provides APIs to manage and play audio. Before calling an API of **AudioPlayer**, you must use [createAudioPlayer()](#mediacreateaudioplayer) to create an **AudioPlayer** instance.
W
wusongqing 已提交
271

W
wusongqing 已提交
272
For details about the audio playback demo, see [Audio Playback Development](../../media/audio-playback.md).
Z
zengyawen 已提交
273

W
wusongqing 已提交
274 275 276
### Attributes<a name=audioplayer_attributes></a>

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
Z
zengyawen 已提交
277

278 279 280 281 282 283 284 285 286
| Name                           | Type                               | Readable| Writable| Description                                                        |
| ------------------------------- | ----------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| src                             | string                              | Yes  | Yes  | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.<br>**Examples of supported URI schemes**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)|
| fdSrc<sup>9+</sup>              | [AVFileDescriptor](#interruptmode9) | Yes  | Yes  | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Music 1 (address offset: 0, byte length: 100)<br>Music 2 (address offset: 101; byte length: 50)<br>Music 3 (address offset: 151, byte length: 150)<br>1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>If the file is an independent music file, use **src=fd://xx**.<br> <br>**Required permissions**: ohos.permission.READ_MEDIA|
| loop                            | boolean                             | Yes  | Yes  | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite.                |
| audioInterruptMode<sup>9+</sup> | [InterruptMode](#interruptmode9)    | Yes  | Yes  | Audio interruption mode.                                              |
| currentTime                     | number                              | Yes  | No  | Current audio playback position, in ms.                      |
| duration                        | number                              | Yes  | No  | Audio duration, in ms.                                |
| state                           | [AudioState](#audiostate)           | Yes  | No  | Audio playback state. This state cannot be used as the condition for triggering the call of **play()**, **pause()**, or **stop()**.|
W
wusongqing 已提交
287
### play<a name=audioplayer_play></a>
Z
zengyawen 已提交
288

W
wusongqing 已提交
289
play(): void
Z
zengyawen 已提交
290

W
wusongqing 已提交
291
Starts to play audio resources. This API can be called only after the [dataLoad](#audioplayer_on) event is triggered.
W
wusongqing 已提交
292 293

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
Z
zengyawen 已提交
294 295 296

**Example**

W
wusongqing 已提交
297 298 299
```js
audioPlayer.on('play', () => {    // Set the 'play' event callback.
    console.log('audio play success');
Z
zengyawen 已提交
300
});
W
wusongqing 已提交
301
audioPlayer.play();
Z
zengyawen 已提交
302 303
```

W
wusongqing 已提交
304
### pause<a name=audioplayer_pause></a>
Z
zengyawen 已提交
305

W
wusongqing 已提交
306
pause(): void
Z
zengyawen 已提交
307 308 309

Pauses audio playback.

W
wusongqing 已提交
310 311
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
312 313
**Example**

W
wusongqing 已提交
314 315 316
```js
audioPlayer.on('pause', () => {    // Set the 'pause' event callback.
    console.log('audio pause success');
Z
zengyawen 已提交
317
});
W
wusongqing 已提交
318
audioPlayer.pause();
Z
zengyawen 已提交
319 320
```

W
wusongqing 已提交
321
### stop<a name=audioplayer_stop></a>
Z
zengyawen 已提交
322

W
wusongqing 已提交
323
stop(): void
Z
zengyawen 已提交
324 325 326

Stops audio playback.

W
wusongqing 已提交
327 328
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
329 330
**Example**

W
wusongqing 已提交
331 332 333
```js
audioPlayer.on('stop', () => {    // Set the 'stop' event callback.
    console.log('audio stop success');
Z
zengyawen 已提交
334
});
W
wusongqing 已提交
335
audioPlayer.stop();
Z
zengyawen 已提交
336 337
```

W
wusongqing 已提交
338 339 340
### reset<sup>7+</sup><a name=audioplayer_reset></a>

reset(): void
Z
zengyawen 已提交
341

W
wusongqing 已提交
342
Switches the audio resource to be played.
Z
zengyawen 已提交
343

W
wusongqing 已提交
344 345
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
346 347 348 349 350 351 352 353 354 355 356 357
**Example**

```js
audioPlayer.on('reset', () => {    // Set the 'reset' event callback.
    console.log('audio reset success');
});
audioPlayer.reset();
```

### seek<a name=audioplayer_seek></a>

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

Seeks to the specified playback position.

W
wusongqing 已提交
361 362
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
363 364
**Parameters**

W
wusongqing 已提交
365 366
| Name| Type  | Mandatory| Description                                |
| ------ | ------ | ---- | ------------------------------------ |
W
wusongqing 已提交
367
| timeMs | number | Yes  | Position to seek to, in milliseconds.|
Z
zengyawen 已提交
368 369 370

**Example**

W
wusongqing 已提交
371 372 373 374 375 376 377
```js
audioPlayer.on('timeUpdate', (seekDoneTime) => {    // Set the 'timeUpdate' event callback.
    if (typeof (seekDoneTime) == 'undefined') {
        console.info('audio seek fail');
        return;
    }
    console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
Z
zengyawen 已提交
378
});
W
wusongqing 已提交
379
audioPlayer.seek(30000); // Seek to 30000 ms.
Z
zengyawen 已提交
380 381
```

W
wusongqing 已提交
382
### setVolume<a name=audioplayer_setvolume></a>
Z
zengyawen 已提交
383

W
wusongqing 已提交
384
setVolume(vol: number): void
Z
zengyawen 已提交
385 386 387

Sets the volume.

W
wusongqing 已提交
388 389
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
390 391
**Parameters**

W
wusongqing 已提交
392
| Name| Type  | Mandatory| Description                                                        |
W
wusongqing 已提交
393
| ------ | ------ | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
394
| vol    | number | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|
Z
zengyawen 已提交
395 396 397

**Example**

W
wusongqing 已提交
398 399 400
```js
audioPlayer.on('volumeChange', () => {    // Set the 'volumeChange' event callback.
    console.log('audio volumeChange success');
Z
zengyawen 已提交
401
});
W
wusongqing 已提交
402
audioPlayer.setVolume(1);    // Set the volume to 100%.
Z
zengyawen 已提交
403 404
```

W
wusongqing 已提交
405
### release<a name=audioplayer_release></a>
Z
zengyawen 已提交
406

W
wusongqing 已提交
407
release(): void
Z
zengyawen 已提交
408

W
wusongqing 已提交
409 410 411
Releases the audio playback resource.

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
Z
zengyawen 已提交
412 413 414

**Example**

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

W
wusongqing 已提交
420 421
### getTrackDescription<sup>8+</sup><a name=audioplayer_gettrackdescription1></a>

W
wusongqing 已提交
422
getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void
Z
zengyawen 已提交
423

W
wusongqing 已提交
424
Obtains the audio track information. This API uses a callback to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered.
W
wusongqing 已提交
425 426

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
Z
zengyawen 已提交
427

W
wusongqing 已提交
428 429
**Parameters**

W
wusongqing 已提交
430
| Name  | Type                                                        | Mandatory| Description                      |
W
wusongqing 已提交
431
| -------- | ------------------------------------------------------------ | ---- | -------------------------- |
W
wusongqing 已提交
432
| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | Yes  | Callback used to return the audio track information obtained.|
Z
zengyawen 已提交
433 434 435

**Example**

W
wusongqing 已提交
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
```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 已提交
454
```
W
wusongqing 已提交
455 456 457

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

W
wusongqing 已提交
458
getTrackDescription(): Promise<Array\<MediaDescription>>
W
wusongqing 已提交
459

W
wusongqing 已提交
460
Obtains the audio track information. This API uses a promise to return the result. It can be called only after the [dataLoad](#audioplayer_on) event is triggered.
W
wusongqing 已提交
461 462

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
W
wusongqing 已提交
463

W
wusongqing 已提交
464
**Return value**
W
wusongqing 已提交
465

W
wusongqing 已提交
466
| Type                                                  | Description                           |
W
wusongqing 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480
| ------------------------------------------------------ | ------------------------------- |
| Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return the audio track information obtained.|

**Example**

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

W
wusongqing 已提交
481
audioPlayer.getTrackDescription().then((arrlist) => {
W
wusongqing 已提交
482 483 484 485 486
    if (typeof (arrlist) != 'undefined') {
        arrayDescription = arrlist;
    } else {
        console.log('audio getTrackDescription fail');
    }
W
wusongqing 已提交
487 488 489 490
}).catch((error) => {
   console.info(`audio catchCallback, error:${error.message}`);
});

W
wusongqing 已提交
491 492 493
for (let i = 0; i < arrayDescription.length; i++) {
    printfDescription(arrayDescription[i]);
}
Z
zengyawen 已提交
494 495
```

W
wusongqing 已提交
496
### on('bufferingUpdate')<sup>8+</sup>
Z
zengyawen 已提交
497

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

W
wusongqing 已提交
500
Subscribes to the audio buffering update event.
Z
zengyawen 已提交
501

W
wusongqing 已提交
502 503
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
504 505
**Parameters**

W
wusongqing 已提交
506 507
| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
508
| type     | string   | Yes  | Event type, which is **'bufferingUpdate'** in this case.   |
W
wusongqing 已提交
509
| callback | function | Yes  | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
Z
zengyawen 已提交
510 511 512

**Example**

W
wusongqing 已提交
513 514 515 516 517
```js
audioPlayer.on('bufferingUpdate', (infoType, value) => {
    console.log('audio bufferingInfo type: ' + infoType);
    console.log('audio bufferingInfo value: ' + value);
});
Z
zengyawen 已提交
518
```
W
wusongqing 已提交
519

W
wusongqing 已提交
520
 ### on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')<a name = audioplayer_on></a>
W
wusongqing 已提交
521 522 523 524 525

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

Subscribes to the audio playback events.

W
wusongqing 已提交
526 527
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

W
wusongqing 已提交
528 529
**Parameters**

W
wusongqing 已提交
530
| Name  | Type      | Mandatory| Description                                                        |
W
wusongqing 已提交
531
| -------- | ---------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
532
| type     | string     | Yes  | Event type. The following events are supported:<br>- 'play': triggered when the [play()](#audioplayer_play) API is called and audio playback starts.<br>- 'pause': triggered when the [pause()](#audioplayer_pause) API is called and audio playback is paused.<br>- 'stop': triggered when the [stop()](#audioplayer_stop) API is called and audio playback stops.<br>- 'reset': triggered when the [reset()](#audioplayer_reset) API is called and audio playback is reset.<br>- 'dataLoad': triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- 'finish': triggered when the audio playback is finished.<br>- 'volumeChange': triggered when the [setVolume()](#audioplayer_setvolume) API is called and the playback volume is changed. |
W
wusongqing 已提交
533
| callback | () => void | Yes  | Callback invoked when the event is triggered.                                          |
W
wusongqing 已提交
534 535 536 537 538 539

**Example**

```js
let audioPlayer = media.createAudioPlayer();  // Create an AudioPlayer instance.
audioPlayer.on('dataLoad', () => {            // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
W
wusongqing 已提交
540
    console.info('audio set source success');
W
wusongqing 已提交
541 542 543
    audioPlayer.play();                       // Start the playback and trigger the 'play' event callback.
});
audioPlayer.on('play', () => {                // Set the 'play' event callback.
W
wusongqing 已提交
544
    console.info('audio play success');
W
wusongqing 已提交
545
    audioPlayer.seek(30000);                  // Call the seek() API and trigger the 'timeUpdate' event callback.
Z
zengyawen 已提交
546
});
W
wusongqing 已提交
547
audioPlayer.on('pause', () => {               // Set the 'pause' event callback.
W
wusongqing 已提交
548
    console.info('audio pause success');
W
wusongqing 已提交
549 550 551
    audioPlayer.stop();                       // Stop the playback and trigger the 'stop' event callback.
});
audioPlayer.on('reset', () => {               // Set the 'reset' event callback.
W
wusongqing 已提交
552
    console.info('audio reset success');
W
wusongqing 已提交
553 554 555 556
    audioPlayer.release();                    // Release the AudioPlayer instance.
    audioPlayer = undefined;
});
audioPlayer.on('timeUpdate', (seekDoneTime) => {  // Set the 'timeUpdate' event callback.
W
wusongqing 已提交
557
    if (typeof(seekDoneTime) == "undefined") {
W
wusongqing 已提交
558 559 560 561 562 563 564
        console.info('audio seek fail');
        return;
    }
    console.info('audio seek success, and seek time is ' + seekDoneTime);
    audioPlayer.setVolume(0.5);                // Set the volume to 50% and trigger the 'volumeChange' event callback.
});
audioPlayer.on('volumeChange', () => {         // Set the 'volumeChange' event callback.
W
wusongqing 已提交
565
    console.info('audio volumeChange success');
W
wusongqing 已提交
566 567 568
    audioPlayer.pause();                       // Pause the playback and trigger the 'pause' event callback.
});
audioPlayer.on('finish', () => {               // Set the 'finish' event callback.
W
wusongqing 已提交
569
    console.info('audio play finish');
W
wusongqing 已提交
570 571 572
    audioPlayer.stop();                        // Stop the playback and trigger the 'stop' event callback.
});
audioPlayer.on('error', (error) => {           // Set the 'error' event callback.
W
wusongqing 已提交
573
    console.info(`audio error called, errName is ${error.name}`);
W
wusongqing 已提交
574 575 576
    console.info(`audio error called, errCode is ${error.code}`);
    console.info(`audio error called, errMessage is ${error.message}`);
});
W
wusongqing 已提交
577 578 579

// Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://'
W
wusongqing 已提交
580 581
// The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command.
let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
W
wusongqing 已提交
582
fileIO.open(path).then(fdNumber) => {
W
wusongqing 已提交
583
   fdPath = fdPath + '' + fdNumber;
JoyboyCZ's avatar
JoyboyCZ 已提交
584
   console.info('open fd success fd is' + fdPath);
W
wusongqing 已提交
585 586
}, (err) => {
   console.info('open fd failed err is' + err);
W
wusongqing 已提交
587
}).catch((err) => {
W
wusongqing 已提交
588 589 590
   console.info('open fd failed err is' + err);
});
audioPlayer.src = fdPath;  // Set the src attribute and trigger the 'dataLoad' event callback.
Z
zengyawen 已提交
591 592 593 594 595 596
```

### on('timeUpdate')

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

597
Subscribes to the **'timeUpdate'** event.
W
wusongqing 已提交
598 599

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer
Z
zengyawen 已提交
600 601 602

**Parameters**

W
wusongqing 已提交
603
| Name  | Type             | Mandatory| Description                                                        |
W
wusongqing 已提交
604
| -------- | ----------------- | ---- | ------------------------------------------------------------ |
605
| type     | string            | Yes  | Event type, which is **'timeUpdate'** in this case.<br>The **'timeUpdate'** event is triggered when the [seek()](#audioplayer_seek) API is called. |
W
wusongqing 已提交
606
| callback | Callback\<number> | Yes  | Callback invoked when the event is triggered. The input parameter of the callback is the time when the seek operation is successful.            |
Z
zengyawen 已提交
607 608 609

**Example**

W
wusongqing 已提交
610 611 612 613 614 615 616
```js
audioPlayer.on('timeUpdate', (seekDoneTime) => {    // Set the 'timeUpdate' event callback.
    if (typeof (seekDoneTime) == 'undefined') {
        console.info('audio seek fail');
        return;
    }
    console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
Z
zengyawen 已提交
617
});
W
wusongqing 已提交
618
audioPlayer.seek(30000); // Seek to 30000 ms.
Z
zengyawen 已提交
619 620 621 622 623 624
```

### on('error')

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

625
Subscribes to audio playback error events. After an error event is reported, you must handle the event and exit the playback.
Z
zengyawen 已提交
626

W
wusongqing 已提交
627 628
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

Z
zengyawen 已提交
629 630
**Parameters**

W
wusongqing 已提交
631
| Name  | Type         | Mandatory| Description                                                        |
W
wusongqing 已提交
632
| -------- | ------------- | ---- | ------------------------------------------------------------ |
633
| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>The **'error'** event is triggered when an error occurs during audio playback. |
W
wusongqing 已提交
634
| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.                                      |
Z
zengyawen 已提交
635 636 637

**Example**

W
wusongqing 已提交
638
```js
639
audioPlayer.on('error', (error) => {      // Set the 'error' event callback.
W
wusongqing 已提交
640
    console.info(`audio error called, errName is ${error.name}`);      // Print the error name.
W
wusongqing 已提交
641 642
    console.info(`audio error called, errCode is ${error.code}`);      // Print the error code.
    console.info(`audio error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
Z
zengyawen 已提交
643
});
W
wusongqing 已提交
644
audioPlayer.setVolume(3); // Set volume to an invalid value to trigger the 'error' event.
Z
zengyawen 已提交
645 646 647 648
```

## AudioState

W
wusongqing 已提交
649
Enumerates the audio playback states. You can obtain the state through the **state** attribute.
W
wusongqing 已提交
650

W
wusongqing 已提交
651 652
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
| Name              | Type  | Description                                          |
| ------------------ | ------ | ---------------------------------------------- |
| idle               | string |  No audio playback is in progress. The audio player is in this state after the **'dataload'** or **'reset'** event is triggered.|
| playing            | string | Audio playback is in progress. The audio player is in this state after the **'play'** event is triggered.          |
| paused             | string | Audio playback is paused. The audio player is in this state after the **'pause'** event is triggered.         |
| stopped            | string | Audio playback is stopped. The audio player is in this state after the **'stop'** event is triggered.     |
| error<sup>8+</sup> | string | Audio playback is in the error state.                                    |

## AVFileDescriptor<sup>9+</sup>

Describes audio and video file resources. It is used to specify a particular resource for playback based on its offset and length within a file.

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| fd     | number | Yes  | Resource handle, which is obtained by calling **resourceManager.getRawFileDescriptor**.      |
| offset | number | Yes  | Resource offset, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.|
| length | number | Yes  | Resource length, which needs to be entered based on the preset resource information. An invalid value causes a failure to parse audio and video resources.|

## InterruptMode<sup>9+</sup>

Describes the audio interruption mode.

**System capability**: SystemCapability.Multimedia.Media.AudioPlayer

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| SHARE_MODE      | 0      | Shared mode.|
| INDEPENDENT_MODE| 1      | Independent mode.    |
Z
zengyawen 已提交
685

W
wusongqing 已提交
686
## VideoPlayer<sup>8+</sup>
W
wusongqing 已提交
687

W
wusongqing 已提交
688
Provides APIs to manage and play video. Before calling an API of **VideoPlayer**, you must call [createVideoPlayer()](#mediacreatevideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
W
wusongqing 已提交
689

W
wusongqing 已提交
690
For details about the video playback demo, see [Video Playback Development](../../media/video-playback.md).
W
wusongqing 已提交
691

W
wusongqing 已提交
692 693
### Attributes<a name=videoplayer_attributes></a>

W
wusongqing 已提交
694 695
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

W
wusongqing 已提交
696 697
| Name                    | Type                              | Readable| Writable| Description                                                        |
| ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
698 699
| url<sup>8+</sup>         | string                             | Yes  | Yes  | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.INTERNET (The latter is required only when online resources are used.)|
| fdSrc<sup>9+</sup> | [AVFileDescriptor](#interruptmode9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent video file, use **src=fd://xx**.<br>**Note**:<br>**Required permissions**: ohos.permission.READ_MEDIA|
W
wusongqing 已提交
700
| loop<sup>8+</sup>        | boolean                            | Yes  | Yes  | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite.                |
701 702 703 704
| videoScaleType<sup>9+</sup>        | [VideoScaleType](#videoscaletype9)                   | Yes  | Yes  | Video scale type.      |
| audioInterruptMode<sup>9+</sup>        | [InterruptMode](#interruptmode9)                   | Yes  | Yes  | Audio interruption mode.      |
| currentTime<sup>8+</sup> | number                             | Yes  | No  | Current video playback position, in ms.                      |
| duration<sup>8+</sup>    | number                             | Yes  | No  | Video duration, in ms. The value **-1** indicates the live mode.            |
W
wusongqing 已提交
705
| state<sup>8+</sup>       | [VideoPlayState](#videoplaystate8) | Yes  | No  | Video playback state.                                            |
706 707
| width<sup>8+</sup>       | number                             | Yes  | No  | Video width, in pixels.                                  |
| height<sup>8+</sup>      | number                             | Yes  | No  | Video height, in pixels.                                  |
W
wusongqing 已提交
708 709 710 711 712 713 714

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

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

Sets **SurfaceId**. This API uses a callback to return the result.

W
wusongqing 已提交
715 716
*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails.

W
wusongqing 已提交
717 718 719 720 721 722 723
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name   | Type    | Mandatory| Description                     |
| --------- | -------- | ---- | ------------------------- |
| surfaceId | string   | Yes  | Surface ID to set.                |
W
wusongqing 已提交
724
| callback  | function | Yes  | Callback used to return the result.|
W
wusongqing 已提交
725 726 727 728

**Example**

```js
W
wusongqing 已提交
729
videoPlayer.setDisplaySurface(surfaceId, (err) => {
W
wusongqing 已提交
730 731 732
    if (typeof (err) == 'undefined') {
        console.info('setDisplaySurface success!');
    } else {
W
wusongqing 已提交
733
        console.info('setDisplaySurface fail!');
W
wusongqing 已提交
734 735 736
    }
});
```
Z
zengyawen 已提交
737

W
wusongqing 已提交
738
### setDisplaySurface<sup>8+</sup>
Z
zengyawen 已提交
739

W
wusongqing 已提交
740
setDisplaySurface(surfaceId: string): Promise\<void>
Z
zengyawen 已提交
741

W
wusongqing 已提交
742
Sets **SurfaceId**. This API uses a promise to return the result.
Z
zengyawen 已提交
743

W
wusongqing 已提交
744 745
*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails.

W
wusongqing 已提交
746
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
Z
zengyawen 已提交
747

W
wusongqing 已提交
748 749 750 751 752 753 754 755
**Parameters**

| Name   | Type  | Mandatory| Description     |
| --------- | ------ | ---- | --------- |
| surfaceId | string | Yes  | Surface ID to set.|

**Return value**

W
wusongqing 已提交
756 757 758
| Type          | Description                          |
| -------------- | ------------------------------ |
| Promise\<void> | Promise used to return the result.|
W
wusongqing 已提交
759 760 761 762

**Example**

```js
W
wusongqing 已提交
763
videoPlayer.setDisplaySurface(surfaceId).then(() => {
W
wusongqing 已提交
764
    console.info('setDisplaySurface success');
W
wusongqing 已提交
765 766 767
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
768 769 770 771 772 773 774 775 776
```

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

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

Prepares for video playback. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
W
wusongqing 已提交
777

Z
zengyawen 已提交
778 779
**Parameters**

W
wusongqing 已提交
780 781 782
| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|
Z
zengyawen 已提交
783 784 785

**Example**

W
wusongqing 已提交
786 787
```js
videoPlayer.prepare((err) => {
W
wusongqing 已提交
788 789 790
    if (typeof (err) == 'undefined') {
        console.info('prepare success!');
    } else {
W
wusongqing 已提交
791 792 793
        console.info('prepare fail!');
    }
});
W
wusongqing 已提交
794
```
W
wusongqing 已提交
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812

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

prepare(): Promise\<void>

Prepares for video playback. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
813
videoPlayer.prepare().then(() => {
W
wusongqing 已提交
814
    console.info('prepare success');
W
wusongqing 已提交
815 816 817
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
818 819
```

W
wusongqing 已提交
820
### play<sup>8+</sup>
W
wusongqing 已提交
821

W
wusongqing 已提交
822
play(callback: AsyncCallback\<void>): void;
Z
zengyawen 已提交
823

W
wusongqing 已提交
824 825 826
Starts to play video resources. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
Z
zengyawen 已提交
827

W
wusongqing 已提交
828 829 830 831 832
**Parameters**

| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|
Z
zengyawen 已提交
833 834 835

**Example**

W
wusongqing 已提交
836 837
```js
videoPlayer.play((err) => {
W
wusongqing 已提交
838 839 840
    if (typeof (err) == 'undefined') {
        console.info('play success!');
    } else {
W
wusongqing 已提交
841 842 843
        console.info('play fail!');
    }
});
Z
zengyawen 已提交
844
```
W
wusongqing 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862

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

play(): Promise\<void>;

Starts to play video resources. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
863
videoPlayer.play().then(() => {
W
wusongqing 已提交
864
    console.info('play success');
W
wusongqing 已提交
865 866 867
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
868 869
```

W
wusongqing 已提交
870
### pause<sup>8+</sup>
Z
zengyawen 已提交
871

W
wusongqing 已提交
872
pause(callback: AsyncCallback\<void>): void
Z
zengyawen 已提交
873

W
wusongqing 已提交
874 875 876 877 878 879 880 881 882
Pauses video playback. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|
Z
zengyawen 已提交
883 884 885

**Example**

W
wusongqing 已提交
886 887
```js
videoPlayer.pause((err) => {
W
wusongqing 已提交
888 889 890
    if (typeof (err) == 'undefined') {
        console.info('pause success!');
    } else {
W
wusongqing 已提交
891 892 893
        console.info('pause fail!');
    }
});
Z
zengyawen 已提交
894
```
W
wusongqing 已提交
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912

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

pause(): Promise\<void>

Pauses video playback. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
913
videoPlayer.pause().then(() => {
W
wusongqing 已提交
914
    console.info('pause success');
W
wusongqing 已提交
915 916 917
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
918 919
```

W
wusongqing 已提交
920
### stop<sup>8+</sup>
Z
zengyawen 已提交
921

W
wusongqing 已提交
922 923 924
stop(callback: AsyncCallback\<void>): void

Stops video playback. This API uses a callback to return the result.
Z
zengyawen 已提交
925

W
wusongqing 已提交
926 927 928 929 930 931 932
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|
W
wusongqing 已提交
933

Z
zengyawen 已提交
934 935
**Example**

W
wusongqing 已提交
936 937
```js
videoPlayer.stop((err) => {
W
wusongqing 已提交
938 939 940
    if (typeof (err) == 'undefined') {
        console.info('stop success!');
    } else {
W
wusongqing 已提交
941 942 943
        console.info('stop fail!');
    }
});
Z
zengyawen 已提交
944
```
W
wusongqing 已提交
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962

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

stop(): Promise\<void>

Stops video playback. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
963
videoPlayer.stop().then(() => {
W
wusongqing 已提交
964
    console.info('stop success');
W
wusongqing 已提交
965 966 967
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
968 969
```

W
wusongqing 已提交
970
### reset<sup>8+</sup>
Z
zengyawen 已提交
971

W
wusongqing 已提交
972
reset(callback: AsyncCallback\<void>): void
Z
zengyawen 已提交
973

W
wusongqing 已提交
974
Switches the video resource to be played. This API uses a callback to return the result.
Z
zengyawen 已提交
975

W
wusongqing 已提交
976 977 978 979 980 981 982
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|
Z
zengyawen 已提交
983 984 985

**Example**

W
wusongqing 已提交
986 987
```js
videoPlayer.reset((err) => {
W
wusongqing 已提交
988 989 990
    if (typeof (err) == 'undefined') {
        console.info('reset success!');
    } else {
W
wusongqing 已提交
991 992 993
        console.info('reset fail!');
    }
});
Z
zengyawen 已提交
994
```
W
wusongqing 已提交
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012

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

reset(): Promise\<void>

Switches the video resource to be played. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
1013
videoPlayer.reset().then(() => {
W
wusongqing 已提交
1014
    console.info('reset success');
W
wusongqing 已提交
1015 1016 1017
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
Z
zengyawen 已提交
1018 1019
```

W
wusongqing 已提交
1020
### seek<sup>8+</sup>
Z
zengyawen 已提交
1021

W
wusongqing 已提交
1022
seek(timeMs: number, callback: AsyncCallback\<number>): void
Z
zengyawen 已提交
1023

W
wusongqing 已提交
1024 1025 1026
Seeks to the specified playback position. The next key frame at the specified position is played. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
Z
zengyawen 已提交
1027 1028 1029

**Parameters**

W
wusongqing 已提交
1030 1031
| Name  | Type    | Mandatory| Description                                |
| -------- | -------- | ---- | ------------------------------------ |
W
wusongqing 已提交
1032
| timeMs   | number   | Yes  | Position to seek to, in milliseconds.|
W
wusongqing 已提交
1033
| callback | function | Yes  | Callback used to return the result.      |
Z
zengyawen 已提交
1034 1035 1036

**Example**

W
wusongqing 已提交
1037
```js
W
wusongqing 已提交
1038 1039
let seekTime = 5000;
videoPlayer.seek(seekTime, (err, result) => {
W
wusongqing 已提交
1040 1041 1042
    if (typeof (err) == 'undefined') {
        console.info('seek success!');
    } else {
W
wusongqing 已提交
1043 1044
        console.info('seek fail!');
    }
Z
zengyawen 已提交
1045 1046 1047
});
```

W
wusongqing 已提交
1048
### seek<sup>8+</sup>
Z
zengyawen 已提交
1049

W
wusongqing 已提交
1050
seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void
Z
zengyawen 已提交
1051

W
wusongqing 已提交
1052 1053 1054
Seeks to the specified playback position. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
Z
zengyawen 已提交
1055 1056 1057

**Parameters**

W
wusongqing 已提交
1058 1059
| Name  | Type                  | Mandatory| Description                                |
| -------- | ---------------------- | ---- | ------------------------------------ |
W
wusongqing 已提交
1060
| timeMs   | number                 | Yes  | Position to seek to, in milliseconds.|
W
wusongqing 已提交
1061 1062
| mode     | [SeekMode](#seekmode8) | Yes  | Seek mode.                          |
| callback | function               | Yes  | Callback used to return the result.      |
W
wusongqing 已提交
1063

W
wusongqing 已提交
1064
**Example**
Z
zengyawen 已提交
1065

W
wusongqing 已提交
1066
```js
W
wusongqing 已提交
1067 1068 1069 1070
import media from '@ohos.multimedia.media'
let seekTime = 5000;
let seekMode = media.SeekMode.SEEK_NEXT_SYNC;
videoPlayer.seek(seekTime, seekMode, (err, result) => {
W
wusongqing 已提交
1071 1072 1073
    if (typeof (err) == 'undefined') {
        console.info('seek success!');
    } else {
W
wusongqing 已提交
1074 1075 1076 1077
        console.info('seek fail!');
    }
});
```
Z
zengyawen 已提交
1078

W
wusongqing 已提交
1079
### seek<sup>8+</sup>
Z
zengyawen 已提交
1080

W
wusongqing 已提交
1081
seek(timeMs: number, mode?:SeekMode): Promise\<number>
W
wusongqing 已提交
1082

W
wusongqing 已提交
1083
Seeks to the specified playback position. If **mode** is not specified, the next key frame at the specified position is played. This API uses a promise to return the result.
Z
zengyawen 已提交
1084

W
wusongqing 已提交
1085
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
Z
zengyawen 已提交
1086

W
wusongqing 已提交
1087
**Parameters**
W
wusongqing 已提交
1088

W
wusongqing 已提交
1089 1090
| Name| Type                  | Mandatory| Description                                |
| ------ | ---------------------- | ---- | ------------------------------------ |
W
wusongqing 已提交
1091
| timeMs | number                 | Yes  | Position to seek to, in milliseconds.|
W
wusongqing 已提交
1092
| mode   | [SeekMode](#seekmode8) | No  | Seek mode.                          |
Z
zengyawen 已提交
1093

W
wusongqing 已提交
1094
**Return value**
Z
zengyawen 已提交
1095

W
wusongqing 已提交
1096 1097 1098
| Type          | Description                               |
| -------------- | ----------------------------------- |
| Promise\<void> | Promise used to return the result.|
Z
zengyawen 已提交
1099

W
wusongqing 已提交
1100
**Example**
Z
zengyawen 已提交
1101

W
wusongqing 已提交
1102
```js
W
wusongqing 已提交
1103
let seekTime = 5000;
W
wusongqing 已提交
1104
videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete.
W
wusongqing 已提交
1105
    console.info('seek success');
W
wusongqing 已提交
1106 1107 1108
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1109

W
wusongqing 已提交
1110
videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => {
W
wusongqing 已提交
1111
    console.info('seek success');
W
wusongqing 已提交
1112 1113 1114
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
```

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

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

Sets the volume. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| vol      | number   | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|
| callback | function | Yes  | Callback used to return the result.                                        |

**Example**

```js
W
wusongqing 已提交
1135 1136
let vol = 0.5;
videoPlayer.setVolume(vol, (err, result) => {
W
wusongqing 已提交
1137 1138 1139
    if (typeof (err) == 'undefined') {
        console.info('setVolume success!');
    } else {
W
wusongqing 已提交
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
        console.info('setVolume fail!');
    }
});
```

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

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

Sets the volume. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| vol    | number | Yes  | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|

**Return value**

| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
1168
let vol = 0.5;
W
wusongqing 已提交
1169
videoPlayer.setVolume(vol).then() => {
W
wusongqing 已提交
1170
    console.info('setVolume success');
W
wusongqing 已提交
1171 1172 1173
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
```

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

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

Releases the video playback resource. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                    |
| -------- | -------- | ---- | ------------------------ |
| callback | function | Yes  | Callback used to return the result.|

**Example**

```js
videoPlayer.release((err) => {
W
wusongqing 已提交
1194 1195 1196
    if (typeof (err) == 'undefined') {
        console.info('release success!');
    } else {
W
wusongqing 已提交
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
        console.info('release fail!');
    }
});
```

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

release(): Promise\<void>

Releases the video playback resource. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
W
wusongqing 已提交
1219
videoPlayer.release().then() => {
W
wusongqing 已提交
1220
    console.info('release success');
W
wusongqing 已提交
1221 1222 1223
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1224 1225 1226 1227
```

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

W
wusongqing 已提交
1228
getTrackDescription(callback: AsyncCallback<Array\<MediaDescription>>): void
W
wusongqing 已提交
1229 1230 1231 1232 1233 1234 1235

Obtains the video track information. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

W
wusongqing 已提交
1236 1237 1238
| Name  | Type                                                        | Mandatory| Description                      |
| -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | Yes  | Callback used to return the video track information obtained.|
W
wusongqing 已提交
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263

**Example**

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

W
wusongqing 已提交
1264
getTrackDescription(): Promise<Array\<MediaDescription>>
W
wusongqing 已提交
1265 1266 1267 1268 1269 1270 1271

Obtains the video track information. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Return value**

W
wusongqing 已提交
1272 1273 1274
| Type                                                  | Description                           |
| ------------------------------------------------------ | ------------------------------- |
| Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return the video track information obtained.|
W
wusongqing 已提交
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287

**Example**

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

let arrayDescription;
W
wusongqing 已提交
1288
videoPlayer.getTrackDescription().then((arrlist) => {
W
wusongqing 已提交
1289 1290 1291 1292 1293
    if (typeof (arrlist) != 'undefined') {
        arrayDescription = arrlist;
    } else {
        console.log('video getTrackDescription fail');
    }
W
wusongqing 已提交
1294 1295 1296
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
for (let i = 0; i < arrayDescription.length; i++) {
    printfDescription(arrayDescription[i]);
}
```

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

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

Sets the video playback speed. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                      |
| -------- | -------- | ---- | ---------------------------------------------------------- |
| speed    | number   | Yes  | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
| callback | function | Yes  | Callback used to return the result.                                  |

**Example**

```js
W
wusongqing 已提交
1320 1321 1322 1323
import media from '@ohos.multimedia.media'
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;

videoPlayer.setSpeed(speed, (err, result) => {
W
wusongqing 已提交
1324 1325 1326
    if (typeof (err) == 'undefined') {
        console.info('setSpeed success!');
    } else {
W
wusongqing 已提交
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
        console.info('setSpeed fail!');
    }
});
```

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

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

Sets the video playback speed. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name| Type  | Mandatory| Description                                                      |
| ------ | ------ | ---- | ---------------------------------------------------------- |
| speed  | number | Yes  | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|

W
wusongqing 已提交
1346 1347 1348 1349 1350 1351
**Return value**

| Type            | Description                     |
| ---------------- | ------------------------- |
| Promise\<number> | Promise used to return the result.|

W
wusongqing 已提交
1352 1353 1354
**Example**

```js
W
wusongqing 已提交
1355 1356 1357
import media from '@ohos.multimedia.media'
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;

W
wusongqing 已提交
1358
videoPlayer.setSpeed(speed).then() => {
W
wusongqing 已提交
1359
    console.info('setSpeed success');
W
wusongqing 已提交
1360 1361 1362
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
W
wusongqing 已提交
1363 1364
```

W
wusongqing 已提交
1365 1366 1367 1368
### selectBitrate<sup>9+</sup>

selectBitrate(bitrate:number, callback: AsyncCallback\<number>): void

1369
Selects a bit rate from available ones, which can be obtained by calling [availableBitratesCollect](#onavailablebitratescollect9). This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type                  | Mandatory| Description                                                      |
| -------- | ---------------------- | ---- | ---------------------------------------------------------- |
| bitrate  | number                 | Yes  | Bit rate to select, which is used in the HLS multi-bit rate scenario. The unit is bit/s.              |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the result. If the set value is returned, the operation is successful; otherwise, the operation fails.|

**Example**

```js
let bitrate = 1024000;
videoPlayer.selectBitrate(bitrate, (err, result) => {
    if (typeof (err) == 'undefined') {
        console.info('selectBitrate success!');
    } else {
        console.info('selectBitrate fail!');
    }
});
```

### selectBitrate<sup>9+</sup>

selectBitrate(bitrate:number): Promise\<number>

1397
Selects a bit rate from available ones, which can be obtained by calling [availableBitratesCollect](#onavailablebitratescollect9). This API uses a promise to return the result.
W
wusongqing 已提交
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name | Type  | Mandatory| Description                                        |
| ------- | ------ | ---- | -------------------------------------------- |
| bitrate | number | Yes  | Bit rate to select, which is used in the HLS multi-bit rate scenario. The unit is bit/s.|

**Return value**

| Type            | Description                     |
| ---------------- | ------------------------- |
| Promise\<number> | Promise used to return the result.|

**Example**

```js
let bitrate = 1024000;
videoPlayer.selectBitrate(bitrate).then() => {
    console.info('selectBitrate success');
}).catch((error) => {
   console.info(`video catchCallback, error:${error.message}`);
});
```

W
wusongqing 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
### on('playbackCompleted')<sup>8+</sup>

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

Subscribes to the video playback completion event.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                       |
| -------- | -------- | ---- | ----------------------------------------------------------- |
1436
| type     | string   | Yes  | Event type, which is **'playbackCompleted'** in this case. |
W
wusongqing 已提交
1437 1438 1439 1440 1441 1442
| callback | function | Yes  | Callback invoked when the event is triggered.                                 |

**Example**

```js
videoPlayer.on('playbackCompleted', () => {
W
wusongqing 已提交
1443
    console.info('playbackCompleted success!');
W
wusongqing 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
});
```

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

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

Subscribes to the video buffering update event.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
1459
| type     | string   | Yes  | Event type, which is **'bufferingUpdate'** in this case.   |
W
wusongqing 已提交
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
| callback | function | Yes  | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|

**Example**

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

Subscribes to the frame rendering start event.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

W
wusongqing 已提交
1481 1482
| Name  | Type           | Mandatory| Description                                                        |
| -------- | --------------- | ---- | ------------------------------------------------------------ |
1483
| type     | string          | Yes  | Event type, which is **'startRenderFrame'** in this case. |
W
wusongqing 已提交
1484
| callback | Callback\<void> | Yes  | Callback invoked when the event is triggered.                          |
W
wusongqing 已提交
1485 1486 1487 1488 1489

**Example**

```js
videoPlayer.on('startRenderFrame', () => {
W
wusongqing 已提交
1490
    console.info('startRenderFrame success!');
W
wusongqing 已提交
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
});
```

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

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

Subscribes to the video width and height change event.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
1506
| type     | string   | Yes  | Event type, which is **'videoSizeChanged'** in this case. |
W
wusongqing 已提交
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
| callback | function | Yes  | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height.   |

**Example**

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

1522
Subscribes to video playback error events. After an error event is reported, you must handle the event and exit the playback.
W
wusongqing 已提交
1523 1524 1525 1526 1527

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

W
wusongqing 已提交
1528 1529
| Name  | Type         | Mandatory| Description                                                        |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
1530
| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>The **'error'** event is triggered when an error occurs during video playback. |
W
wusongqing 已提交
1531
| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.                                      |
W
wusongqing 已提交
1532 1533 1534 1535 1536

**Example**

```js
videoPlayer.on('error', (error) => {      // Set the 'error' event callback.
W
wusongqing 已提交
1537
    console.info(`video error called, errName is ${error.name}`);      // Print the error name.
W
wusongqing 已提交
1538 1539 1540
    console.info(`video error called, errCode is ${error.code}`);      // Print the error code.
    console.info(`video error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
});
1541
videoPlayer.url = 'fd://error';  // Set an incorrect URL to trigger the 'error' event.
W
wusongqing 已提交
1542 1543
```

1544
### on('availableBitratesCollect')<sup>9+</sup>
W
wusongqing 已提交
1545

1546
on(type: 'availableBitratesCollect', callback: (bitrates: Array\<number>) => void): void
W
wusongqing 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555

Subscribes to the video playback bit rate reporting event.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

**Parameters**

| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
1556 1557
| type     | string   | Yes  | Event type, which is **'availableBitratesCollect'** in this case. This event is reported only once when the playback starts.|
| callback | function | Yes  | Callback used to return supported bit rates, in an array.          |
W
wusongqing 已提交
1558 1559 1560 1561

**Example**

```js
1562
videoPlayer.on('availableBitratesCollect', (bitrates) => {
W
wusongqing 已提交
1563
    for (let i = 0; i < bitrates.length; i++) {
1564
        console.info('case availableBitratesCollect bitrates: '  + bitrates[i]);  // Print bit rates.
W
wusongqing 已提交
1565 1566 1567 1568
    }
});
```

W
wusongqing 已提交
1569 1570 1571 1572
## VideoPlayState<sup>8+</sup>

Enumerates the video playback states. You can obtain the state through the **state** attribute.

W
wusongqing 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

| Name    | Type  | Description          |
| -------- | ------ | -------------- |
| idle     | string | The video player is idle.|
| prepared | string | Video playback is being prepared.|
| playing  | string | Video playback is in progress.|
| paused   | string | Video playback is paused.|
| stopped  | string | Video playback is stopped.|
| error    | string | Video playback is in the error state.    |
W
wusongqing 已提交
1583 1584 1585

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

W
wusongqing 已提交
1586
Enumerates the video playback seek modes, which can be passed in the **seek** API.
W
wusongqing 已提交
1587

W
wusongqing 已提交
1588 1589
**System capability**: SystemCapability.Multimedia.Media.Core

W
wusongqing 已提交
1590 1591
| Name          | Value  | Description                                                        |
| -------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1592 1593
| SEEK_NEXT_SYNC | 0    | Seeks to the next key frame at the specified position. You are advised to use this value for the rewind operation.|
| SEEK_PREV_SYNC | 1    | Seeks to the previous key frame at the specified position. You are advised to use this value for the fast-forward operation.|
W
wusongqing 已提交
1594 1595 1596

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

W
wusongqing 已提交
1597
Enumerates the video playback speeds, which can be passed in the **setSpeed** API.
W
wusongqing 已提交
1598

W
wusongqing 已提交
1599 1600 1601 1602 1603 1604 1605 1606 1607
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

| Name                | Value  | Description                          |
| -------------------- | ---- | ------------------------------ |
| SPEED_FORWARD_0_75_X | 0    | Plays the video at 0.75 times the normal speed.|
| SPEED_FORWARD_1_00_X | 1    | Plays the video at the normal speed.        |
| SPEED_FORWARD_1_25_X | 2    | Plays the video at 1.25 times the normal speed.|
| SPEED_FORWARD_1_75_X | 3    | Plays the video at 1.75 times the normal speed.|
| SPEED_FORWARD_2_00_X | 4    | Plays the video at 2.00 times the normal speed.|
W
wusongqing 已提交
1608

1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
## VideoScaleType<sup>9+</sup>

Enumerates the video scale modes.

**System capability**: SystemCapability.Multimedia.Media.VideoPlayer

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| VIDEO_SCALE_TYPE_FIT     | 0      | The video will be stretched to fit the window.|
| VIDEO_SCALE_TYPE_FIT_CROP| 1      | The video will be stretched to fit the window, without changing its aspect ratio. The content may be cropped.    |

W
wusongqing 已提交
1620 1621
## MediaDescription<sup>8+</sup>

W
wusongqing 已提交
1622
### [key : string] : Object
W
wusongqing 已提交
1623 1624 1625

Defines media information in key-value mode.

W
wusongqing 已提交
1626 1627
**System capability**: SystemCapability.Multimedia.Media.Core

W
wusongqing 已提交
1628 1629
| Name | Type  | Description                                                        |
| ----- | ------ | ------------------------------------------------------------ |
W
wusongqing 已提交
1630 1631
| key   | string | Key of the media information. For details about the keys, see [MediaDescriptionKey](#mediadescriptionkey8).|
| value | any    | Value of the key. For details about the values, see [MediaDescriptionKey](#mediadescriptionkey8).|
W
wusongqing 已提交
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654

**Example**

```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++) {
            printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE);  // Print the MD_KEY_TRACK_TYPE value of each track.
        }
    } else {
        console.log(`audio getTrackDescription fail, error:${error.message}`);
    }
});
```

## AudioRecorder

W
wusongqing 已提交
1655
Implements audio recording. Before calling an API of **AudioRecorder**, you must call [createAudioRecorder()](#mediacreateaudiorecorder) to create an [AudioRecorder](#audiorecorder) instance.
W
wusongqing 已提交
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672

For details about the audio recording demo, see [Audio Recording Development](../../media/audio-recorder.md).

### prepare<a name=audiorecorder_prepare></a>

prepare(config: AudioRecorderConfig): void

Prepares for recording.

**Required permissions:** ohos.permission.MICROPHONE

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Parameters**

| Name| Type                                       | Mandatory| Description                                                        |
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1673
| config | [AudioRecorderConfig](#audiorecorderconfig) | Yes  | Audio recording parameters, including the audio output URI, encoding format, sampling rate, number of audio channels, and output format.|
W
wusongqing 已提交
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

**Example**

```js
let audioRecorderConfig = {
    audioEncoder : media.AudioEncoder.AAC_LC,
    audioEncodeBitRate : 22050,
    audioSampleRate : 22050,
    numberOfChannels : 2,
    format : media.AudioOutputFormat.AAC_ADTS,
    uri : 'fd://1',       // The file must be created by the caller and granted with proper permissions.
    location : { latitude : 30, longitude : 130},
}
audioRecorder.on('prepare', () => {    // Set the 'prepare' event callback.
    console.log('prepare success');
});
audioRecorder.prepare(audioRecorderConfig);
```


### start<a name=audiorecorder_start></a>

start(): void

W
wusongqing 已提交
1698
Starts audio recording. This API can be called only after the [prepare](#audiorecorder_on) event is triggered.
W
wusongqing 已提交
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('start', () => {    // Set the 'start' event callback.
    console.log('audio recorder start success');
});
audioRecorder.start();
```

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

pause():void

W
wusongqing 已提交
1715
Pauses audio recording. This API can be called only after the [start](#audiorecorder_on) event is triggered.
W
wusongqing 已提交
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('pause', () => {    // Set the 'pause' event callback.
    console.log('audio recorder pause success');
});
audioRecorder.pause();
```

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

resume():void

W
wusongqing 已提交
1732
Resumes audio recording. This API can be called only after the [pause](#audiorecorder_on) event is triggered.
W
wusongqing 已提交
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('resume', () => { // Set the 'resume' event callback.
    console.log('audio recorder resume success');
});
audioRecorder.resume();
```

### stop<a name=audiorecorder_stop></a>

stop(): void

Stops audio recording.

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('stop', () => {    // Set the 'stop' event callback.
    console.log('audio recorder stop success');
});
audioRecorder.stop();
```

### release<a name=audiorecorder_release></a>

release(): void

Releases the audio recording resource.

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('release', () => {    // Set the 'release' event callback.
    console.log('audio recorder release success');
});
audioRecorder.release();
audioRecorder = undefined;
```

### reset<a name=audiorecorder_reset></a>

reset(): void

Resets audio recording.

Before resetting audio recording, you must call [stop()](#audiorecorder_stop) to stop recording. After audio recording is reset, you must call [prepare()](#audiorecorder_prepare) to set the recording parameters for another recording.

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Example**

```js
audioRecorder.on('reset', () => {    // Set the 'reset' event callback.
    console.log('audio recorder reset success');
});
audioRecorder.reset();
```

### on('prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset')<a name=audiorecorder_on></a>

on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void

Subscribes to the audio recording events.

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Parameters**

| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
1811
| type     | string   | Yes  | Event type. The following events are supported:<br>- 'prepare': triggered when the [prepare](#audiorecorder_prepare) API is called and the audio recording parameters are set.<br>- 'start': triggered when the [start](#audiorecorder_start) API is called and audio recording starts.<br>- 'pause': triggered when the [pause](#audiorecorder_pause) API is called and audio recording is paused.<br>- 'resume': triggered when the [resume](#audiorecorder_resume) API is called and audio recording is resumed.<br>- 'stop': triggered when the [stop](#audiorecorder_stop) API is called and audio recording stops.<br>- 'release': triggered when the [release](#audiorecorder_release) API is called and the recording resource is released.<br>- 'reset': triggered when the [reset](#audiorecorder_reset) API is called and audio recording is reset. |
W
wusongqing 已提交
1812 1813 1814 1815 1816
| callback | ()=>void | Yes  | Callback invoked when the event is triggered.                                          |

**Example**

```js
W
wusongqing 已提交
1817
let audiorecorder = media.createAudioRecorder();                                  // Create an AudioRecorder instance.
W
wusongqing 已提交
1818 1819 1820 1821 1822 1823 1824 1825 1826
let audioRecorderConfig = {
    audioEncoder : media.AudioEncoder.AAC_LC, ,
    audioEncodeBitRate : 22050,
    audioSampleRate : 22050,
    numberOfChannels : 2,
    format : media.AudioOutputFormat.AAC_ADTS,
    uri : 'fd://xx',                                                            // The file must be created by the caller and granted with proper permissions.
    location : { latitude : 30, longitude : 130},
}
1827
audioRecorder.on('error', (error) => {                                             // Set the 'error' event callback.
W
wusongqing 已提交
1828
    console.info(`audio error called, errName is ${error.name}`);
W
wusongqing 已提交
1829 1830 1831
    console.info(`audio error called, errCode is ${error.code}`);
    console.info(`audio error called, errMessage is ${error.message}`);
});
1832
audioRecorder.on('prepare', () => {                                              // Set the 'prepare' event callback.
W
wusongqing 已提交
1833
    console.log('prepare success');
1834
    audioRecorder.start();                                                       // Start recording and trigger the 'start' event callback.
W
wusongqing 已提交
1835
});
1836
audioRecorder.on('start', () => {                                                 // Set the 'start' event callback.
W
wusongqing 已提交
1837 1838
    console.log('audio recorder start success');
});
1839
audioRecorder.on('pause', () => {                                                 // Set the 'pause' event callback.
W
wusongqing 已提交
1840 1841
    console.log('audio recorder pause success');
});
1842
audioRecorder.on('resume', () => {                                                 // Set the 'resume' event callback.
W
wusongqing 已提交
1843 1844
    console.log('audio recorder resume success');
});
1845
audioRecorder.on('stop', () => {                                                 // Set the 'stop' event callback.
W
wusongqing 已提交
1846 1847
    console.log('audio recorder stop success');
});
1848
audioRecorder.on('release', () => {                                                 // Set the 'release' event callback.
W
wusongqing 已提交
1849 1850
    console.log('audio recorder release success');
});
1851
audioRecorder.on('reset', () => {                                                 // Set the 'reset' event callback.
W
wusongqing 已提交
1852 1853
    console.log('audio recorder reset success');
});
1854
audioRecorder.prepare(audioRecorderConfig)                                       // Set recording parameters and trigger the 'prepare' event callback.
W
wusongqing 已提交
1855 1856 1857 1858 1859 1860
```

### on('error')

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

1861
Subscribes to audio recording error events. After an error event is reported, you must handle the event and exit the recording.
W
wusongqing 已提交
1862 1863 1864 1865 1866 1867 1868

**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

**Parameters**

| Name  | Type         | Mandatory| Description                                                        |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
1869
| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>The **'error'** event is triggered when an error occurs during audio recording. |
W
wusongqing 已提交
1870 1871 1872 1873 1874
| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.                                      |

**Example**

```js
1875
audioRecorder.on('error', (error) => {                                  // Set the 'error' event callback.
W
wusongqing 已提交
1876
    console.info(`audio error called, errName is ${error.name}`);       // Print the error name.
W
wusongqing 已提交
1877 1878 1879
    console.info(`audio error called, errCode is ${error.code}`);       // Print the error code.
    console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type.
});
1880
audioRecorder.prepare();                                                  // Do no set any parameter in prepare and trigger the 'error' event callback.
W
wusongqing 已提交
1881 1882 1883 1884 1885 1886
```

## AudioRecorderConfig

Describes audio recording configurations.

W
wusongqing 已提交
1887 1888
**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1889 1890
| Name                 | Type                               | Mandatory| Description                                                        |
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1891
| audioEncoder<sup>(deprecated)</sup>          | [AudioEncoder](#audioencoder)           | No  | Audio encoding format. The default value is **AAC_LC**.<br>**Note**: This parameter is deprecated since API version 8. Use **audioEncoderMime** instead.                            |
W
wusongqing 已提交
1892 1893 1894
| audioEncodeBitRate    | number                                  | No  | Audio encoding bit rate. The default value is **48000**.                             |
| audioSampleRate       | number                                  | No  | Audio sampling rate. The default value is **48000**.                             |
| numberOfChannels      | number                                  | No  | Number of audio channels. The default value is **2**.                                 |
W
wusongqing 已提交
1895
| format<sup>(deprecated)</sup>                | [AudioOutputFormat](#audiooutputformat) | No  | Audio output format. The default value is **MPEG_4**.<br>**Note**: This parameter is deprecated since API version 8. Use **fileFormat** instead.                        |
W
wusongqing 已提交
1896
| location              | [Location](#location)                   | No  | Geographical location of the recorded audio.                                        |
W
wusongqing 已提交
1897 1898 1899
| uri                   | string                                  | Yes  | Audio output URI. Supported: fd://xx (fd number)<br>![](figures/en-us_image_url.png) <br>The file must be created by the caller and granted with proper permissions.|
| audioEncoderMime<sup>8+</sup>      | [CodecMimeType](#codecmimetype8)        | No  | Audio encoding format.          |
| fileFormat<sup>8+</sup>      | [ContainerFormatType](#containerformattype8)        | No  | Audio encoding format.        |
W
wusongqing 已提交
1900

W
wusongqing 已提交
1901 1902 1903 1904
## AudioEncoder<sup>(deprecated)</sup>

> **NOTE**
> This API is deprecated since API version 8. You are advised to use [CodecMimeType](#codecmimetype8) instead.
W
wusongqing 已提交
1905 1906 1907

Enumerates the audio encoding formats.

W
wusongqing 已提交
1908 1909
**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1910 1911
| Name   | Default Value| Description                                                        |
| ------- | ------ | ------------------------------------------------------------ |
W
wusongqing 已提交
1912 1913 1914
| DEFAULT | 0      | Default encoding format.<br>This API is defined but not implemented yet.|
| AMR_NB  | 1      | AMR-NB.<br>This API is defined but not implemented yet.|
| AMR_WB  | 2      | Adaptive Multi Rate-Wide Band Speech Codec (AMR-WB).<br>This API is defined but not implemented yet.|
W
wusongqing 已提交
1915
| AAC_LC  | 3      | Advanced Audio Coding Low Complexity (AAC-LC).|
W
wusongqing 已提交
1916
| HE_AAC  | 4      | High-Efficiency Advanced Audio Coding (HE_AAC).<br>This API is defined but not implemented yet.|
W
wusongqing 已提交
1917 1918


W
wusongqing 已提交
1919 1920 1921
## AudioOutputFormat<sup>(deprecated)</sup>

> **NOTE**
W
wusongqing 已提交
1922
> This API is deprecated since API version 8. You are advised to use [ContainerFormatType](#containerformattype8) instead.
W
wusongqing 已提交
1923 1924 1925

Enumerates the audio output formats.

W
wusongqing 已提交
1926 1927
**System capability**: SystemCapability.Multimedia.Media.AudioRecorder

W
wusongqing 已提交
1928 1929
| Name    | Default Value| Description                                                        |
| -------- | ------ | ------------------------------------------------------------ |
W
wusongqing 已提交
1930
| DEFAULT  | 0      | Default encapsulation format.<br>This API is defined but not implemented yet.|
W
wusongqing 已提交
1931
| MPEG_4   | 2      | MPEG-4.                                          |
W
wusongqing 已提交
1932 1933
| AMR_NB   | 3      | AMR_NB.<br>This API is defined but not implemented yet.|
| AMR_WB   | 4      | AMR_WB.<br>This API is defined but not implemented yet.|
W
wusongqing 已提交
1934
| AAC_ADTS | 6      | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.|
W
wusongqing 已提交
1935

W
wusongqing 已提交
1936
## VideoRecorder<sup>9+</sup>
W
wusongqing 已提交
1937

W
wusongqing 已提交
1938
Implements video recording. Before calling an API of the **VideoRecorder** class, you must call [createVideoRecorder()](#mediacreatevideorecorder9) to create a [VideoRecorder](#videorecorder9) instance.
W
wusongqing 已提交
1939 1940 1941 1942 1943

For details about the video recording demo, see [Video Recording Development](../../media/video-recorder.md).

### Attributes

W
wusongqing 已提交
1944 1945 1946 1947
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

| Name              | Type                                  | Readable| Writable| Description            |
| ------------------ | -------------------------------------- | ---- | ---- | ---------------- |
W
wusongqing 已提交
1948
| state<sup>9+</sup> | [VideoRecordState](#videorecordstate9) | Yes  | No  | Video recording state.|
W
wusongqing 已提交
1949

W
wusongqing 已提交
1950
### prepare<sup>9+</sup><a name=videorecorder_prepare1></a>
W
wusongqing 已提交
1951 1952 1953 1954 1955

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

Sets video recording parameters in asynchronous mode. This API uses a callback to return the result.

W
wusongqing 已提交
1956
**Required permissions:** ohos.permission.MICROPHONE
W
wusongqing 已提交
1957 1958 1959 1960 1961

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

W
wusongqing 已提交
1962 1963
| Name  | Type                                        | Mandatory| Description                               |
| -------- | -------------------------------------------- | ---- | ----------------------------------- |
W
wusongqing 已提交
1964
| config   | [VideoRecorderConfig](#videorecorderconfig9) | Yes  | Video recording parameters to set.           |
W
wusongqing 已提交
1965
| callback | AsyncCallback\<void>                         | Yes  | Callback used to return the result.|
W
wusongqing 已提交
1966 1967 1968 1969 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

**Example**

```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,
    url : 'fd://xx',   // The file must be created by the caller and granted with proper permissions.
    orientationHint : 0,
    location : { latitude : 30, longitude : 130 },
}

// asyncallback
let videoRecorder = null;
let events = require('events');
W
wusongqing 已提交
1995
let eventEmitter = new events.EventEmitter();
W
wusongqing 已提交
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017

eventEmitter.on('prepare', () => {
    videoRecorder.prepare(videoConfig, (err) => {
        if (typeof (err) == 'undefined') {
            console.info('prepare success');
        } else {
            console.info('prepare failed and error is ' + err.message);
        }
    });
});

media.createVideoRecorder((err, recorder) => {
    if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') {
        videoRecorder = recorder;
        console.info('createVideoRecorder success');
        eventEmitter.emit('prepare');                                        // Trigger the 'prepare' event.
    } else {
        console.info('createVideoRecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2018
### prepare<sup>9+</sup><a name=videorecorder_prepare2></a>
W
wusongqing 已提交
2019 2020 2021 2022 2023

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

Sets video recording parameters in asynchronous mode. This API uses a promise to return the result.

2024
**Required permissions:** ohos.permission.MICROPHONE
W
wusongqing 已提交
2025 2026 2027 2028 2029

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

W
wusongqing 已提交
2030 2031
| Name| Type                                        | Mandatory| Description                    |
| ------ | -------------------------------------------- | ---- | ------------------------ |
W
wusongqing 已提交
2032
| config | [VideoRecorderConfig](#videorecorderconfig9) | Yes  | Video recording parameters to set.|
W
wusongqing 已提交
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066

**Return value**

| Type          | Description                                    |
| -------------- | ---------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```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,
    url : 'fd://xx',   // The file must be created by the caller and granted with proper permissions.
    orientationHint : 0,
    location : { latitude : 30, longitude : 130 },
}

// promise
let videoRecorder = null;
W
wusongqing 已提交
2067
media.createVideoRecorder().then((recorder) => {
W
wusongqing 已提交
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
    if (typeof (recorder) != 'undefined') {
        videoRecorder = recorder;
        console.info('createVideoRecorder success');
    } else {
        console.info('createVideoRecorder failed');
    }
}).catch((err) => {
    console.info('catch err error message is ' + err.message);
});

W
wusongqing 已提交
2078
videoRecorder.prepare(videoConfig).then(() => {
W
wusongqing 已提交
2079 2080 2081 2082 2083 2084
    console.info('prepare success');
}).catch((err) => {
    console.info('prepare failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2085
### getInputSurface<sup>9+</sup>
W
wusongqing 已提交
2086 2087 2088 2089 2090 2091 2092

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

Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.

Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.

W
wusongqing 已提交
2093
This API can be called only after [prepare()](#videorecorder_prepare1) is called.
W
wusongqing 已提交
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                  | Mandatory| Description                       |
| -------- | ---------------------- | ---- | --------------------------- |
| callback | AsyncCallback\<string> | Yes  | Callback used to obtain the result.|

**Example**

```js
// asyncallback
W
wusongqing 已提交
2107
let surfaceID = null;                                               // Surface ID passed to the external system.
W
wusongqing 已提交
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117
videoRecorder.getInputSurface((err, surfaceId) => {
    if (typeof (err) == 'undefined') {
        console.info('getInputSurface success');
        surfaceID = surfaceId;
    } else {
        console.info('getInputSurface failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2118
### getInputSurface<sup>9+</sup>
W
wusongqing 已提交
2119 2120 2121 2122 2123 2124 2125

getInputSurface(): Promise\<string>;

 Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.

Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.

W
wusongqing 已提交
2126
This API can be called only after [prepare()](#videorecorder_prepare1) is called.
W
wusongqing 已提交
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type            | Description                            |
| ---------------- | -------------------------------- |
| Promise\<string> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2140
let surfaceID = null;                                               // Surface ID passed to the external system.
W
wusongqing 已提交
2141
videoRecorder.getInputSurface().then((surfaceId) => {
W
wusongqing 已提交
2142 2143 2144 2145 2146 2147 2148
    console.info('getInputSurface success');
    surfaceID = surfaceId;
}).catch((err) => {
    console.info('getInputSurface failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2149
### start<sup>9+</sup><a name=videorecorder_start1></a>
W
wusongqing 已提交
2150 2151 2152 2153 2154

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

Starts video recording in asynchronous mode. This API uses a callback to return the result.

2155
This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) are called, because the data source must pass data to the surface first.
W
wusongqing 已提交
2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                        |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.start((err) => {
    if (typeof (err) == 'undefined') {
        console.info('start videorecorder success');
    } else {
        console.info('start videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2178
### start<sup>9+</sup><a name=videorecorder_start2></a>
W
wusongqing 已提交
2179 2180 2181 2182 2183

start(): Promise\<void>;

Starts video recording in asynchronous mode. This API uses a promise to return the result.

2184
This API can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) are called, because the data source must pass data to the surface first.
W
wusongqing 已提交
2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                 |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2198
videoRecorder.start().then(() => {
W
wusongqing 已提交
2199 2200 2201 2202 2203 2204
    console.info('start videorecorder success');
}).catch((err) => {
    console.info('start videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2205
### pause<sup>9+</sup><a name=videorecorder_pause1></a>
W
wusongqing 已提交
2206 2207 2208 2209 2210

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

Pauses video recording in asynchronous mode. This API uses a callback to return the result.

W
wusongqing 已提交
2211
This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
W
wusongqing 已提交
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                        |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.pause((err) => {
    if (typeof (err) == 'undefined') {
        console.info('pause videorecorder success');
    } else {
        console.info('pause videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2234
### pause<sup>9+</sup><a name=videorecorder_pause2></a>
W
wusongqing 已提交
2235 2236 2237 2238 2239

pause(): Promise\<void>;

Pauses video recording in asynchronous mode. This API uses a promise to return the result.

W
wusongqing 已提交
2240
This API can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
W
wusongqing 已提交
2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                 |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2254
videoRecorder.pause().then(() => {
W
wusongqing 已提交
2255 2256 2257 2258 2259 2260
    console.info('pause videorecorder success');
}).catch((err) => {
    console.info('pause videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2261
### resume<sup>9+</sup><a name=videorecorder_resume1></a>
W
wusongqing 已提交
2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287

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

Resumes video recording in asynchronous mode. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                        |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.resume((err) => {
    if (typeof (err) == 'undefined') {
        console.info('resume videorecorder success');
    } else {
        console.info('resume videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2288
### resume<sup>9+</sup><a name=videorecorder_resume2></a>
W
wusongqing 已提交
2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305

resume(): Promise\<void>;

Resumes video recording in asynchronous mode. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                 |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2306
videoRecorder.resume().then(() => {
W
wusongqing 已提交
2307 2308 2309 2310 2311 2312
    console.info('resume videorecorder success');
}).catch((err) => {
    console.info('resume videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2313
### stop<sup>9+</sup><a name=videorecorder_stop1></a>
W
wusongqing 已提交
2314 2315 2316 2317 2318

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

Stops video recording in asynchronous mode. This API uses a callback to return the result.

2319
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) again.
W
wusongqing 已提交
2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                        |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.stop((err) => {
    if (typeof (err) == 'undefined') {
        console.info('stop videorecorder success');
    } else {
        console.info('stop videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2342
### stop<sup>9+</sup><a name=videorecorder_stop2></a>
W
wusongqing 已提交
2343 2344 2345 2346 2347

stop(): Promise\<void>;

Stops video recording in asynchronous mode. This API uses a promise to return the result.

2348
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) again.
W
wusongqing 已提交
2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                 |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2362
videoRecorder.stop().then(() => {
W
wusongqing 已提交
2363 2364 2365 2366 2367 2368
    console.info('stop videorecorder success');
}).catch((err) => {
    console.info('stop videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2369
### release<sup>9+</sup><a name=videorecorder_release1></a>
W
wusongqing 已提交
2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395

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

Releases the video recording resource in asynchronous mode. This API uses a callback to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                            |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.release((err) => {
    if (typeof (err) == 'undefined') {
        console.info('release videorecorder success');
    } else {
        console.info('release videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2396
### release<sup>9+</sup><a name=videorecorder_release2></a>
W
wusongqing 已提交
2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413

release(): Promise\<void>;

Releases the video recording resource in asynchronous mode. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                     |
| -------------- | ----------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2414
videoRecorder.release().then(() => {
W
wusongqing 已提交
2415 2416 2417 2418 2419 2420
    console.info('release videorecorder success');
}).catch((err) => {
    console.info('release videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2421
### reset<sup>9+</sup><a name=videorecorder_reset1></a>
W
wusongqing 已提交
2422 2423 2424 2425 2426

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

Resets video recording in asynchronous mode. This API uses a callback to return the result.

2427
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) again.
W
wusongqing 已提交
2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type                | Mandatory| Description                        |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|

**Example**

```js
// asyncallback
videoRecorder.reset((err) => {
    if (typeof (err) == 'undefined') {
        console.info('reset videorecorder success');
    } else {
        console.info('reset videorecorder failed and error is ' + err.message);
    }
});
```

W
wusongqing 已提交
2450
### reset<sup>9+</sup><a name=videorecorder_reset2></a>
W
wusongqing 已提交
2451 2452 2453 2454 2455

reset(): Promise\<void>;

Resets video recording in asynchronous mode. This API uses a promise to return the result.

2456
To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface9) again.
W
wusongqing 已提交
2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Return value**

| Type          | Description                                 |
| -------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|

**Example**

```js
// promise
W
wusongqing 已提交
2470
videoRecorder.reset().then(() => {
W
wusongqing 已提交
2471 2472 2473 2474 2475 2476
    console.info('reset videorecorder success');
}).catch((err) => {
    console.info('reset videorecorder failed and catch error is ' + err.message);
});
```

W
wusongqing 已提交
2477
### on('error')<sup>9+</sup>
W
wusongqing 已提交
2478 2479 2480

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

2481
Subscribes to video recording error events. After an error event is reported, you must handle the event and exit the recording.
W
wusongqing 已提交
2482 2483 2484 2485 2486 2487 2488

**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

**Parameters**

| Name  | Type         | Mandatory| Description                                                        |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
2489
| type     | string        | Yes  | Event type, which is **'error'** in this case.<br>The **'error'** event is triggered when an error occurs during video recording. |
W
wusongqing 已提交
2490 2491 2492 2493 2494
| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.                                      |

**Example**

```js
2495
videoRecorder.on('error', (error) => {                                  // Set the 'error event' callback.
W
wusongqing 已提交
2496
    console.info(`audio error called, errName is ${error.name}`);       // Print the error name.
W
wusongqing 已提交
2497 2498 2499 2500 2501 2502
    console.info(`audio error called, errCode is ${error.code}`);       // Print the error code.
    console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type.
});
// This event is reported when an error occurs during the retrieval of videoRecordState.
```

W
wusongqing 已提交
2503
## VideoRecordState<sup>9+</sup>
W
wusongqing 已提交
2504 2505 2506

Enumerates the video recording states. You can obtain the state through the **state** attribute.

W
wusongqing 已提交
2507 2508 2509 2510 2511 2512 2513 2514 2515
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

| Name    | Type  | Description                  |
| -------- | ------ | ---------------------- |
| idle     | string | The video recorder is idle.        |
| prepared | string | The video recording parameters are set.|
| playing  | string | Video recording is in progress.        |
| paused   | string | Video recording is paused.        |
| stopped  | string | Video recording is stopped.        |
W
wusongqing 已提交
2516
| error    | string | Video recording is in the error state.            |
W
wusongqing 已提交
2517

W
wusongqing 已提交
2518
## VideoRecorderConfig<sup>9+</sup>
W
wusongqing 已提交
2519 2520 2521

Describes the video recording parameters.

W
wusongqing 已提交
2522 2523
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

W
wusongqing 已提交
2524 2525 2526 2527 2528 2529 2530
| Name           | Type                                      | Mandatory| Description                                                        |
| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| audioSourceType | [AudioSourceType](#audiosourcetype9)           | Yes  | Type of the audio source for video recording.                                      |
| videoSourceType | [VideoSourceType](#videosourcetype9)           | Yes  | Type of the video source for video recording.                                      |
| profile         | [VideoRecorderProfile](#videorecorderprofile9) | Yes  | Video recording profile.                                         |
| rotation        | number                                         | No  | Rotation angle of the recorded video.                                        |
| location        | [Location](#location)                          | No  | Geographical location of the recorded video.                                        |
2531
| url             | string                                         | Yes  | Video output URL. Supported: fd://xx (fd number)<br>![](figures/en-us_image_url.png) <br>**Required permissions**: ohos.permission.READ_MEDIA|
W
wusongqing 已提交
2532

W
wusongqing 已提交
2533
## AudioSourceType<sup>9+</sup>
W
wusongqing 已提交
2534 2535 2536

Enumerates the audio source types for video recording.

W
wusongqing 已提交
2537 2538 2539 2540 2541 2542
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

| Name                     | Value  | Description                  |
| ------------------------- | ---- | ---------------------- |
| AUDIO_SOURCE_TYPE_DEFAULT | 0    | Default audio input source.|
| AUDIO_SOURCE_TYPE_MIC     | 1    | Mic audio input source. |
W
wusongqing 已提交
2543

W
wusongqing 已提交
2544
## VideoSourceType<sup>9+</sup>
W
wusongqing 已提交
2545 2546 2547

Enumerates the video source types for video recording.

W
wusongqing 已提交
2548 2549 2550 2551 2552 2553
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

| Name                         | Value  | Description                           |
| ----------------------------- | ---- | ------------------------------- |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0    | The input surface carries raw data.|
| VIDEO_SOURCE_TYPE_SURFACE_ES  | 1    | The input surface carries ES data. |
W
wusongqing 已提交
2554

W
wusongqing 已提交
2555
## VideoRecorderProfile<sup>9+</sup>
W
wusongqing 已提交
2556 2557 2558

Describes the video recording profile.

W
wusongqing 已提交
2559 2560 2561 2562 2563 2564
**System capability**: SystemCapability.Multimedia.Media.VideoRecorder

| Name            | Type                                    | Mandatory| Description            |
| ---------------- | -------------------------------------------- | ---- | ---------------- |
| audioBitrate     | number                                       | Yes  | Audio encoding bit rate.|
| audioChannels    | number                                       | Yes  | Number of audio channels.|
W
wusongqing 已提交
2565
| audioCodec       | [CodecMimeType](#codecmimetype8)             | Yes  | Audio encoding format.  |
W
wusongqing 已提交
2566 2567
| audioSampleRate  | number                                       | Yes  | Audio sampling rate.    |
| fileFormat       | [ContainerFormatType](#containerformattype8) | Yes  | Container format of a file.|
W
wusongqing 已提交
2568
| videoBitrate     | number                                       | Yes  | Video encoding bit rate.|
W
wusongqing 已提交
2569
| videoCodec       | [CodecMimeType](#codecmimetype8)             | Yes  | Video encoding format.  |
W
wusongqing 已提交
2570 2571
| videoFrameWidth  | number                                       | Yes  | Width of the recorded video frame.|
| videoFrameHeight | number                                       | Yes  | Height of the recorded video frame.|
W
wusongqing 已提交
2572
| videoFrameRate   | number                                       | Yes  | Video frame rate.  |
W
wusongqing 已提交
2573 2574 2575 2576 2577

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

Enumerates the container format types (CFTs).

W
wusongqing 已提交
2578 2579 2580 2581
**System capability**: SystemCapability.Multimedia.Media.Core

| Name       | Value   | Description                 |
| ----------- | ----- | --------------------- |
W
wusongqing 已提交
2582
| CFT_MPEG_4  | "mp4" | Video container format MPEG-4.|
W
wusongqing 已提交
2583
| CFT_MPEG_4A | "m4a" | Audio container format M4A.|
W
wusongqing 已提交
2584

W
wusongqing 已提交
2585
## Location
W
wusongqing 已提交
2586 2587 2588

Describes the geographical location of the recorded video.

W
wusongqing 已提交
2589 2590 2591 2592 2593 2594
**System capability**: SystemCapability.Multimedia.Media.Core

| Name     | Type| Mandatory| Description            |
| --------- | -------- | ---- | ---------------- |
| latitude  | number   | Yes  | Latitude of the geographical location.|
| longitude | number   | Yes  | Longitude of the geographical location.|