js-apis-audio.md 111.7 KB
Newer Older
1
# Audio Management
V
Vaidegi B 已提交
2

W
wusongqing 已提交
3 4
>  **NOTE**
>
W
wusongqing 已提交
5 6 7
>  The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>  API version 9 is a canary release for trial use. The APIs of this version may be unstable.
V
Vaidegi B 已提交
8

9 10
This module provides the following common audio-related functions:

W
wusongqing 已提交
11 12 13
- [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
14 15

## Modules to Import
W
wusongqing 已提交
16 17 18 19 20

```
import audio from '@ohos.multimedia.audio';
```

W
wusongqing 已提交
21

22
## audio.getAudioManager
V
Vaidegi B 已提交
23

24
getAudioManager(): AudioManager
25

26
Obtains an **AudioManager** instance.
W
wusongqing 已提交
27

W
wusongqing 已提交
28
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
29

W
wusongqing 已提交
30 31 32 33
**Return value**
| Type                         | Description        |
| ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | **AudioManager** instance.|
W
wusongqing 已提交
34

W
wusongqing 已提交
35
**Example**
W
wusongqing 已提交
36 37 38 39
```
var audioManager = audio.getAudioManager();
```

40
## audio.createAudioRenderer<sup>8+</sup>
41

42
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
43

W
wusongqing 已提交
44 45 46
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Renderer
47

W
wusongqing 已提交
48
**Parameters**
49

W
wusongqing 已提交
50 51 52 53
| Name  | Type                                           | Mandatory| Description            |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options  | [AudioRendererOptions](#audiorendereroptions8)  | Yes  | Renderer configurations.    |
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes  | Callback used to return the **AudioRenderer** instance.|
54

W
wusongqing 已提交
55
**Example**
56 57

```
58
import audio from '@ohos.multimedia.audio';
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

audio.createAudioRenderer(audioRendererOptions,(err, data) => {
    if (err) {
79
        console.error(`AudioRenderer Created : Error: ${err.message}`);
80 81
    }
    else {
82 83
        console.info('AudioRenderer Created : Success : SUCCESS');
        let audioRenderer = data;
84 85 86
    }
});
```
W
wusongqing 已提交
87

88
## audio.createAudioRenderer<sup>8+</sup>
89

W
wusongqing 已提交
90 91 92
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>

Obtains an **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
93

W
wusongqing 已提交
94
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
95

W
wusongqing 已提交
96
**Parameters**
97

W
wusongqing 已提交
98 99 100
| Name | Type                                          | Mandatory| Description        |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes  | Renderer configurations.|
V
Vaidegi B 已提交
101

W
wusongqing 已提交
102
**Return value**
V
Vaidegi B 已提交
103

W
wusongqing 已提交
104 105 106
| Type                                     | Description            |
| ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
V
Vaidegi B 已提交
107

W
wusongqing 已提交
108
**Example**
V
Vaidegi B 已提交
109 110

```
111 112
import audio from '@ohos.multimedia.audio';

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

131 132 133 134 135 136 137
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : ERROR : '+err.message);
});
V
Vaidegi B 已提交
138 139
```

140
## audio.createAudioCapturer<sup>8+</sup>
141

142
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
V
Vaidegi B 已提交
143

W
wusongqing 已提交
144
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
145

W
wusongqing 已提交
146
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
147

W
wusongqing 已提交
148
**Parameters**
V
Vaidegi B 已提交
149

W
wusongqing 已提交
150 151 152 153 154 155
| Name  | Type                                           | Mandatory| Description            |
| :------- | :---------------------------------------------- | :--- | :--------------- |
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the **AudioCapturer** instance.|

**Example**
156 157

```
158
import audio from '@ohos.multimedia.audio';
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
}

audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
    if (err) {
        console.error(`AudioCapturer Created : Error: ${err.message}`);
    }
    else {
        console.info('AudioCapturer Created : Success : SUCCESS');
182
        let audioCapturer = data;
183 184 185 186
    }
});
```

187
## audio.createAudioCapturer<sup>8+</sup>
188

189
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
190

W
wusongqing 已提交
191 192 193
Obtains an **AudioCapturer** instance. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Capturer
194

W
wusongqing 已提交
195
**Parameters**
196

W
wusongqing 已提交
197 198 199
| Name | Type                                          | Mandatory| Description            |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
200

W
wusongqing 已提交
201
**Return value**
V
Vaidegi B 已提交
202

W
wusongqing 已提交
203 204 205
| Type                                     | Description          |
| ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
V
Vaidegi B 已提交
206

W
wusongqing 已提交
207
**Example**
V
Vaidegi B 已提交
208 209

```
210 211
import audio from '@ohos.multimedia.audio';

212 213 214 215 216 217 218 219 220 221 222 223 224
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
225 226
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
227
}
V
Vaidegi B 已提交
228

229 230 231 232 233 234 235
var audioCapturer;
audio.createAudioRenderer(audioCapturerOptions).then((data) => {
    audioCapturer = data;
    console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioCapturer Created : ERROR : '+err.message);
});
236
```
V
Vaidegi B 已提交
237

238
## AudioVolumeType
W
wusongqing 已提交
239

W
wusongqing 已提交
240
Enumerates the audio stream types.
W
wusongqing 已提交
241

W
wusongqing 已提交
242 243 244 245 246 247 248 249
**System capability**: SystemCapability.Multimedia.Audio.Volume

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
| RINGTONE                     | 2      | Audio stream for ringtones.    |
| MEDIA                        | 3      | Audio stream for media purpose.    |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
Z
zengyawen 已提交
250

V
Vaidegi B 已提交
251

252
## DeviceFlag
W
wusongqing 已提交
253

W
wusongqing 已提交
254
Enumerates the audio device flags.
W
wusongqing 已提交
255

W
wusongqing 已提交
256
**System capability**: SystemCapability.Multimedia.Audio.Device
Z
zengyawen 已提交
257

W
wusongqing 已提交
258 259 260 261 262
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1      | Output device.|
| INPUT_DEVICES_FLAG  | 2      | Input device.|
| ALL_DEVICES_FLAG    | 3      | All devices.|
V
Vaidegi B 已提交
263

264 265

## DeviceRole
W
wusongqing 已提交
266

W
wusongqing 已提交
267 268 269
Enumerates the audio device roles.

**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
270

W
wusongqing 已提交
271 272 273 274
| Name         | Default Value| Description          |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
275

V
Vaidegi B 已提交
276

277
## DeviceType
W
wusongqing 已提交
278

W
wusongqing 已提交
279
Enumerates the audio device types.
W
wusongqing 已提交
280

W
wusongqing 已提交
281
**System capability**: SystemCapability.Multimedia.Audio.Device
282

W
wusongqing 已提交
283 284 285 286 287 288 289 290 291 292 293
| Name            | Default Value| Description                                                     |
| ---------------- | ------ | --------------------------------------------------------- |
| INVALID          | 0      | Invalid device.                                               |
| EARPIECE         | 1      | Earpiece.                                                   |
| SPEAKER          | 2      | Speaker.                                                 |
| WIRED_HEADSET    | 3      | Wired headset with a microphone.                                     |
| WIRED_HEADPHONES | 4      | Wired headset without microphone.                                     |
| BLUETOOTH_SCO    | 7      | Bluetooth device using Synchronous Connection Oriented (SCO) links.     |
| BLUETOOTH_A2DP   | 8      | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
| MIC              | 15     | Microphone.                                                 |
| USB_HEADSET      | 22     | USB Type-C headset.                                      |
Z
zengyawen 已提交
294

W
wusongqing 已提交
295
## ActiveDeviceType
V
Vaidegi B 已提交
296

W
wusongqing 已提交
297 298
Enumerates the active device types.

W
wusongqing 已提交
299
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
300

W
wusongqing 已提交
301 302 303 304
| Name         | Default Value| Description                                                |
| ------------- | ------ | ---------------------------------------------------- |
| SPEAKER       | 2      | Speaker.                                            |
| BLUETOOTH_SCO | 7      | Bluetooth device using the SCO links.|
W
wusongqing 已提交
305 306

## AudioRingMode
W
wusongqing 已提交
307

W
wusongqing 已提交
308
Enumerates the ringer modes.
W
wusongqing 已提交
309

W
wusongqing 已提交
310
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
311

W
wusongqing 已提交
312 313 314 315 316
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | Silent mode.|
| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
| RINGER_MODE_NORMAL  | 2      | Normal mode.|
317 318

## AudioSampleFormat<sup>8+</sup>
V
Vaidegi B 已提交
319

W
wusongqing 已提交
320
Enumerate the audio sample formats.
V
Vaidegi B 已提交
321

W
wusongqing 已提交
322
**System capability**: SystemCapability.Multimedia.Audio.Core
323

W
wusongqing 已提交
324 325 326 327 328 329 330
| Name                 | Default Value| Description                      |
| --------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1     | Invalid format.                |
| SAMPLE_FORMAT_U8      | 0      | Unsigned 8-bit integer.           |
| SAMPLE_FORMAT_S16LE   | 1      | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE   | 2      | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE   | 3      | Signed 32-bit integer, little endian.|
331 332

## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
333 334 335

Enumerates the audio channels.

W
wusongqing 已提交
336
**System capability**: SystemCapability.Multimedia.Audio.Core
337

W
wusongqing 已提交
338 339 340 341
| Name     | Default Value  | Description    |
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
342 343

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
344 345 346

Enumerates the audio sampling rates.

W
wusongqing 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
**System capability**: SystemCapability.Multimedia.Audio.Core

| Name             | Default Value| Description           |
| ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000  | 8000   | The sampling rate is 8000. |
| SAMPLE_RATE_11025 | 11025  | The sampling rate is 11025.|
| SAMPLE_RATE_12000 | 12000  | The sampling rate is 12000.|
| SAMPLE_RATE_16000 | 16000  | The sampling rate is 16000.|
| SAMPLE_RATE_22050 | 22050  | The sampling rate is 22050.|
| SAMPLE_RATE_24000 | 24000  | The sampling rate is 24000.|
| SAMPLE_RATE_32000 | 32000  | The sampling rate is 32000.|
| SAMPLE_RATE_44100 | 44100  | The sampling rate is 44100.|
| SAMPLE_RATE_48000 | 48000  | The sampling rate is 48000.|
| SAMPLE_RATE_64000 | 64000  | The sampling rate is 64000.|
| SAMPLE_RATE_96000 | 96000  | The sampling rate is 96000.|
362 363 364

## AudioEncodingType<sup>8+</sup>

V
Vaidegi B 已提交
365 366
Enumerates the audio encoding types.

W
wusongqing 已提交
367
**System capability**: SystemCapability.Multimedia.Audio.Core
V
Vaidegi B 已提交
368

W
wusongqing 已提交
369 370 371 372
| Name                 | Default Value| Description     |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
373

374 375
## ContentType

W
wusongqing 已提交
376
Enumerates the audio content types.
377

W
wusongqing 已提交
378
**System capability**: SystemCapability.Multimedia.Audio.Core
V
Vaidegi B 已提交
379

W
wusongqing 已提交
380 381 382 383 384 385 386 387
| Name                              | Default Value| Description      |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
| CONTENT_TYPE_SONIFICATION          | 4      | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
V
Vaidegi B 已提交
388

389 390
## StreamUsage

W
wusongqing 已提交
391
Enumerates the audio stream usage.
392

W
wusongqing 已提交
393
**System capability**: SystemCapability.Multimedia.Audio.Core
V
Vaidegi B 已提交
394

W
wusongqing 已提交
395 396 397 398 399 400
| Name                              | Default Value| Description      |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN               | 0      | Unknown usage.|
| STREAM_USAGE_MEDIA                 | 1      | Used for media.    |
| STREAM_USAGE_VOICE_COMMUNICATION   | 2      | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6      | Used for notification.|
V
Vaidegi B 已提交
401

402 403
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
404 405
Enumerates the audio states.

W
wusongqing 已提交
406
**System capability**: SystemCapability.Multimedia.Audio.Core
V
Vaidegi B 已提交
407

W
wusongqing 已提交
408 409 410 411 412 413 414 415 416
| Name          | Default Value| Description            |
| -------------- | ------ | ---------------- |
| STATE_INVALID  | -1     | Invalid state.      |
| STATE_NEW      | 0      | Creating instance state.|
| STATE_PREPARED | 1      | Prepared.      |
| STATE_RUNNING  | 2      | Running.    |
| STATE_STOPPED  | 3      | Stopped.      |
| STATE_RELEASED | 4      | Released.      |
| STATE_PAUSED   | 5      | Paused.      |
V
Vaidegi B 已提交
417

418 419
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
420 421
Enumerates the audio renderer rates.

W
wusongqing 已提交
422
**System capability**: SystemCapability.Multimedia.Audio.Renderer
423

W
wusongqing 已提交
424 425 426 427 428
| Name              | Default Value| Description      |
| ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0      | Normal rate.|
| RENDER_RATE_DOUBLE | 1      | Double rate.   |
| RENDER_RATE_HALF   | 2      | Half rate. |
V
Vaidegi B 已提交
429

430
## InterruptType
V
Vaidegi B 已提交
431

W
wusongqing 已提交
432 433 434 435 436 437 438 439 440 441
Enumerates the audio interruption types.

**System capability**: SystemCapability.Multimedia.Audio.Renderer

| Name                | Default Value| Description                  |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|

## InterruptForceType<sup>9+</sup>
V
Vaidegi B 已提交
442

W
wusongqing 已提交
443
Enumerates the types of force that causes audio interruption.
V
Vaidegi B 已提交
444

W
wusongqing 已提交
445 446 447 448 449 450
**System capability**: SystemCapability.Multimedia.Audio.Renderer

| Name           | Default Value| Description                                |
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
451 452

## InterruptHint
V
Vaidegi B 已提交
453

W
wusongqing 已提交
454
Enumerates the hints provided along with audio interruption.
V
Vaidegi B 已提交
455

W
wusongqing 已提交
456
**System capability**: SystemCapability.Multimedia.Audio.Renderer
457

W
wusongqing 已提交
458 459 460 461 462 463 464 465
| Name                              | Default Value| Description                                        |
| ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | None.                                    |
| INTERRUPT_HINT_RESUME              | 1      | Resume the playback.                              |
| INTERRUPT_HINT_PAUSE               | 2      | Paused/Pause the playback.                              |
| INTERRUPT_HINT_STOP                | 3      | Stopped/Stop the playback.                              |
| INTERRUPT_HINT_DUCK                | 4      | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | Unducked the playback.                              |
466 467 468

## InterruptActionType

W
wusongqing 已提交
469
Enumerates the returned event types for audio interruption events.
470

W
wusongqing 已提交
471
**System capability**: SystemCapability.Multimedia.Audio.Renderer
472

W
wusongqing 已提交
473 474 475 476
| Name          | Default Value| Description              |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | Focus gain event.|
| TYPE_INTERRUPT | 1      | Audio interruption event.|
477 478

## AudioStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
479

480
Describes audio stream information.
V
Vaidegi B 已提交
481

W
wusongqing 已提交
482
**System capability**: SystemCapability.Multimedia.Audio.Core
V
Vaidegi B 已提交
483

W
wusongqing 已提交
484 485 486 487 488 489
| Name        | Type                                    | Mandatory| Description              |
| ------------ | ---------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes  | Audio sampling rate.|
| channels     | [AudioChannel](#audiochannel8)           | Yes  | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes  | Audio sample format.    |
| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes  | Audio encoding type.    |
490 491

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
492 493 494

Describes audio renderer information.

W
wusongqing 已提交
495
**System capability**: SystemCapability.Multimedia.Audio.Core
496

W
wusongqing 已提交
497 498 499 500 501
| Name         | Type                       | Mandatory| Description            |
| ------------- | --------------------------- | ---- | ---------------- |
| content       | [ContentType](#contenttype) | Yes  | Audio content type.      |
| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
| rendererFlags | number                      | Yes  | Audio renderer flags.|
V
Vaidegi B 已提交
502

503
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
504

W
wusongqing 已提交
505
Describes audio renderer configurations.
G
Geevarghese V K 已提交
506

W
wusongqing 已提交
507
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Geevarghese V K 已提交
508

W
wusongqing 已提交
509 510 511 512
| Name        | Type                                    | Mandatory| Description            |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
513

W
wusongqing 已提交
514
## InterruptEvent<sup>9+</sup>
G
Geevarghese V K 已提交
515

W
wusongqing 已提交
516
Describes the interruption event received by the application when playback is interrupted.
G
Geevarghese V K 已提交
517

W
wusongqing 已提交
518
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Geevarghese V K 已提交
519

W
wusongqing 已提交
520 521 522 523 524
| Name     | Type                                      | Mandatory| Description                                |
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
| eventType | [InterruptType](#interrupttype)            | Yes  | Whether the interruption has started or ended.        |
| forceType | [InterruptForceType](#interruptforcetype9) | Yes  | Whether the interruption is taken by the system or to be taken by the application.|
| hintType  | [InterruptHint](#interrupthint)            | Yes  | Hint provided along the interruption.                          |
G
Geevarghese V K 已提交
525

526
## AudioInterrupt
527

W
wusongqing 已提交
528
Describes input parameters of audio interruption events.
V
Vaidegi B 已提交
529

W
wusongqing 已提交
530
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
531

W
wusongqing 已提交
532
| Name           | Type                       | Mandatory| Description                                                        |
533
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
534 535 536
| streamUsage     | [StreamUsage](#streamusage) | Yes  | Audio stream usage.                                            |
| contentType     | [ContentType](#contenttype) | Yes  | Audio content type.                                          |
| pauseWhenDucked | boolean                     | Yes  | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite.|
537 538 539

## InterruptAction

W
wusongqing 已提交
540
Describes the callback invoked for audio interruption or focus gain events.
541

W
wusongqing 已提交
542
**System capability**: SystemCapability.Multimedia.Audio.Renderer
543

W
wusongqing 已提交
544 545 546 547
| Name      | Type                                       | Mandatory| Description                                                        |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes  | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event.|
| type       | [InterruptType](#interrupttype)             | No  | Type of the audio interruption event.                                              |
W
wusongqing 已提交
548
| hint       | [InterruptHint](#interrupthint)             | No  | Hint provided along with the audio interruption event.                                              |
W
wusongqing 已提交
549
| activated  | boolean                                     | No  | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released.|
550 551

## VolumeEvent<sup>8+</sup>
V
Vaidegi B 已提交
552

W
wusongqing 已提交
553
Describes the event received by the application when the volume is changed.
554

W
wusongqing 已提交
555
This is a system API and cannot be called by third-party applications.
V
Vaidegi B 已提交
556

W
wusongqing 已提交
557
**System capability**: SystemCapability.Multimedia.Audio.Volume
558

W
wusongqing 已提交
559 560 561 562 563
| Name      | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume level. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                    |
V
Vaidegi B 已提交
564

565
## DeviceChangeAction
566

W
wusongqing 已提交
567
Describes the device connection status and device information.
568

W
wusongqing 已提交
569
**System capability**: SystemCapability.Multimedia.Audio.Device
570

W
wusongqing 已提交
571 572 573 574
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type              | [DeviceChangeType](#DeviceChangeType)             | Yes  | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes  | Device information.        |
575 576

## DeviceChangeType
577

W
wusongqing 已提交
578
Enumerates the device connection statuses.
579

W
wusongqing 已提交
580
**System capability**: SystemCapability.Multimedia.Audio.Device
581

W
wusongqing 已提交
582 583 584 585
| Name      | Default Value| Description          |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
586

W
wusongqing 已提交
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
## AudioCapturerOptions<sup>8+</sup>

Describes audio capturer configurations.

**System capability**: SystemCapability.Multimedia.Audio.Capturer

| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|

## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>

Describes audio capturer information.

**System capability**: SystemCapability.Multimedia.Audio.Core
603

W
wusongqing 已提交
604 605 606 607
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
608

W
wusongqing 已提交
609 610 611
## SourceType<sup>8+</sup><a name="sourcetype"></a>

Enumerates the audio source types.
612

W
wusongqing 已提交
613
**System capability**: SystemCapability.Multimedia.Audio.Core
614

W
wusongqing 已提交
615 616 617 618 619
| Name                           | Default Value| Description                  |
| :------------------------------ | :----- | :--------------------- |
| SOURCE_TYPE_INVALID             | -1     | Invalid audio source.        |
| SOURCE_TYPE_MIC                 | 0      | Mic source.           |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7      | Voice communication source.|
620 621

## AudioScene<sup>8+</sup><a name="audioscene"></a>
622

W
wusongqing 已提交
623
Enumerates the audio scenes.
624

W
wusongqing 已提交
625
**System capability**: SystemCapability.Multimedia.Audio.Communication
626

W
wusongqing 已提交
627 628 629 630 631 632
| Name                  | Default Value| Description                                         |
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
633

634
## AudioManager
W
wusongqing 已提交
635

W
wusongqing 已提交
636
Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
W
wusongqing 已提交
637

638 639
### setVolume

W
wusongqing 已提交
640
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
641 642 643

Sets the volume for a stream. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
644
**System capability**: SystemCapability.Multimedia.Audio.Volume
645

W
wusongqing 已提交
646
**Parameters**
647

W
wusongqing 已提交
648 649 650 651 652
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
653

W
wusongqing 已提交
654
**Example**
W
wusongqing 已提交
655 656

```
657 658 659 660 661 662
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
    if (err) {
        console.error('Failed to set the volume. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate a successful volume setting.');
663
});
W
wusongqing 已提交
664
```
W
wusongqing 已提交
665

666
### setVolume
W
wusongqing 已提交
667

W
wusongqing 已提交
668
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
669 670 671

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

W
wusongqing 已提交
672
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
673

W
wusongqing 已提交
674
**Parameters**
675

W
wusongqing 已提交
676 677 678 679
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
680

W
wusongqing 已提交
681
**Return value**
682

W
wusongqing 已提交
683 684 685
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
686

W
wusongqing 已提交
687
**Example**
W
wusongqing 已提交
688 689

```
690
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
W
wusongqing 已提交
691
    console.log('Promise returned to indicate a successful volume setting.');
692 693 694 695
});
```

### getVolume
W
wusongqing 已提交
696

W
wusongqing 已提交
697
getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
W
wusongqing 已提交
698

W
wusongqing 已提交
699
Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
700

W
wusongqing 已提交
701
**System capability**: SystemCapability.Multimedia.Audio.Volume
702

W
wusongqing 已提交
703
**Parameters**
704

W
wusongqing 已提交
705 706 707 708
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
709

W
wusongqing 已提交
710
**Example**
W
wusongqing 已提交
711 712 713 714

```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
715 716
       console.error('Failed to obtain the volume. ${err.message}');
       return;
W
wusongqing 已提交
717 718
   }
   console.log('Callback invoked to indicate that the volume is obtained.');
719
});
W
wusongqing 已提交
720 721
```

722
### getVolume
V
Vaidegi B 已提交
723

W
wusongqing 已提交
724
getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
W
wusongqing 已提交
725

W
wusongqing 已提交
726
Obtains the volume of a stream. This API uses a promise to return the result.
W
wusongqing 已提交
727

W
wusongqing 已提交
728
**System capability**: SystemCapability.Multimedia.Audio.Volume
729

W
wusongqing 已提交
730
**Parameters**
W
wusongqing 已提交
731

W
wusongqing 已提交
732 733 734
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
W
wusongqing 已提交
735

W
wusongqing 已提交
736
**Return value**
737

W
wusongqing 已提交
738 739 740
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
741

W
wusongqing 已提交
742
**Example**
W
wusongqing 已提交
743 744

```
745
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
746
    console.log('Promise returned to indicate that the volume is obtained.' + value);
747 748 749 750 751
});
```

### getMinVolume

W
wusongqing 已提交
752
getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
753

W
wusongqing 已提交
754
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
755

W
wusongqing 已提交
756
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
757

W
wusongqing 已提交
758
**Parameters**
W
wusongqing 已提交
759

W
wusongqing 已提交
760 761 762 763
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
764

W
wusongqing 已提交
765
**Example**
W
wusongqing 已提交
766 767 768 769 770

```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the minimum volume. ${err.message}');
771
        return;
W
wusongqing 已提交
772 773
    }
    console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
774
});
W
wusongqing 已提交
775 776
```

777
### getMinVolume
V
Vaidegi B 已提交
778

W
wusongqing 已提交
779
getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
W
wusongqing 已提交
780

W
wusongqing 已提交
781
Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
W
wusongqing 已提交
782

W
wusongqing 已提交
783
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
784

W
wusongqing 已提交
785
**Parameters**
786

W
wusongqing 已提交
787 788 789
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
W
wusongqing 已提交
790

W
wusongqing 已提交
791
**Return value**
W
wusongqing 已提交
792

W
wusongqing 已提交
793 794 795
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
W
wusongqing 已提交
796

W
wusongqing 已提交
797
**Example**
798 799 800 801 802 803 804 805 806

```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
    console.log('Promised returned to indicate that the minimum volume is obtained.' + value);
});
```

### getMaxVolume

W
wusongqing 已提交
807
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
808

W
wusongqing 已提交
809
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
810

W
wusongqing 已提交
811
**System capability**: SystemCapability.Multimedia.Audio.Volume
812

W
wusongqing 已提交
813
**Parameters**
814

W
wusongqing 已提交
815 816 817 818
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
819

W
wusongqing 已提交
820
**Example**
W
wusongqing 已提交
821 822 823 824 825 826 827 828

```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the maximum volume. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the maximum volume is obtained.' + value);
829
});
W
wusongqing 已提交
830 831
```

832
### getMaxVolume
V
Vaidegi B 已提交
833

W
wusongqing 已提交
834
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
W
wusongqing 已提交
835

W
wusongqing 已提交
836
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
W
wusongqing 已提交
837

W
wusongqing 已提交
838
**System capability**: SystemCapability.Multimedia.Audio.Volume
839

W
wusongqing 已提交
840
**Parameters**
W
wusongqing 已提交
841

W
wusongqing 已提交
842 843 844
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
W
wusongqing 已提交
845

W
wusongqing 已提交
846
**Return value**
847

W
wusongqing 已提交
848 849 850
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
W
wusongqing 已提交
851

W
wusongqing 已提交
852
**Example**
W
wusongqing 已提交
853 854

```
855
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
W
wusongqing 已提交
856
    console.log('Promised returned to indicate that the maximum volume is obtained.');
857
});
W
wusongqing 已提交
858 859
```

860
### mute
V
Vaidegi B 已提交
861

W
wusongqing 已提交
862
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
W
wusongqing 已提交
863

W
wusongqing 已提交
864
Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
865

W
wusongqing 已提交
866
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
867

W
wusongqing 已提交
868
**Parameters**
W
wusongqing 已提交
869

W
wusongqing 已提交
870 871 872 873 874
| Name    | Type                               | Mandatory| Description                                 |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.               |
875

W
wusongqing 已提交
876
**Example**
W
wusongqing 已提交
877 878 879 880 881

```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
    if (err) {
        console.error('Failed to mute the stream. ${err.message}');
882
        return;
W
wusongqing 已提交
883 884
    }
    console.log('Callback invoked to indicate that the stream is muted.');
885
});
W
wusongqing 已提交
886 887
```

888
### mute
V
Vaidegi B 已提交
889

W
wusongqing 已提交
890 891 892
mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;

Mutes or unmutes a stream. This API uses a promise to return the result.
V
Vaidegi B 已提交
893

W
wusongqing 已提交
894
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
895

W
wusongqing 已提交
896
**Parameters**
897

W
wusongqing 已提交
898 899 900 901
| Name    | Type                               | Mandatory| Description                                 |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
902

W
wusongqing 已提交
903
**Return value**
W
wusongqing 已提交
904

W
wusongqing 已提交
905 906 907
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
908

W
wusongqing 已提交
909
**Example**
910

W
wusongqing 已提交
911 912

```
913
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
W
wusongqing 已提交
914
    console.log('Promise returned to indicate that the stream is muted.');
915
});
W
wusongqing 已提交
916 917
```

V
Vaidegi B 已提交
918

919
### isMute
V
Vaidegi B 已提交
920

W
wusongqing 已提交
921
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
922

W
wusongqing 已提交
923
Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
924

W
wusongqing 已提交
925
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
926

W
wusongqing 已提交
927
**Parameters**
W
wusongqing 已提交
928

W
wusongqing 已提交
929 930 931 932
| Name    | Type                               | Mandatory| Description                                           |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
933

W
wusongqing 已提交
934
**Example**
W
wusongqing 已提交
935 936 937 938

```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
939 940
       console.error('Failed to obtain the mute status. ${err.message}');
       return;
W
wusongqing 已提交
941 942
   }
   console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
943
});
W
wusongqing 已提交
944 945 946
```


947
### isMute
V
Vaidegi B 已提交
948

W
wusongqing 已提交
949
isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
V
Vaidegi B 已提交
950

W
wusongqing 已提交
951
Checks whether a stream is muted. This method uses a promise to return the result.
W
wusongqing 已提交
952

W
wusongqing 已提交
953
**System capability**: SystemCapability.Multimedia.Audio.Volume
954

W
wusongqing 已提交
955
**Parameters**
W
wusongqing 已提交
956

W
wusongqing 已提交
957 958 959
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
960

W
wusongqing 已提交
961
**Return value**
962

W
wusongqing 已提交
963 964 965
| Type                  | Description                                                  |
| ---------------------- | ------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
966

W
wusongqing 已提交
967
**Example**
W
wusongqing 已提交
968 969

```
970
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
971
    console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
972
});
W
wusongqing 已提交
973 974
```

975
### isActive
V
Vaidegi B 已提交
976

W
wusongqing 已提交
977
isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
978

W
wusongqing 已提交
979
Checks whether a stream is active. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
980

W
wusongqing 已提交
981
**System capability**: SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
982

W
wusongqing 已提交
983
**Parameters**
W
wusongqing 已提交
984

W
wusongqing 已提交
985 986 987 988
| Name    | Type                               | Mandatory| Description                                             |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                     |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
989

W
wusongqing 已提交
990
**Example**
W
wusongqing 已提交
991 992 993 994 995

```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the active status of the stream. ${err.message}');
996
        return;
W
wusongqing 已提交
997 998
    }
    console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
999
});
W
wusongqing 已提交
1000 1001
```

1002
### isActive
V
Vaidegi B 已提交
1003

W
wusongqing 已提交
1004
isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
W
wusongqing 已提交
1005

W
wusongqing 已提交
1006
Checks whether a stream is active. This method uses a promise to return the result.
W
wusongqing 已提交
1007

W
wusongqing 已提交
1008
**System capability**: SystemCapability.Multimedia.Audio.Volume
1009

W
wusongqing 已提交
1010
**Parameters**
1011

W
wusongqing 已提交
1012 1013 1014
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
W
wusongqing 已提交
1015

W
wusongqing 已提交
1016
**Return value**
1017

W
wusongqing 已提交
1018 1019 1020
| Type                  | Description                                                    |
| ---------------------- | -------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
1021

W
wusongqing 已提交
1022
**Example**
W
wusongqing 已提交
1023 1024

```
1025
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
1026
    console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
1027
});
W
wusongqing 已提交
1028 1029
```

1030
### setRingerMode
V
Vaidegi B 已提交
1031

W
wusongqing 已提交
1032
setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1033

1034
Sets the ringer mode. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1035

W
wusongqing 已提交
1036
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1037

W
wusongqing 已提交
1038
**Parameters**
W
wusongqing 已提交
1039

W
wusongqing 已提交
1040 1041 1042 1043
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1044

W
wusongqing 已提交
1045
**Example**
W
wusongqing 已提交
1046 1047 1048 1049 1050 1051 1052 1053

```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
   if (err) {
       console.error('Failed to set the ringer mode.​ ${err.message}');
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the ringer mode.');
1054
});
W
wusongqing 已提交
1055 1056
```

1057
### setRingerMode
V
Vaidegi B 已提交
1058

W
wusongqing 已提交
1059
setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
V
Vaidegi B 已提交
1060

1061
Sets the ringer mode. This API uses a promise to return the result.
W
wusongqing 已提交
1062

W
wusongqing 已提交
1063
**System capability**: SystemCapability.Multimedia.Audio.Communication
1064

W
wusongqing 已提交
1065
**Parameters**
W
wusongqing 已提交
1066

W
wusongqing 已提交
1067 1068 1069
| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1070

W
wusongqing 已提交
1071
**Return value**
1072

W
wusongqing 已提交
1073 1074 1075
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1076

W
wusongqing 已提交
1077
**Example**
W
wusongqing 已提交
1078 1079

```
1080
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
W
wusongqing 已提交
1081
    console.log('Promise returned to indicate a successful setting of the ringer mode.');
1082
});
W
wusongqing 已提交
1083 1084
```

V
Vaidegi B 已提交
1085

1086
### getRingerMode
V
Vaidegi B 已提交
1087

W
wusongqing 已提交
1088
getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
W
wusongqing 已提交
1089

W
wusongqing 已提交
1090
Obtains the ringer mode. This API uses an asynchronous callback to return the result.
1091

W
wusongqing 已提交
1092
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1093

W
wusongqing 已提交
1094
**Parameters**
W
wusongqing 已提交
1095

W
wusongqing 已提交
1096 1097 1098
| Name  | Type                                                | Mandatory| Description                    |
| -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the ringer mode.|
W
wusongqing 已提交
1099

W
wusongqing 已提交
1100
**Example**
W
wusongqing 已提交
1101 1102 1103 1104

```
audioManager.getRingerMode((err, value) => {
   if (err) {
1105 1106
       console.error('Failed to obtain the ringer mode.​ ${err.message}');
       return;
W
wusongqing 已提交
1107 1108
   }
   console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
1109
});
W
wusongqing 已提交
1110 1111
```

V
Vaidegi B 已提交
1112

1113
### getRingerMode
V
Vaidegi B 已提交
1114

W
wusongqing 已提交
1115
getRingerMode(): Promise&lt;AudioRingMode&gt;
W
wusongqing 已提交
1116

W
wusongqing 已提交
1117
Obtains the ringer mode. This API uses a promise to return the result.
W
wusongqing 已提交
1118

W
wusongqing 已提交
1119
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1120

W
wusongqing 已提交
1121
**Return value**
W
wusongqing 已提交
1122

W
wusongqing 已提交
1123 1124 1125
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
W
wusongqing 已提交
1126

W
wusongqing 已提交
1127
**Example**
W
wusongqing 已提交
1128 1129

```
1130
audioManager.getRingerMode().then((value) => {
W
wusongqing 已提交
1131
    console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
1132
});
W
wusongqing 已提交
1133 1134
```

1135
### setAudioParameter
V
Vaidegi B 已提交
1136

W
wusongqing 已提交
1137
setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1138

1139 1140
Sets an audio parameter. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
1141
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1142

W
wusongqing 已提交
1143
**Parameters**
W
wusongqing 已提交
1144

W
wusongqing 已提交
1145 1146 1147 1148 1149
| Name  | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
| key      | string                    | Yes  | Key of the audio parameter to set.  |
| value    | string                    | Yes  | Value of the audio parameter to set.  |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
W
wusongqing 已提交
1150

W
wusongqing 已提交
1151
**Example**
W
wusongqing 已提交
1152 1153 1154 1155 1156

```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
1157
        return;
W
wusongqing 已提交
1158 1159
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
1160
});
W
wusongqing 已提交
1161 1162
```

1163
### setAudioParameter
V
Vaidegi B 已提交
1164

W
wusongqing 已提交
1165
setAudioParameter(key: string, value: string): Promise&lt;void&gt;
V
Vaidegi B 已提交
1166

1167
Sets an audio parameter. This API uses a promise to return the result.
W
wusongqing 已提交
1168

W
wusongqing 已提交
1169
**System capability**: SystemCapability.Multimedia.Audio.Core
1170

W
wusongqing 已提交
1171
**Parameters**
W
wusongqing 已提交
1172

W
wusongqing 已提交
1173 1174 1175 1176
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
1177

W
wusongqing 已提交
1178
**Return value**
1179

W
wusongqing 已提交
1180 1181 1182
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1183

W
wusongqing 已提交
1184
**Example**
W
wusongqing 已提交
1185 1186

```
1187
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
W
wusongqing 已提交
1188
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1189
});
W
wusongqing 已提交
1190 1191
```

1192
### getAudioParameter
V
Vaidegi B 已提交
1193

W
wusongqing 已提交
1194
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
W
wusongqing 已提交
1195

W
wusongqing 已提交
1196
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
1197

W
wusongqing 已提交
1198
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1199

W
wusongqing 已提交
1200
**Parameters**
W
wusongqing 已提交
1201

W
wusongqing 已提交
1202 1203 1204 1205
| Name  | Type                       | Mandatory| Description                        |
| -------- | --------------------------- | ---- | ---------------------------- |
| key      | string                      | Yes  | Key of the audio parameter whose value is to be obtained.      |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the value of the audio parameter.|
W
wusongqing 已提交
1206

W
wusongqing 已提交
1207
**Example**
W
wusongqing 已提交
1208 1209 1210 1211 1212

```
audioManager.getAudioParameter('PBits per sample', (err, value) => {
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1213
        return;
W
wusongqing 已提交
1214 1215
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1216
});
W
wusongqing 已提交
1217 1218
```

1219
### getAudioParameter
V
Vaidegi B 已提交
1220

W
wusongqing 已提交
1221
getAudioParameter(key: string): Promise&lt;string&gt;
W
wusongqing 已提交
1222

W
wusongqing 已提交
1223
Obtains the value of an audio parameter. This API uses a promise to return the result.
W
wusongqing 已提交
1224

W
wusongqing 已提交
1225
**System capability**: SystemCapability.Multimedia.Audio.Core
1226

W
wusongqing 已提交
1227
**Parameters**
1228

W
wusongqing 已提交
1229 1230 1231
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1232

W
wusongqing 已提交
1233
**Return value**
W
wusongqing 已提交
1234

W
wusongqing 已提交
1235 1236 1237
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1238

W
wusongqing 已提交
1239
**Example**
W
wusongqing 已提交
1240 1241

```
1242
audioManager.getAudioParameter('PBits per sample').then((value) => {
W
wusongqing 已提交
1243
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1244
});
W
wusongqing 已提交
1245 1246
```

1247 1248
### getDevices

W
wusongqing 已提交
1249
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
W
wusongqing 已提交
1250

W
wusongqing 已提交
1251
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1252

W
wusongqing 已提交
1253
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1254

W
wusongqing 已提交
1255
**Parameters**
1256

W
wusongqing 已提交
1257 1258 1259 1260
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the device list.|
W
wusongqing 已提交
1261

W
wusongqing 已提交
1262
**Example**
W
wusongqing 已提交
1263
```
1264
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1265
   if (err) {
1266 1267
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1268 1269
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1270
});
W
wusongqing 已提交
1271 1272
```

1273
### getDevices
V
Vaidegi B 已提交
1274

W
wusongqing 已提交
1275
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
W
wusongqing 已提交
1276

W
wusongqing 已提交
1277
Obtains the audio devices with a specific flag. This API uses a promise to return the result.
W
wusongqing 已提交
1278

W
wusongqing 已提交
1279
**System capability**: SystemCapability.Multimedia.Audio.Device
1280

W
wusongqing 已提交
1281
**Parameters**
W
wusongqing 已提交
1282

W
wusongqing 已提交
1283 1284 1285
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
W
wusongqing 已提交
1286

W
wusongqing 已提交
1287
**Return value**
1288

W
wusongqing 已提交
1289 1290 1291
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
W
wusongqing 已提交
1292

W
wusongqing 已提交
1293
**Example**
W
wusongqing 已提交
1294 1295

```
1296
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1297
    console.log('Promise returned to indicate that the device list is obtained.');
1298
});
W
wusongqing 已提交
1299 1300
```

1301
### setDeviceActive
V
Vaidegi B 已提交
1302

W
wusongqing 已提交
1303
setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1304

1305
Sets a device to the active state. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1306

W
wusongqing 已提交
1307
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1308

W
wusongqing 已提交
1309
**Parameters**
W
wusongqing 已提交
1310

W
wusongqing 已提交
1311 1312 1313 1314 1315
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.      |
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
1316

W
wusongqing 已提交
1317
**Example**
W
wusongqing 已提交
1318 1319

```
1320
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1321 1322
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1323
        return;
W
wusongqing 已提交
1324 1325
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1326
});
W
wusongqing 已提交
1327 1328
```

1329
### setDeviceActive
V
Vaidegi B 已提交
1330

W
wusongqing 已提交
1331
setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
1332

1333
Sets a device to the active state. This API uses a promise to return the result.
W
wusongqing 已提交
1334

W
wusongqing 已提交
1335
**System capability**: SystemCapability.Multimedia.Audio.Device
1336

W
wusongqing 已提交
1337
**Parameters**
1338

W
wusongqing 已提交
1339 1340 1341 1342
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
W
wusongqing 已提交
1343

W
wusongqing 已提交
1344
**Return value**
1345

W
wusongqing 已提交
1346 1347 1348
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1349

W
wusongqing 已提交
1350
**Example**
1351

W
wusongqing 已提交
1352 1353

```
1354
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1355
    console.log('Promise returned to indicate that the device is set to the active status.');
1356
});
W
wusongqing 已提交
1357 1358
```

1359
### isDeviceActive
V
Vaidegi B 已提交
1360

W
wusongqing 已提交
1361
isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
1362

W
wusongqing 已提交
1363
Checks whether a device is active. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1364

W
wusongqing 已提交
1365
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1366

W
wusongqing 已提交
1367
**Parameters**
W
wusongqing 已提交
1368

W
wusongqing 已提交
1369 1370 1371 1372
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.      |
| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the active state of the device.|
1373

W
wusongqing 已提交
1374
**Example**
W
wusongqing 已提交
1375 1376

```
Z
zengyawen 已提交
1377
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1378 1379
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1380
        return;
W
wusongqing 已提交
1381 1382
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1383
});
W
wusongqing 已提交
1384 1385
```

V
Vaidegi B 已提交
1386

1387
### isDeviceActive
V
Vaidegi B 已提交
1388

W
wusongqing 已提交
1389
isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
W
wusongqing 已提交
1390

W
wusongqing 已提交
1391
Checks whether a device is active. This API uses a promise to return the result.
W
wusongqing 已提交
1392

W
wusongqing 已提交
1393
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1394

W
wusongqing 已提交
1395
**Parameters**
1396

W
wusongqing 已提交
1397 1398 1399
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
1400

W
wusongqing 已提交
1401
**Return value**
1402

W
wusongqing 已提交
1403 1404 1405
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1406

W
wusongqing 已提交
1407
**Example**
W
wusongqing 已提交
1408 1409

```
1410
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1411
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1412
});
W
wusongqing 已提交
1413 1414
```

1415
### setMicrophoneMute
V
Vaidegi B 已提交
1416

W
wusongqing 已提交
1417
setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1418

1419 1420
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
1421
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1422

W
wusongqing 已提交
1423
**Parameters**
W
wusongqing 已提交
1424

W
wusongqing 已提交
1425 1426 1427 1428
| Name  | Type                     | Mandatory| Description                                         |
| -------- | ------------------------- | ---- | --------------------------------------------- |
| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                     |
W
wusongqing 已提交
1429

W
wusongqing 已提交
1430
**Example**
W
wusongqing 已提交
1431 1432 1433 1434 1435 1436 1437 1438

```
audioManager.setMicrophoneMute(true, (err) => {
    if (err) {
        console.error('Failed to mute the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the microphone is muted.');
1439
});
W
wusongqing 已提交
1440 1441
```

1442
### setMicrophoneMute
V
Vaidegi B 已提交
1443

W
wusongqing 已提交
1444
setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
1445

1446 1447
Mutes or unmutes the microphone. This API uses a promise to return the result.

W
wusongqing 已提交
1448
**System capability**: SystemCapability.Multimedia.Audio.Device
1449

W
wusongqing 已提交
1450
**Parameters**
1451

W
wusongqing 已提交
1452 1453 1454
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1455

W
wusongqing 已提交
1456
**Return value**
W
wusongqing 已提交
1457

W
wusongqing 已提交
1458 1459 1460
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1461

W
wusongqing 已提交
1462
**Example**
W
wusongqing 已提交
1463 1464

```
1465
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1466
    console.log('Promise returned to indicate that the microphone is muted.');
1467
});
W
wusongqing 已提交
1468 1469
```

1470
### isMicrophoneMute
V
Vaidegi B 已提交
1471

W
wusongqing 已提交
1472
isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
1473

W
wusongqing 已提交
1474
Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
1475

W
wusongqing 已提交
1476
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1477

W
wusongqing 已提交
1478
**Parameters**
W
wusongqing 已提交
1479

W
wusongqing 已提交
1480 1481 1482
| Name  | Type                        | Mandatory| Description                                                   |
| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
W
wusongqing 已提交
1483

W
wusongqing 已提交
1484
**Example**
W
wusongqing 已提交
1485 1486 1487 1488 1489 1490 1491 1492

```
audioManager.isMicrophoneMute((err, value) => {
    if (err) {
        console.error('Failed to obtain the mute status of the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value);
1493
});
W
wusongqing 已提交
1494 1495
```

1496
### isMicrophoneMute
V
Vaidegi B 已提交
1497

W
wusongqing 已提交
1498 1499 1500
isMicrophoneMute(): Promise&lt;boolean&gt;

Checks whether the microphone is muted. This API uses a promise to return the result.
W
wusongqing 已提交
1501

W
wusongqing 已提交
1502
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1503

W
wusongqing 已提交
1504
**Return value**
1505

W
wusongqing 已提交
1506 1507 1508
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
W
wusongqing 已提交
1509

W
wusongqing 已提交
1510
**Example**
W
wusongqing 已提交
1511 1512 1513


```
1514
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1515
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1516
});
W
wusongqing 已提交
1517 1518
```

1519
### on('volumeChange')<sup>8+</sup>
W
wusongqing 已提交
1520

1521
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
Z
zengyawen 已提交
1522

W
wusongqing 已提交
1523
Subscribes to system volume change events.
V
Vaidegi B 已提交
1524

1525
This is a system API and cannot be called by third-party applications.
1526

W
wusongqing 已提交
1527
**System capability**: SystemCapability.Multimedia.Audio.Volume
V
Vaidegi B 已提交
1528

W
wusongqing 已提交
1529
**Parameters**
V
Vaidegi B 已提交
1530

W
wusongqing 已提交
1531 1532 1533 1534
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Type of event to subscribe to. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
V
Vaidegi B 已提交
1535

W
wusongqing 已提交
1536
**Example**
V
Vaidegi B 已提交
1537 1538 1539 1540 1541 1542

```
audioManager.on('volumeChange', (volumeEvent) => {
    console.log('VolumeType of stream: ' + volumeEvent.volumeType);
    console.log('Volume level: ' + volumeEvent.volume);
    console.log('Whether to updateUI: ' + volumeEvent.updateUi);
1543
});
V
Vaidegi B 已提交
1544 1545
```

1546
### on('ringerModeChange')<sup>8+</sup>
V
Vaidegi B 已提交
1547

1548
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
V
Vaidegi B 已提交
1549

W
wusongqing 已提交
1550
Subscribes to ringer mode change events.
1551

1552
This is a system API and cannot be called by third-party applications.
V
Vaidegi B 已提交
1553

W
wusongqing 已提交
1554
**System capability**: SystemCapability.Multimedia.Audio.Communication
V
Vaidegi B 已提交
1555

W
wusongqing 已提交
1556
**Parameters**
V
Vaidegi B 已提交
1557

W
wusongqing 已提交
1558 1559 1560 1561
| Name  | Type                                     | Mandatory| Description                                                        |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                    | Yes  | Type of event to subscribe to. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the updated ringer mode.                                                  |
V
Vaidegi B 已提交
1562

W
wusongqing 已提交
1563
**Example**
V
Vaidegi B 已提交
1564 1565 1566 1567

```
audioManager.on('ringerModeChange', (ringerMode) => {
    console.log('Updated ringermode: ' + ringerMode);
1568
});
V
Vaidegi B 已提交
1569 1570
```

1571
### on('deviceChange')
1572

1573
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1574

W
wusongqing 已提交
1575
Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
1576

W
wusongqing 已提交
1577
**System capability**: SystemCapability.Multimedia.Audio.Device
1578

W
wusongqing 已提交
1579
**Parameters**
1580

W
wusongqing 已提交
1581 1582 1583 1584
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Type of event to subscribe to. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes  | Callback used to return the device update details.                        |
1585

W
wusongqing 已提交
1586
**Example**
1587 1588 1589 1590 1591 1592 1593

```
audioManager.on('deviceChange', (deviceChanged) => {
    console.info("device change type : " + deviceChanged.type);
    console.info("device descriptor size : " + deviceChanged.deviceDescriptors.length);
    console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceRole);
    console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceType);
1594
});
1595 1596
```

1597 1598 1599 1600
### off('deviceChange')

off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void

W
wusongqing 已提交
1601
Unsubscribes from device change events.
1602

W
wusongqing 已提交
1603
**System capability**: SystemCapability.Multimedia.Audio.Device
1604

W
wusongqing 已提交
1605
**Parameters**
1606

W
wusongqing 已提交
1607 1608 1609 1610
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Type of event to unsubscribe from. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | No  | Callback used to return the device update details.                        |
1611

W
wusongqing 已提交
1612
**Example**
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623

```
audioManager.off('deviceChange', (deviceChanged) => {
    console.log("Should be no callback.");
});
```

### on('interrupt')

on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void

W
wusongqing 已提交
1624
Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
1625

W
wusongqing 已提交
1626
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1627

W
wusongqing 已提交
1628
**Parameters**
1629

W
wusongqing 已提交
1630 1631 1632 1633 1634
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | Yes  | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | Yes  | Callback invoked for the audio interruption event.                                      |
1635

W
wusongqing 已提交
1636
**Example**
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
    if (InterruptAction.actionType === 0) {
        console.log("An event to gain the audio focus starts.");
        console.log("Focus gain event:" + JSON.stringify(InterruptAction));
    }
    if (InterruptAction.actionType === 1) {
        console.log("An audio interruption event starts.");
        console.log("Audio interruption event:" + JSON.stringify(InterruptAction));
    }
});
```

### off('interrupt')

off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void

W
wusongqing 已提交
1660
Unsubscribes from audio interruption events.
1661

W
wusongqing 已提交
1662
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1663

W
wusongqing 已提交
1664
**Parameters**
1665

W
wusongqing 已提交
1666 1667
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1668
| type      | string                                        | Yes  | Type of event to unsubscribe from. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
W
wusongqing 已提交
1669 1670
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1671

W
wusongqing 已提交
1672
**Example**
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
    if (InterruptAction.actionType === 0) {
        console.log("An event to release the audio focus starts.");
        console.log("Focus release event:" + JSON.stringify(InterruptAction));
    }
});
```

### setAudioScene<sup>8+</sup>
1689

1690
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1691

W
wusongqing 已提交
1692
Sets an audio scene. This API uses an asynchronous callback to return the result.
1693

1694
This is a system API and cannot be called by third-party applications.
1695

W
wusongqing 已提交
1696
**System capability**: SystemCapability.Multimedia.Audio.Communication
1697

W
wusongqing 已提交
1698
**Parameters**
1699

W
wusongqing 已提交
1700 1701 1702 1703
| Name  | Type                                | Mandatory| Description                |
| :------- | :----------------------------------- | :--- | :------------------- |
| scene    | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.      |
| callback | AsyncCallback<void\>                 | Yes  | Callback used to return the result.|
1704

W
wusongqing 已提交
1705
**Example**
1706 1707 1708 1709 1710 1711 1712 1713

```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
   if (err) {
       console.error('Failed to set the audio scene mode.​ ${err.message}');
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the audio scene mode.');
1714
});
1715 1716
```

1717
### setAudioScene<sup>8+</sup>
1718

1719
setAudioScene\(scene: AudioScene\): Promise<void\>
1720

W
wusongqing 已提交
1721
Sets an audio scene. This API uses a promise to return the result.
1722

1723
This is a system API and cannot be called by third-party applications.
1724

W
wusongqing 已提交
1725
**System capability**: SystemCapability.Multimedia.Audio.Communication
1726

W
wusongqing 已提交
1727
**Parameters**
1728

W
wusongqing 已提交
1729 1730 1731
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1732

W
wusongqing 已提交
1733
**Return value**
1734

W
wusongqing 已提交
1735 1736 1737
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
1738

W
wusongqing 已提交
1739
**Example**
1740 1741 1742 1743 1744 1745 1746 1747 1748

```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => {
    console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => {
    console.log('Failed to set the audio scene mode');
});
```

1749
### getAudioScene<sup>8+</sup>
1750

1751
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1752

W
wusongqing 已提交
1753
Obtains the audio scene. This API uses an asynchronous callback to return the result.
1754

W
wusongqing 已提交
1755
**System capability**: SystemCapability.Multimedia.Audio.Communication
1756

W
wusongqing 已提交
1757
**Parameters**
1758

W
wusongqing 已提交
1759 1760 1761
| Name  | Type                                               | Mandatory| Description                        |
| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes  | Callback used to return the audio scene.|
1762

W
wusongqing 已提交
1763
**Example**
1764 1765 1766 1767 1768 1769 1770 1771

```
audioManager.getAudioScene((err, value) => {
   if (err) {
       console.error('Failed to obtain the audio scene mode.​ ${err.message}');
       return;
   }
   console.log('Callback invoked to indicate that the audio scene mode is obtained.' + value);
1772
});
1773 1774 1775
```


1776
### getAudioScene<sup>8+</sup>
1777

1778
getAudioScene\(\): Promise<AudioScene\>
1779

W
wusongqing 已提交
1780
Obtains the audio scene. This API uses a promise to return the result.
1781

W
wusongqing 已提交
1782
**System capability**: SystemCapability.Multimedia.Audio.Communication
1783

W
wusongqing 已提交
1784
**Return value**
1785

W
wusongqing 已提交
1786 1787 1788
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1789

W
wusongqing 已提交
1790
**Example**
1791 1792 1793 1794 1795 1796

```
audioManager.getAudioScene().then((value) => {
    console.log('Promise returned to indicate that the audio scene mode is obtained.' + value);
}).catch ((err) => {
    console.log('Failed to obtain the audio scene mode');
1797
});
1798 1799
```

1800
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1801

1802
Describes an audio device.
1803

W
wusongqing 已提交
1804
**System capability**: SystemCapability.Multimedia.Audio.Device
W
wusongqing 已提交
1805

W
wusongqing 已提交
1806 1807 1808 1809
| Name      | Type                   | Readable| Writable| Description      |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes  | No  | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes  | No  | Device type.|
V
Vaidegi B 已提交
1810

1811
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1812

1813
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
V
Vaidegi B 已提交
1814

W
wusongqing 已提交
1815
**Example**
V
Vaidegi B 已提交
1816

1817 1818
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1819

1820 1821 1822
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1823 1824 1825

}

1826 1827 1828 1829 1830 1831
var deviceRoleValue = null;
var deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
    console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
    value.forEach(displayDeviceProp);
V
Vaidegi B 已提交
1832
    if (deviceTypeValue != null && deviceRoleValue != null){
1833
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1834 1835
    }
    else{
1836 1837
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1838
});
V
Vaidegi B 已提交
1839
```
W
wusongqing 已提交
1840

1841 1842
## AudioRenderer<sup>8+</sup>

W
wusongqing 已提交
1843
Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
V
Vaidegi B 已提交
1844

W
wusongqing 已提交
1845
### Attributes
V
Vaidegi B 已提交
1846

W
wusongqing 已提交
1847
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1848

W
wusongqing 已提交
1849 1850
| Name | Type                    | Readable| Writable| Description              |
| ----- | -------------------------- | ---- | ---- | ------------------ |
W
wusongqing 已提交
1851
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes  | No  | Audio renderer state.|
V
Vaidegi B 已提交
1852

W
wusongqing 已提交
1853
**Example**
V
Vaidegi B 已提交
1854 1855

```
W
wusongqing 已提交
1856
var state = audioRenderer.state;
V
Vaidegi B 已提交
1857 1858
```

1859
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1860

1861
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
V
Vaidegi B 已提交
1862

W
wusongqing 已提交
1863
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1864

W
wusongqing 已提交
1865
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1866

W
wusongqing 已提交
1867
**Parameters**
V
Vaidegi B 已提交
1868

W
wusongqing 已提交
1869 1870 1871
| Name  | Type                                                    | Mandatory| Description                  |
| :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes  | Callback used to return the renderer information.|
V
Vaidegi B 已提交
1872

W
wusongqing 已提交
1873
**Example**
V
Vaidegi B 已提交
1874 1875

```
1876
audioRenderer.getRendererInfo((err, rendererInfo) => {
1877 1878 1879 1880
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1881
});
V
Vaidegi B 已提交
1882 1883
```

1884
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1885

1886
getRendererInfo(): Promise<AudioRendererInfo\>
1887

W
wusongqing 已提交
1888
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
1889

W
wusongqing 已提交
1890
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
1891

W
wusongqing 已提交
1892
**Return value**
V
Vaidegi B 已提交
1893

W
wusongqing 已提交
1894 1895 1896
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
V
Vaidegi B 已提交
1897

W
wusongqing 已提交
1898
**Example**
V
Vaidegi B 已提交
1899 1900

```
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
audioRenderer.getRendererInfo().then((rendererInfo) => {
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
}).catch((err) => {
    console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
    resultFlag = false;
});
```
V
Vaidegi B 已提交
1911

1912
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1913

1914
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1915

W
wusongqing 已提交
1916
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1917

W
wusongqing 已提交
1918
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
1919

W
wusongqing 已提交
1920
**Parameters**
V
Vaidegi B 已提交
1921

W
wusongqing 已提交
1922 1923 1924
| Name  | Type                                                | Mandatory| Description                |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
V
Vaidegi B 已提交
1925

W
wusongqing 已提交
1926
**Example**
V
Vaidegi B 已提交
1927 1928

```
1929
audioRenderer.getStreamInfo((err, streamInfo) => {
1930 1931
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1932 1933 1934
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1935
});
V
Vaidegi B 已提交
1936 1937
```

1938
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1939

1940
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1941

W
wusongqing 已提交
1942
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
1943

W
wusongqing 已提交
1944
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1945

W
wusongqing 已提交
1946
**Return value**
V
Vaidegi B 已提交
1947

W
wusongqing 已提交
1948 1949 1950
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
1951

W
wusongqing 已提交
1952
**Example**
V
Vaidegi B 已提交
1953 1954

```
1955 1956 1957 1958 1959 1960 1961 1962 1963
audioRenderer.getStreamInfo().then((streamInfo) => {
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
1964 1965
```

1966
### start<sup>8+</sup>
V
Vaidegi B 已提交
1967

1968
start(callback: AsyncCallback<void\>): void
V
Vaidegi B 已提交
1969

1970
Starts the renderer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1971

W
wusongqing 已提交
1972
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1973

W
wusongqing 已提交
1974
**Parameters**
V
Vaidegi B 已提交
1975

W
wusongqing 已提交
1976 1977 1978
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
1979

W
wusongqing 已提交
1980
**Example**
V
Vaidegi B 已提交
1981 1982

```
1983
audioRenderer.start((err) => {
1984 1985
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
1986
    } else {
1987
        console.info('Renderer start success.');
V
Vaidegi B 已提交
1988
    }
1989
});
V
Vaidegi B 已提交
1990 1991
```

1992
### start<sup>8+</sup>
V
Vaidegi B 已提交
1993

1994
start(): Promise<void\>
V
Vaidegi B 已提交
1995

1996
Starts the renderer. This API uses a promise to return the result.
V
Vaidegi B 已提交
1997

W
wusongqing 已提交
1998
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1999

W
wusongqing 已提交
2000
**Return value**
V
Vaidegi B 已提交
2001

W
wusongqing 已提交
2002 2003 2004
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2005

W
wusongqing 已提交
2006
**Example**
V
Vaidegi B 已提交
2007 2008

```
2009 2010 2011 2012 2013
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2014 2015
```

2016
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2017

2018
pause(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2019

2020
Pauses rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2021

W
wusongqing 已提交
2022
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2023

W
wusongqing 已提交
2024
**Parameters**
V
Vaidegi B 已提交
2025

W
wusongqing 已提交
2026 2027 2028
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2029

W
wusongqing 已提交
2030
**Example**
V
Vaidegi B 已提交
2031 2032

```
2033
audioRenderer.pause((err) => {
2034 2035
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2036
    } else {
2037
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2038
    }
2039
});
V
Vaidegi B 已提交
2040 2041
```

2042
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2043

2044
pause(): Promise\<void>
V
Vaidegi B 已提交
2045

2046
Pauses rendering. This API uses a promise to return the result.
2047

W
wusongqing 已提交
2048
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2049

W
wusongqing 已提交
2050
**Return value**
V
Vaidegi B 已提交
2051

W
wusongqing 已提交
2052 2053 2054
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2055

W
wusongqing 已提交
2056
**Example**
V
Vaidegi B 已提交
2057 2058

```
2059 2060 2061 2062 2063
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2064 2065
```

2066
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2067

2068
drain(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2069

2070
Drains the playback buffer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2071

W
wusongqing 已提交
2072
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2073

W
wusongqing 已提交
2074
**Parameters**
V
Vaidegi B 已提交
2075

W
wusongqing 已提交
2076 2077 2078
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2079

W
wusongqing 已提交
2080
**Example**
V
Vaidegi B 已提交
2081 2082

```
2083
audioRenderer.drain((err) => {
2084 2085
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2086
    } else {
2087
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2088
    }
2089
});
V
Vaidegi B 已提交
2090 2091
```

2092
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2093

2094
drain(): Promise\<void>
V
Vaidegi B 已提交
2095

2096
Drains the playback buffer. This API uses a promise to return the result.
2097

W
wusongqing 已提交
2098
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2099

W
wusongqing 已提交
2100
**Return value**
V
Vaidegi B 已提交
2101

W
wusongqing 已提交
2102 2103 2104
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2105

W
wusongqing 已提交
2106
**Example**
V
Vaidegi B 已提交
2107 2108

```
2109 2110 2111 2112 2113
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2114 2115
```

2116
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2117

2118
stop(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2119

2120
Stops rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2121

W
wusongqing 已提交
2122
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2123

W
wusongqing 已提交
2124
**Parameters**
V
Vaidegi B 已提交
2125

W
wusongqing 已提交
2126 2127 2128
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2129

W
wusongqing 已提交
2130
**Example**
V
Vaidegi B 已提交
2131 2132

```
2133
audioRenderer.stop((err) => {
2134 2135
    if (err) {
        console.error('Renderer stop failed');
V
Vaidegi B 已提交
2136
    } else {
2137
        console.log('Renderer stopped.');
V
Vaidegi B 已提交
2138
    }
2139
});
V
Vaidegi B 已提交
2140 2141
```

2142
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2143

2144
stop(): Promise\<void>
V
Vaidegi B 已提交
2145

2146
Stops rendering. This API uses a promise to return the result.
V
Vaidegi B 已提交
2147

W
wusongqing 已提交
2148
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2149

W
wusongqing 已提交
2150
**Return value**
V
Vaidegi B 已提交
2151

W
wusongqing 已提交
2152 2153 2154
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2155

W
wusongqing 已提交
2156
**Example**
V
Vaidegi B 已提交
2157 2158

```
2159 2160 2161 2162 2163
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2164 2165
```

2166
### release<sup>8+</sup>
V
Vaidegi B 已提交
2167

2168
release(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2169

2170
Releases the renderer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2171

W
wusongqing 已提交
2172
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2173

W
wusongqing 已提交
2174
**Parameters**
V
Vaidegi B 已提交
2175

W
wusongqing 已提交
2176 2177 2178
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2179

W
wusongqing 已提交
2180
**Example**
V
Vaidegi B 已提交
2181 2182

```
2183
audioRenderer.release((err) => {
2184 2185
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2186
    } else {
2187
        console.log('Renderer released.');
V
Vaidegi B 已提交
2188
    }
2189
});
V
Vaidegi B 已提交
2190 2191
```

2192
### release<sup>8+</sup>
V
Vaidegi B 已提交
2193

2194
release(): Promise\<void>
V
Vaidegi B 已提交
2195

2196
Releases the renderer. This API uses a promise to return the result.
V
Vaidegi B 已提交
2197

W
wusongqing 已提交
2198
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2199

W
wusongqing 已提交
2200
**Return value**
V
Vaidegi B 已提交
2201

W
wusongqing 已提交
2202 2203 2204
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2205

W
wusongqing 已提交
2206
**Example**
V
Vaidegi B 已提交
2207 2208

```
2209 2210 2211 2212 2213
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2214 2215
```

2216
### write<sup>8+</sup>
V
Vaidegi B 已提交
2217

2218
write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
2219

2220
Writes the buffer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2221

W
wusongqing 已提交
2222
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2223

W
wusongqing 已提交
2224
**Parameters**
V
Vaidegi B 已提交
2225

W
wusongqing 已提交
2226 2227 2228 2229
| Name  | Type                  | Mandatory| Description                                               |
| -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer   | ArrayBuffer            | Yes  | Buffer to be written.                               |
| callback | AsyncCallback\<number> | Yes  | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
V
Vaidegi B 已提交
2230

W
wusongqing 已提交
2231
**Example**
V
Vaidegi B 已提交
2232 2233

```
2234 2235 2236
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

V
Vaidegi B 已提交
2237 2238 2239
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2240
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2241
    if (writtenbytes < 0) {
2242
        console.error('write failed.');
V
Vaidegi B 已提交
2243 2244 2245
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2246
});
V
Vaidegi B 已提交
2247 2248
```

2249
### write<sup>8+</sup>
V
Vaidegi B 已提交
2250

2251
write(buffer: ArrayBuffer): Promise\<number>
V
Vaidegi B 已提交
2252

2253
Writes the buffer. This API uses a promise to return the result.
2254

W
wusongqing 已提交
2255
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2256

W
wusongqing 已提交
2257
**Return value**
V
Vaidegi B 已提交
2258

W
wusongqing 已提交
2259 2260 2261
| Type            | Description                                                        |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
V
Vaidegi B 已提交
2262

W
wusongqing 已提交
2263
**Example**
V
Vaidegi B 已提交
2264 2265

```
2266 2267 2268 2269
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2270 2271 2272
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2273 2274 2275 2276 2277 2278 2279 2280 2281
audioRenderer.write(buf).then((writtenbytes) => {
    if (writtenbytes < 0) {
        console.error('write failed.');
    } else {
        console.log('Actual written bytes: ' + writtenbytes);
    }
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2282 2283
```

2284
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2285

2286
getAudioTime(callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
2287

W
wusongqing 已提交
2288
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2289

W
wusongqing 已提交
2290
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2291

W
wusongqing 已提交
2292
**Parameters**
V
Vaidegi B 已提交
2293

W
wusongqing 已提交
2294 2295 2296
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
2297

W
wusongqing 已提交
2298
**Example**
V
Vaidegi B 已提交
2299 2300

```
2301
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2302
    console.log('Current timestamp: ' + timestamp);
2303
});
V
Vaidegi B 已提交
2304 2305
```

2306
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2307

2308
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2309

W
wusongqing 已提交
2310
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
V
Vaidegi B 已提交
2311

W
wusongqing 已提交
2312
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2313

W
wusongqing 已提交
2314
**Return value**
V
Vaidegi B 已提交
2315

W
wusongqing 已提交
2316 2317 2318
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
2319

W
wusongqing 已提交
2320
**Example**
V
Vaidegi B 已提交
2321 2322

```
2323 2324 2325 2326 2327
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2328 2329
```

2330
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2331

2332
getBufferSize(callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
2333

2334
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2335

W
wusongqing 已提交
2336
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2337

W
wusongqing 已提交
2338
**Parameters**
V
Vaidegi B 已提交
2339

W
wusongqing 已提交
2340 2341 2342
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
2343

W
wusongqing 已提交
2344
**Example**
V
Vaidegi B 已提交
2345 2346

```
2347
audioRenderer.getBufferSize((err, bufferSize) => {
V
Vaidegi B 已提交
2348 2349 2350
    if (err) {
        console.error('getBufferSize error');
    }
2351
});
V
Vaidegi B 已提交
2352 2353 2354 2355
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
```

2356
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2357

2358
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2359

2360
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
2361

W
wusongqing 已提交
2362
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2363

W
wusongqing 已提交
2364
**Return value**
V
Vaidegi B 已提交
2365

W
wusongqing 已提交
2366 2367 2368
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
2369

W
wusongqing 已提交
2370
**Example**
V
Vaidegi B 已提交
2371 2372

```
2373 2374 2375 2376 2377 2378
audioRenderer.getBufferSize().then((bufferSize) => {
    let buf = new ArrayBuffer(bufferSize);
    ss.readSync(buf);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2379 2380
```

2381
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2382

2383
setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2384

2385
Sets the render rate. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2386

W
wusongqing 已提交
2387
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2388

W
wusongqing 已提交
2389
**Parameters**
2390

W
wusongqing 已提交
2391 2392 2393 2394
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2395

W
wusongqing 已提交
2396
**Example**
V
Vaidegi B 已提交
2397 2398

```
2399
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2400
    if (err) {
2401
        console.error('Failed to set params');
V
Vaidegi B 已提交
2402 2403 2404
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2405
});
V
Vaidegi B 已提交
2406 2407
```

2408
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2409

2410
setRenderRate(rate: AudioRendererRate): Promise\<void>
V
Vaidegi B 已提交
2411

2412
Sets the render rate. This API uses a promise to return the result.
V
Vaidegi B 已提交
2413

W
wusongqing 已提交
2414
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2415

W
wusongqing 已提交
2416
**Parameters**
V
Vaidegi B 已提交
2417

W
wusongqing 已提交
2418 2419 2420
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
V
Vaidegi B 已提交
2421

W
wusongqing 已提交
2422
**Return value**
V
Vaidegi B 已提交
2423

W
wusongqing 已提交
2424 2425 2426
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2427

W
wusongqing 已提交
2428
**Example**
V
Vaidegi B 已提交
2429 2430

```
2431 2432 2433 2434 2435
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2436 2437
```

2438
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2439

2440
getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
V
Vaidegi B 已提交
2441

2442
Obtains the current render rate. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2443

W
wusongqing 已提交
2444
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2445

W
wusongqing 已提交
2446
**Parameters**
2447

W
wusongqing 已提交
2448 2449 2450
| Name  | Type                                                   | Mandatory| Description              |
| -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes  | Callback used to return the audio render rate.|
V
Vaidegi B 已提交
2451

W
wusongqing 已提交
2452
**Example**
V
Vaidegi B 已提交
2453 2454

```
2455
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2456
    console.log('getRenderRate: ' + renderrate);
2457
});
V
Vaidegi B 已提交
2458 2459
```

2460
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2461

2462
getRenderRate(): Promise\<AudioRendererRate>
2463

2464
Obtains the current render rate. This API uses a promise to return the result.
V
Vaidegi B 已提交
2465

W
wusongqing 已提交
2466
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2467

W
wusongqing 已提交
2468
**Return value**
V
Vaidegi B 已提交
2469

W
wusongqing 已提交
2470 2471 2472
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
2473

W
wusongqing 已提交
2474
**Example**
V
Vaidegi B 已提交
2475 2476

```
2477 2478 2479 2480 2481
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2482 2483
```

W
wusongqing 已提交
2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528
### on('interrupt')<sup>9+</sup>

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

Subscribes to audio interruption events. This API uses a callback to get interrupt events.

**System capability**: SystemCapability.Multimedia.Audio.Renderer

**Parameters**

| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                       | Yes  | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.|
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes  | Callback used to return the audio interruption event.                                    |

**Example**

```
audioRenderer.on('interrupt', (interruptEvent) => {
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
        switch (interruptEvent.hintType) {
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Force paused. Stop writing');
                isPlay = false;
                break;
            case audio.InterruptHint.INTERRUPT_HINT_STOP:
                console.log('Force stopped. Stop writing');
                isPlay = false;
                break;
        }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
         switch (interruptEvent.hintType) {
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
                startRenderer();
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
                pauseRenderer();
                break;
        }
    }
});
```

2529
### on('markReach')<sup>8+</sup>
2530

2531
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
2532

W
wusongqing 已提交
2533
Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
2534

W
wusongqing 已提交
2535
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2536

W
wusongqing 已提交
2537
**Parameters**
2538

W
wusongqing 已提交
2539 2540 2541 2542 2543
| Name  | Type                    | Mandatory| Description                                     |
| :------- | :----------------------- | :--- | :---------------------------------------- |
| type     | string                   | Yes  | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
| frame    | number                   | Yes  | Number of frames to trigger the event. The value must be greater than **0**.        |
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.                   |
2544

W
wusongqing 已提交
2545
**Example**
2546 2547 2548 2549 2550 2551 2552 2553 2554 2555

```
audioRenderer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```


2556
### off('markReach') <sup>8+</sup>
2557

2558
off(type: 'markReach'): void
2559 2560 2561

Unsubscribes from mark reached events.

W
wusongqing 已提交
2562
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2563

W
wusongqing 已提交
2564
**Parameters**
2565

W
wusongqing 已提交
2566 2567 2568
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **markReach**.|
2569

W
wusongqing 已提交
2570
**Example**
2571 2572 2573 2574 2575

```
audioRenderer.off('markReach');
```

2576
### on('periodReach') <sup>8+</sup>
2577

2578
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
2579

W
wusongqing 已提交
2580
Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
2581

W
wusongqing 已提交
2582
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2583

W
wusongqing 已提交
2584
**Parameters**
2585

W
wusongqing 已提交
2586 2587 2588 2589 2590
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | Yes  | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
| frame    | number                   | Yes  | Period during which frame rendering is listened. The value must be greater than **0**.          |
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.                     |
2591

W
wusongqing 已提交
2592
**Example**
2593 2594 2595 2596 2597 2598 2599 2600 2601

```
audioRenderer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

2602
### off('periodReach') <sup>8+</sup>
2603

2604
off(type: 'periodReach'): void
2605 2606 2607

Unsubscribes from period reached events.

W
wusongqing 已提交
2608
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2609

W
wusongqing 已提交
2610
**Parameters**
2611

W
wusongqing 已提交
2612 2613 2614
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
2615

W
wusongqing 已提交
2616
**Example**
2617 2618 2619 2620

```
audioRenderer.off('periodReach')
```
V
Vaidegi B 已提交
2621

2622
### on('stateChange') <sup>8+</sup>
V
Vaidegi B 已提交
2623

2624
on(type: 'stateChange', callback: Callback<AudioState\>): void
V
Vaidegi B 已提交
2625

2626
Subscribes to state change events.
V
Vaidegi B 已提交
2627

W
wusongqing 已提交
2628
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2629

W
wusongqing 已提交
2630
**Parameters**
2631

W
wusongqing 已提交
2632 2633 2634 2635
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | Yes  | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
2636

W
wusongqing 已提交
2637
**Example**
2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648

```
audioRenderer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio renderer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio renderer state is: STATE_RUNNING");
    }
});
```
V
Vaidegi B 已提交
2649

2650
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2651

W
wusongqing 已提交
2652
Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
V
Vaidegi B 已提交
2653

W
wusongqing 已提交
2654
### Attributes
V
Vaidegi B 已提交
2655

W
wusongqing 已提交
2656
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2657

W
wusongqing 已提交
2658 2659
| Name | Type                    | Readable| Writable| Description            |
| :---- | :------------------------- | :--- | :--- | :--------------- |
W
wusongqing 已提交
2660
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No  | Audio capturer state.|
V
Vaidegi B 已提交
2661

W
wusongqing 已提交
2662
**Example**
V
Vaidegi B 已提交
2663 2664

```
2665
var state = audioCapturer.state;
V
Vaidegi B 已提交
2666 2667
```

2668
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2669

2670
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
V
Vaidegi B 已提交
2671

W
wusongqing 已提交
2672
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2673

W
wusongqing 已提交
2674
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2675

W
wusongqing 已提交
2676
**Parameters**
V
Vaidegi B 已提交
2677

W
wusongqing 已提交
2678 2679 2680
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
V
Vaidegi B 已提交
2681

W
wusongqing 已提交
2682
**Example**
V
Vaidegi B 已提交
2683 2684

```
2685
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2686
    if (err) {
2687
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2688
    } else {
2689 2690 2691
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2692
    }
2693
});
V
Vaidegi B 已提交
2694 2695 2696
```


2697
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2698

2699
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2700

W
wusongqing 已提交
2701
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2702

W
wusongqing 已提交
2703
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2704

W
wusongqing 已提交
2705
**Return value**
V
Vaidegi B 已提交
2706

W
wusongqing 已提交
2707 2708 2709
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
V
Vaidegi B 已提交
2710

W
wusongqing 已提交
2711
**Example**
V
Vaidegi B 已提交
2712 2713

```
2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724
audioCapturer.getCapturerInfo().then((audioParamsGet) => {
    if (audioParamsGet != undefined) {
        console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
        console.info('AudioFrameworkRecLog: Capturer SourceType:' + audioParamsGet.source);
        console.info('AudioFrameworkRecLog: Capturer capturerFlags:' + audioParamsGet.capturerFlags);
    }else {
        console.info('AudioFrameworkRecLog: audioParamsGet is : '+audioParamsGet);
        console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect: ');
    }
}).catch((err) => {
    console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
2725
});
2726
```
V
Vaidegi B 已提交
2727

2728
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2729

2730
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
V
Vaidegi B 已提交
2731

W
wusongqing 已提交
2732
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2733

W
wusongqing 已提交
2734
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2735

W
wusongqing 已提交
2736
**Parameters**
V
Vaidegi B 已提交
2737

W
wusongqing 已提交
2738 2739 2740
| Name  | Type                                                | Mandatory| Description                            |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
V
Vaidegi B 已提交
2741

W
wusongqing 已提交
2742
**Example**
V
Vaidegi B 已提交
2743 2744

```
2745
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2746
    if (err) {
2747
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2748
    } else {
2749 2750 2751 2752 2753
        console.log('Capturer GetStreamInfo:');
        console.log('Capturer sampling rate:' + streamInfo.samplingRate);
        console.log('Capturer channel:' + streamInfo.channels);
        console.log('Capturer format:' + streamInfo.sampleFormat);
        console.log('Capturer encoding type:' + streamInfo.encodingType);
V
Vaidegi B 已提交
2754
    }
2755
});
V
Vaidegi B 已提交
2756 2757
```

2758
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2759

2760
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2761

W
wusongqing 已提交
2762
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2763

W
wusongqing 已提交
2764
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2765

W
wusongqing 已提交
2766
**Return value**
V
Vaidegi B 已提交
2767

W
wusongqing 已提交
2768 2769 2770
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2771

W
wusongqing 已提交
2772
**Example**
V
Vaidegi B 已提交
2773 2774

```
2775 2776 2777 2778 2779 2780 2781 2782
audioCapturer.getStreamInfo().then((audioParamsGet) => {
    console.info('getStreamInfo:');
    console.info('sampleFormat:' + audioParamsGet.sampleFormat);
    console.info('samplingRate:' + audioParamsGet.samplingRate);
    console.info('channels:' + audioParamsGet.channels);
    console.info('encodingType:' + audioParamsGet.encodingType);
}).catch((err) => {
    console.log('getStreamInfo :ERROR: ' + err.message);
2783
});
V
Vaidegi B 已提交
2784 2785
```

2786
### start<sup>8+</sup>
V
Vaidegi B 已提交
2787

2788
start(callback: AsyncCallback<void\>): void
V
Vaidegi B 已提交
2789

2790
Starts capturing. This API uses an asynchronous callback to return the result.
2791

W
wusongqing 已提交
2792
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2793

W
wusongqing 已提交
2794
**Parameters**
2795

W
wusongqing 已提交
2796 2797 2798
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2799

W
wusongqing 已提交
2800
**Example**
2801 2802

```
2803
audioCapturer.start((err) => {
2804 2805 2806 2807 2808
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2809
});
2810 2811 2812
```


2813
### start<sup>8+</sup>
2814

2815
start(): Promise<void\>
2816

2817
Starts capturing. This API uses a promise to return the result.
2818

W
wusongqing 已提交
2819
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2820

W
wusongqing 已提交
2821
**Return value**
2822

W
wusongqing 已提交
2823 2824 2825
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2826

W
wusongqing 已提交
2827
**Example**
2828 2829 2830

```
audioCapturer.start().then(() => {
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840
    console.info('AudioFrameworkRecLog: ---------START---------');
    console.info('AudioFrameworkRecLog: Capturer started :SUCCESS ');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    console.info('AudioFrameworkRecLog: Capturer started :SUCCESS ');
    if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
        stateFlag = true;
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
    stateFlag=false;
2841 2842 2843
});
```

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

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

2848
Stops capturing. This API uses an asynchronous callback to return the result.
2849

W
wusongqing 已提交
2850
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2851

W
wusongqing 已提交
2852
**Parameters**
2853

W
wusongqing 已提交
2854 2855 2856
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2857

W
wusongqing 已提交
2858
**Example**
2859 2860

```
2861
audioCapturer.stop((err) => {
2862 2863 2864 2865 2866
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
2867
});
2868 2869 2870
```


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

2873
stop(): Promise<void\>
2874

2875
Stops capturing. This API uses a promise to return the result.
2876

W
wusongqing 已提交
2877
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2878

W
wusongqing 已提交
2879
**Return value**
2880

W
wusongqing 已提交
2881 2882 2883
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2884

W
wusongqing 已提交
2885
**Example**
2886 2887 2888

```
audioCapturer.stop().then(() => {
2889 2890 2891 2892 2893 2894 2895 2896 2897
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
    if ((audioCapturer.state == audioCapturer.AudioState.STATE_STOPPED)){
        stateFlag=true;
        console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false;
2898 2899 2900
});
```

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

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

W
wusongqing 已提交
2905
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
2906

W
wusongqing 已提交
2907
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2908

W
wusongqing 已提交
2909
**Parameters**
2910

W
wusongqing 已提交
2911 2912 2913
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
2914

W
wusongqing 已提交
2915
**Example**
2916 2917

```
2918
audioCapturer.release((err) => {
2919 2920 2921 2922 2923
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
2924
});
2925 2926 2927
```


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

2930
release(): Promise<void\>
2931

W
wusongqing 已提交
2932
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
2933

W
wusongqing 已提交
2934
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2935

W
wusongqing 已提交
2936
**Return value**
2937

W
wusongqing 已提交
2938 2939 2940
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2941

W
wusongqing 已提交
2942
**Example**
2943 2944 2945

```
audioCapturer.release().then(() => {
2946 2947 2948 2949 2950 2951 2952 2953 2954 2955
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    stateFlag=true;
    console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
    expect(stateFlag).assertTrue();
    done();
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false
2956 2957 2958 2959
});
```


2960
### read<sup>8+</sup>
2961

2962
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
2963

W
wusongqing 已提交
2964
Reads the buffer. This API uses an asynchronous callback to return the result.
2965

W
wusongqing 已提交
2966
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2967

W
wusongqing 已提交
2968
**Parameters**
2969

W
wusongqing 已提交
2970 2971 2972 2973 2974
| Name        | Type                       | Mandatory| Description                            |
| :------------- | :-------------------------- | :--- | :------------------------------- |
| size           | number                      | Yes  | Number of bytes to read.                  |
| isBlockingRead | boolean                     | Yes  | Whether to block the read operation.                |
| callback       | AsyncCallback<ArrayBuffer\> | Yes  | Callback used to return the buffer.|
2975

W
wusongqing 已提交
2976
**Example**
2977 2978 2979 2980 2981 2982 2983 2984 2985 2986

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
};
```


2987
### read<sup>8+</sup>
2988

2989
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
2990

W
wusongqing 已提交
2991
Reads the buffer. This API uses a promise to return the result.
2992

W
wusongqing 已提交
2993
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2994

W
wusongqing 已提交
2995
**Parameters**
2996

W
wusongqing 已提交
2997 2998 2999 3000
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3001

W
wusongqing 已提交
3002
**Return value**
3003

W
wusongqing 已提交
3004 3005 3006
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3007

W
wusongqing 已提交
3008
**Example**
3009 3010

```
3011 3012 3013 3014
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3015 3016 3017 3018
});
```


3019
### getAudioTime<sup>8+</sup>
3020

3021
getAudioTime(callback: AsyncCallback<number\>): void
3022

W
wusongqing 已提交
3023
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
3024

W
wusongqing 已提交
3025
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3026

W
wusongqing 已提交
3027
**Parameters**
3028

W
wusongqing 已提交
3029 3030 3031
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3032

W
wusongqing 已提交
3033
**Example**
3034 3035

```
3036
audioCapturer.getAudioTime((err, timestamp) => {
3037
    console.log('Current timestamp: ' + timestamp);
3038
});
3039 3040 3041
```


3042
### getAudioTime<sup>8+</sup>
3043

3044
getAudioTime(): Promise<number\>
3045

W
wusongqing 已提交
3046
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
3047

W
wusongqing 已提交
3048
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3049

W
wusongqing 已提交
3050
**Return value**
3051

W
wusongqing 已提交
3052 3053 3054
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3055

W
wusongqing 已提交
3056
**Example**
3057 3058 3059

```
audioCapturer.getAudioTime().then((audioTime) => {
3060 3061 3062
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3063 3064 3065 3066
});
```


3067
### getBufferSize<sup>8+</sup>
3068

3069
getBufferSize(callback: AsyncCallback<number\>): void
3070

3071
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
3072

W
wusongqing 已提交
3073
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3074

W
wusongqing 已提交
3075
**Parameters**
3076

W
wusongqing 已提交
3077 3078 3079
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3080

W
wusongqing 已提交
3081
**Example**
3082 3083

```
3084
audioCapturer.getBufferSize((err, bufferSize) => {
3085 3086
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3087 3088 3089 3090 3091
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3092 3093 3094 3095
    }
});
```

W
wusongqing 已提交
3096

3097
### getBufferSize<sup>8+</sup>
3098

3099
getBufferSize(): Promise<number\>
3100

3101
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
3102

W
wusongqing 已提交
3103
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3104

W
wusongqing 已提交
3105
**Return value**
3106

W
wusongqing 已提交
3107 3108 3109
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3110

W
wusongqing 已提交
3111
**Example**
3112 3113 3114

```
audioCapturer.getBufferSize().then((bufferSize) => {
3115 3116 3117 3118 3119 3120 3121 3122
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('ERROR : '+err.message);
        });
    }
3123 3124 3125
});
```

W
wusongqing 已提交
3126

3127
### on('markReach')<sup>8+</sup>
3128

3129
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
3130

W
wusongqing 已提交
3131
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
3132

W
wusongqing 已提交
3133
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3134

W
wusongqing 已提交
3135
**Parameters**
3136

W
wusongqing 已提交
3137 3138 3139 3140 3141
| Name  | Type                   | Mandatory| Description                                      |
| :------- | :---------------------- | :--- | :----------------------------------------- |
| type     | string                  | Yes  | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame    | number                  | Yes  | Number of frames to trigger the event. The value must be greater than **0**.          |
| callback | position: number) => {} | Yes  | Callback invoked when the event is triggered.|
3142

W
wusongqing 已提交
3143
**Example**
3144 3145 3146 3147 3148 3149 3150 3151 3152

```
audioCapturer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

3153
### off('markReach')<sup>8+</sup>
3154

3155
off(type: 'markReach'): void
3156

W
wusongqing 已提交
3157
Unsubscribes from mark reached events.
3158

W
wusongqing 已提交
3159
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3160

W
wusongqing 已提交
3161
**Parameters**
3162

W
wusongqing 已提交
3163 3164 3165
| Name| Type  | Mandatory| Description                                         |
| :----- | :----- | :--- | :-------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
3166

W
wusongqing 已提交
3167
**Example**
3168 3169 3170 3171 3172

```
audioCapturer.off('markReach');
```

3173
### on('periodReach')<sup>8+</sup>
3174

3175
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
3176

W
wusongqing 已提交
3177
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3178

W
wusongqing 已提交
3179
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3180

W
wusongqing 已提交
3181
**Parameters**
3182

W
wusongqing 已提交
3183 3184 3185
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | Yes  | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
W
wusongqing 已提交
3186
| frame    | number                   | Yes  | Period during which frame rendering is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3187
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3188

W
wusongqing 已提交
3189
**Example**
3190 3191 3192 3193 3194 3195 3196 3197 3198

```
audioCapturer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

3199
### off('periodReach')<sup>8+</sup>
3200

3201
off(type: 'periodReach'): void
3202 3203 3204

Unsubscribes from period reached events.

W
wusongqing 已提交
3205
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3206

W
wusongqing 已提交
3207
**Parameters**
3208

W
wusongqing 已提交
3209 3210 3211
| Name| Type  | Mandatory| Description                                           |
| :----- | :----- | :--- | :---------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
3212

W
wusongqing 已提交
3213
**Example**
3214 3215 3216 3217 3218 3219 3220 3221

```
audioCapturer.off('periodReach')
```

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

on(type: 'stateChange', callback: Callback<AudioState\>): void
3222

3223
Subscribes to state change events.
3224

W
wusongqing 已提交
3225
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3226

W
wusongqing 已提交
3227
**Parameters**
3228

W
wusongqing 已提交
3229 3230 3231 3232
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | Yes  | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
3233

W
wusongqing 已提交
3234
**Example**
3235 3236

```
3237 3238 3239 3240 3241 3242 3243 3244
audioCapturer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio capturer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio capturer state is: STATE_RUNNING");
    }
});
3245
```