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

W
wusongqing 已提交
3 4 5 6
>  **NOTE**<br/>
>  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 已提交
7

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

W
wusongqing 已提交
10 11 12
- [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.
13 14

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

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

W
wusongqing 已提交
20

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

23
getAudioManager(): AudioManager
24

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

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

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

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

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

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

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

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

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

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

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

```
57
import audio from '@ohos.multimedia.audio';
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
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) {
78
        console.error(`AudioRenderer Created : Error: ${err.message}`);
79 80
    }
    else {
81 82
        console.info('AudioRenderer Created : Success : SUCCESS');
        let audioRenderer = data;
83 84 85
    }
});
```
W
wusongqing 已提交
86

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

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

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

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

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

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

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

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

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

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

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
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
}

130 131 132 133 134 135 136
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 已提交
137 138
```

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

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

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

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

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

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

**Example**
155 156

```
157
import audio from '@ohos.multimedia.audio';
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
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');
181
        let audioCapturer = data;
182 183 184 185
    }
});
```

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

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

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

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

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

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

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

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

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

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

211 212 213 214 215 216 217 218 219 220 221 222 223
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 = {
224 225
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
226
}
V
Vaidegi B 已提交
227

228 229 230 231 232 233 234
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);
});
235
```
V
Vaidegi B 已提交
236

237
## AudioVolumeType
W
wusongqing 已提交
238

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

W
wusongqing 已提交
241 242 243 244 245 246 247 248
**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 已提交
249

V
Vaidegi B 已提交
250

251
## DeviceFlag
W
wusongqing 已提交
252

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

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

W
wusongqing 已提交
257 258 259 260 261
| 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 已提交
262

263 264

## DeviceRole
W
wusongqing 已提交
265

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

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

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

V
Vaidegi B 已提交
275

276
## DeviceType
W
wusongqing 已提交
277

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

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

W
wusongqing 已提交
282 283 284 285 286 287 288 289 290 291 292
| 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 已提交
293

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

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

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

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

## AudioRingMode
W
wusongqing 已提交
306

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

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

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

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

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

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

W
wusongqing 已提交
323 324 325 326 327 328 329
| 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.|
330 331

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

Enumerates the audio channels.

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

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

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

Enumerates the audio sampling rates.

W
wusongqing 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
**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.|
361 362 363

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

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

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

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

373 374
## ContentType

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

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

W
wusongqing 已提交
379 380 381 382 383 384 385 386
| 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 已提交
387

388 389
## StreamUsage

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

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

W
wusongqing 已提交
394 395 396 397 398 399
| 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 已提交
400

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

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

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

W
wusongqing 已提交
407 408 409 410 411 412 413 414 415
| 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 已提交
416

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

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

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

W
wusongqing 已提交
423 424 425 426 427
| 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 已提交
428

429
## InterruptType
V
Vaidegi B 已提交
430

W
wusongqing 已提交
431 432 433 434 435 436 437 438 439 440
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 已提交
441

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

W
wusongqing 已提交
444 445 446 447 448 449
**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.|
450 451

## InterruptHint
V
Vaidegi B 已提交
452

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

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

W
wusongqing 已提交
457 458 459 460 461 462 463 464
| 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.                              |
465 466 467

## InterruptActionType

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

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

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

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

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

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

W
wusongqing 已提交
483 484 485 486 487 488
| 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.    |
489 490

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

Describes audio renderer information.

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

W
wusongqing 已提交
496 497 498 499 500
| 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 已提交
501

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

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

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

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

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

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

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

W
wusongqing 已提交
519 520 521 522 523
| 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 已提交
524

525
## AudioInterrupt
526

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

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

W
wusongqing 已提交
531
| Name           | Type                       | Mandatory| Description                                                        |
532
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
533 534 535
| 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.|
536 537 538

## InterruptAction

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

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

W
wusongqing 已提交
543 544 545 546 547 548
| 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.                                              |
| hint       | [InterruptHint](interrupthint)              | No  | Hint provided along with the audio interruption event.                                              |
| 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.|
549 550

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

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

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

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

W
wusongqing 已提交
558 559 560 561 562
| 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 已提交
563

564
## DeviceChangeAction
565

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

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

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

## DeviceChangeType
576

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

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

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

W
wusongqing 已提交
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
## 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
602

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

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

Enumerates the audio source types.
611

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

W
wusongqing 已提交
614 615 616 617 618
| 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.|
619 620

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

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

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

W
wusongqing 已提交
626 627 628 629 630 631
| 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 已提交
632

633
## AudioManager
W
wusongqing 已提交
634

W
wusongqing 已提交
635
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 已提交
636

637 638
### setVolume

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

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

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

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

W
wusongqing 已提交
647 648 649 650 651
| 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.                                  |
652

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

```
656 657 658 659 660 661
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.');
662
});
W
wusongqing 已提交
663
```
W
wusongqing 已提交
664

665
### setVolume
W
wusongqing 已提交
666

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

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

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

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

W
wusongqing 已提交
675 676 677 678
| 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**.|
679

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

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

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

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

### getVolume
W
wusongqing 已提交
695

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### getMinVolume

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### getMaxVolume

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

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

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

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

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

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

```
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);
828
});
W
wusongqing 已提交
829 830
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
869 870 871 872 873
| 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.               |
874

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

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

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

W
wusongqing 已提交
889 890 891
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 已提交
892

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

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

W
wusongqing 已提交
897 898 899 900
| 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.|
901

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

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

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

W
wusongqing 已提交
910 911

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

V
Vaidegi B 已提交
917

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

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

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

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

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

W
wusongqing 已提交
928 929 930 931
| 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.|
932

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

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


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

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

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

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

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

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

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

W
wusongqing 已提交
962 963 964
| 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.|
965

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

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

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

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

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

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

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

W
wusongqing 已提交
984 985 986 987
| 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.|
988

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1017 1018 1019
| 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.|
1020

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

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

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

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

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

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

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

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

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

```
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.');
1053
});
W
wusongqing 已提交
1054 1055
```

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

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

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

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

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

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

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

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

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

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

V
Vaidegi B 已提交
1084

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

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

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

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

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

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

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

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

V
Vaidegi B 已提交
1111

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1144 1145 1146 1147 1148
| 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 已提交
1149

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1201 1202 1203 1204
| 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 已提交
1205

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

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

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

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

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

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

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

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

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

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

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

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

1246 1247
### getDevices

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

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

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

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

W
wusongqing 已提交
1256 1257 1258 1259
| 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 已提交
1260

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1310 1311 1312 1313 1314
| 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.|
1315

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

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

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

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

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

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

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

W
wusongqing 已提交
1338 1339 1340 1341
| 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 已提交
1342

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

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

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

W
wusongqing 已提交
1351 1352

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

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

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

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

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

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

W
wusongqing 已提交
1368 1369 1370 1371
| 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.|
1372

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

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

V
Vaidegi B 已提交
1385

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1424 1425 1426 1427
| 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 已提交
1428

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

```
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.');
1438
});
W
wusongqing 已提交
1439 1440
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1479 1480 1481
| 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 已提交
1482

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

```
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);
1492
});
W
wusongqing 已提交
1493 1494
```

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

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

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

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

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

W
wusongqing 已提交
1505 1506 1507
| 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 已提交
1508

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


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

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

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

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

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

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

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

W
wusongqing 已提交
1530 1531 1532 1533
| 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 已提交
1534

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1557 1558 1559 1560
| 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 已提交
1561

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

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

1570
### on('deviceChange')
1571

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

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

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

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

W
wusongqing 已提交
1580 1581 1582 1583
| 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.                        |
1584

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

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

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

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

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

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

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

W
wusongqing 已提交
1606 1607 1608 1609
| 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.                        |
1610

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

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

### on('interrupt')

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

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

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

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

W
wusongqing 已提交
1629 1630 1631 1632 1633
| 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.                                      |
1634

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

```
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 已提交
1659
Unsubscribes from audio interruption events.
1660

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

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

W
wusongqing 已提交
1665 1666
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1667
| 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 已提交
1668 1669
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1670

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

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

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

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

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

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

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

W
wusongqing 已提交
1699 1700 1701 1702
| 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.|
1703

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

```
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.');
1713
});
1714 1715
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```
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);
1771
});
1772 1773 1774
```


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

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

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

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

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

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

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

```
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');
1796
});
1797 1798
```

1799
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1800

1801
Describes an audio device.
1802

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

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

1810
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1811

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

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

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

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

}

1825 1826 1827 1828 1829 1830
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 已提交
1831
    if (deviceTypeValue != null && deviceRoleValue != null){
1832
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1833 1834
    }
    else{
1835 1836
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1837
});
V
Vaidegi B 已提交
1838
```
W
wusongqing 已提交
1839

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1885
getRendererInfo(): Promise<AudioRendererInfo\>
1886

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

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

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

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

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

```
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909
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 已提交
1910

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```
1954 1955 1956 1957 1958 1959 1960 1961 1962
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 已提交
1963 1964
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
2225 2226 2227 2228
| 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 已提交
2229

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

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

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

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

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

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

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

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

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

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

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

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2269 2270 2271
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2272 2273 2274 2275 2276 2277 2278 2279 2280
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 已提交
2281 2282
```

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

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

W
wusongqing 已提交
2287
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 已提交
2288

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

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

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

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

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

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

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

W
wusongqing 已提交
2309
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 已提交
2310

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2461
getRenderRate(): Promise\<AudioRendererRate>
2462

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

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

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

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

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

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

W
wusongqing 已提交
2483 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
### 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;
        }
    }
});
```

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

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

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

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

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

W
wusongqing 已提交
2538 2539 2540 2541 2542
| 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.                   |
2543

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

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


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

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

Unsubscribes from mark reached events.

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
2585 2586 2587 2588 2589
| 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.                     |
2590

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

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

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

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

Unsubscribes from period reached events.

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
2631 2632 2633 2634
| 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.                           |
2635

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

```
2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723
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);
2724
});
2725
```
V
Vaidegi B 已提交
2726

2727
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2728

2729
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
V
Vaidegi B 已提交
2730

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

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

W
wusongqing 已提交
2735
**Parameters**
V
Vaidegi B 已提交
2736

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

W
wusongqing 已提交
2741
**Example**
V
Vaidegi B 已提交
2742 2743

```
2744
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2745
    if (err) {
2746
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2747
    } else {
2748 2749 2750 2751 2752
        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 已提交
2753
    }
2754
});
V
Vaidegi B 已提交
2755 2756
```

2757
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2758

2759
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2760

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

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

W
wusongqing 已提交
2765
**Return value**
V
Vaidegi B 已提交
2766

W
wusongqing 已提交
2767 2768 2769
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2770

W
wusongqing 已提交
2771
**Example**
V
Vaidegi B 已提交
2772 2773

```
2774 2775 2776 2777 2778 2779 2780 2781
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);
2782
});
V
Vaidegi B 已提交
2783 2784
```

2785
### start<sup>8+</sup>
V
Vaidegi B 已提交
2786

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

2789
Starts capturing. This API uses an asynchronous callback to return the result.
2790

W
wusongqing 已提交
2791
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2792

W
wusongqing 已提交
2793
**Parameters**
2794

W
wusongqing 已提交
2795 2796 2797
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2798

W
wusongqing 已提交
2799
**Example**
2800 2801

```
2802
audioCapturer.start((err) => {
2803 2804 2805 2806 2807
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2808
});
2809 2810 2811
```


2812
### start<sup>8+</sup>
2813

2814
start(): Promise<void\>
2815

2816
Starts capturing. This API uses a promise to return the result.
2817

W
wusongqing 已提交
2818
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2819

W
wusongqing 已提交
2820
**Return value**
2821

W
wusongqing 已提交
2822 2823 2824
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2825

W
wusongqing 已提交
2826
**Example**
2827 2828 2829

```
audioCapturer.start().then(() => {
2830 2831 2832 2833 2834 2835 2836 2837 2838 2839
    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;
2840 2841 2842
});
```

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

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

2847
Stops capturing. This API uses an asynchronous callback to return the result.
2848

W
wusongqing 已提交
2849
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2850

W
wusongqing 已提交
2851
**Parameters**
2852

W
wusongqing 已提交
2853 2854 2855
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2856

W
wusongqing 已提交
2857
**Example**
2858 2859

```
2860
audioCapturer.stop((err) => {
2861 2862 2863 2864 2865
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
2866
});
2867 2868 2869
```


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

2872
stop(): Promise<void\>
2873

2874
Stops capturing. This API uses a promise to return the result.
2875

W
wusongqing 已提交
2876
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2877

W
wusongqing 已提交
2878
**Return value**
2879

W
wusongqing 已提交
2880 2881 2882
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2883

W
wusongqing 已提交
2884
**Example**
2885 2886 2887

```
audioCapturer.stop().then(() => {
2888 2889 2890 2891 2892 2893 2894 2895 2896
    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;
2897 2898 2899
});
```

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

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

W
wusongqing 已提交
2904
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
2905

W
wusongqing 已提交
2906
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2907

W
wusongqing 已提交
2908
**Parameters**
2909

W
wusongqing 已提交
2910 2911 2912
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
2913

W
wusongqing 已提交
2914
**Example**
2915 2916

```
2917
audioCapturer.release((err) => {
2918 2919 2920 2921 2922
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
2923
});
2924 2925 2926
```


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

2929
release(): Promise<void\>
2930

W
wusongqing 已提交
2931
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
2932

W
wusongqing 已提交
2933
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2934

W
wusongqing 已提交
2935
**Return value**
2936

W
wusongqing 已提交
2937 2938 2939
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2940

W
wusongqing 已提交
2941
**Example**
2942 2943 2944

```
audioCapturer.release().then(() => {
2945 2946 2947 2948 2949 2950 2951 2952 2953 2954
    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
2955 2956 2957 2958
});
```


2959
### read<sup>8+</sup>
2960

2961
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
2962

W
wusongqing 已提交
2963
Reads the buffer. This API uses an asynchronous callback to return the result.
2964

W
wusongqing 已提交
2965
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2966

W
wusongqing 已提交
2967
**Parameters**
2968

W
wusongqing 已提交
2969 2970 2971 2972 2973
| 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.|
2974

W
wusongqing 已提交
2975
**Example**
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
};
```


2986
### read<sup>8+</sup>
2987

2988
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
2989

W
wusongqing 已提交
2990
Reads the buffer. This API uses a promise to return the result.
2991

W
wusongqing 已提交
2992
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2993

W
wusongqing 已提交
2994
**Parameters**
2995

W
wusongqing 已提交
2996 2997 2998 2999
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3000

W
wusongqing 已提交
3001
**Return value**
3002

W
wusongqing 已提交
3003 3004 3005
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3006

W
wusongqing 已提交
3007
**Example**
3008 3009

```
3010 3011 3012 3013
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3014 3015 3016 3017
});
```


3018
### getAudioTime<sup>8+</sup>
3019

3020
getAudioTime(callback: AsyncCallback<number\>): void
3021

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

W
wusongqing 已提交
3024
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3025

W
wusongqing 已提交
3026
**Parameters**
3027

W
wusongqing 已提交
3028 3029 3030
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3031

W
wusongqing 已提交
3032
**Example**
3033 3034

```
3035
audioCapturer.getAudioTime((err, timestamp) => {
3036
    console.log('Current timestamp: ' + timestamp);
3037
});
3038 3039 3040
```


3041
### getAudioTime<sup>8+</sup>
3042

3043
getAudioTime(): Promise<number\>
3044

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

W
wusongqing 已提交
3047
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3048

W
wusongqing 已提交
3049
**Return value**
3050

W
wusongqing 已提交
3051 3052 3053
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3054

W
wusongqing 已提交
3055
**Example**
3056 3057 3058

```
audioCapturer.getAudioTime().then((audioTime) => {
3059 3060 3061
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3062 3063 3064 3065
});
```


3066
### getBufferSize<sup>8+</sup>
3067

3068
getBufferSize(callback: AsyncCallback<number\>): void
3069

3070
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
3071

W
wusongqing 已提交
3072
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3073

W
wusongqing 已提交
3074
**Parameters**
3075

W
wusongqing 已提交
3076 3077 3078
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3079

W
wusongqing 已提交
3080
**Example**
3081 3082

```
3083
audioCapturer.getBufferSize((err, bufferSize) => {
3084 3085
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3086 3087 3088 3089 3090
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3091 3092 3093 3094
    }
});
```

W
wusongqing 已提交
3095

3096
### getBufferSize<sup>8+</sup>
3097

3098
getBufferSize(): Promise<number\>
3099

3100
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
3101

W
wusongqing 已提交
3102
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3103

W
wusongqing 已提交
3104
**Return value**
3105

W
wusongqing 已提交
3106 3107 3108
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3109

W
wusongqing 已提交
3110
**Example**
3111 3112 3113

```
audioCapturer.getBufferSize().then((bufferSize) => {
3114 3115 3116 3117 3118 3119 3120 3121
    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);
        });
    }
3122 3123 3124
});
```

W
wusongqing 已提交
3125

3126
### on('markReach')<sup>8+</sup>
3127

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

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

W
wusongqing 已提交
3132
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3133

W
wusongqing 已提交
3134
**Parameters**
3135

W
wusongqing 已提交
3136 3137 3138 3139 3140
| 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.|
3141

W
wusongqing 已提交
3142
**Example**
3143 3144 3145 3146 3147 3148 3149 3150 3151

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

3152
### off('markReach')<sup>8+</sup>
3153

3154
off(type: 'markReach'): void
3155

W
wusongqing 已提交
3156
Unsubscribes from mark reached events.
3157

W
wusongqing 已提交
3158
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3159

W
wusongqing 已提交
3160
**Parameters**
3161

W
wusongqing 已提交
3162 3163 3164
| 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.|
3165

W
wusongqing 已提交
3166
**Example**
3167 3168 3169 3170 3171

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

3172
### on('periodReach')<sup>8+</sup>
3173

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

W
wusongqing 已提交
3176
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3177

W
wusongqing 已提交
3178
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3179

W
wusongqing 已提交
3180
**Parameters**
3181

W
wusongqing 已提交
3182 3183 3184
| 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 已提交
3185
| frame    | number                   | Yes  | Period during which frame rendering is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3186
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3187

W
wusongqing 已提交
3188
**Example**
3189 3190 3191 3192 3193 3194 3195 3196 3197

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

3198
### off('periodReach')<sup>8+</sup>
3199

3200
off(type: 'periodReach'): void
3201 3202 3203

Unsubscribes from period reached events.

W
wusongqing 已提交
3204
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3205

W
wusongqing 已提交
3206
**Parameters**
3207

W
wusongqing 已提交
3208 3209 3210
| 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.|
3211

W
wusongqing 已提交
3212
**Example**
3213 3214 3215 3216 3217 3218 3219 3220

```
audioCapturer.off('periodReach')
```

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

on(type: 'stateChange', callback: Callback<AudioState\>): void
3221

3222
Subscribes to state change events.
3223

W
wusongqing 已提交
3224
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3225

W
wusongqing 已提交
3226
**Parameters**
3227

W
wusongqing 已提交
3228 3229 3230 3231
| 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.                           |
3232

W
wusongqing 已提交
3233
**Example**
3234 3235

```
3236 3237 3238 3239 3240 3241 3242 3243
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");
    }
});
3244
```