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

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

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

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

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

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

W
wusongqing 已提交
21

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

24
getAudioManager(): AudioManager
25

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

**Example**
156 157

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

238
## AudioVolumeType
W
wusongqing 已提交
239

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

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

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

V
Vaidegi B 已提交
251

252
## DeviceFlag
W
wusongqing 已提交
253

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

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

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

264 265

## DeviceRole
W
wusongqing 已提交
266

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

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

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

V
Vaidegi B 已提交
276

277
## DeviceType
W
wusongqing 已提交
278

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

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

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

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

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

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

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

## AudioRingMode
W
wusongqing 已提交
307

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

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

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

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

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

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

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

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

Enumerates the audio channels.

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

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

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

Enumerates the audio sampling rates.

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

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

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

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

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

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

374 375
## ContentType

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

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

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

389 390
## StreamUsage

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

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

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

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

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

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

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

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

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

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

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

430
## InterruptType
V
Vaidegi B 已提交
431

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

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

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

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

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

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

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

## InterruptHint
V
Vaidegi B 已提交
453

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

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

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

## InterruptActionType

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

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

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

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

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

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

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

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

Describes audio renderer information.

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

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

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

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

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

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

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

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

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

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

526
## AudioInterrupt
527

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

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

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

## InterruptAction

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

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

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

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

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

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

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

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

565
## DeviceChangeAction
566

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

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

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

## DeviceChangeType
577

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

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

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

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

Describes audio capturer configurations.

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

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

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

Describes audio capturer information.

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

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

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

Enumerates the audio source types.
612

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

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

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

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

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

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

634
## AudioManager
W
wusongqing 已提交
635

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

638 639
### setVolume

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

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

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

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

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

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

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

666
### setVolume
W
wusongqing 已提交
667

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

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

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

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

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

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

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

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

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

### getVolume
W
wusongqing 已提交
696

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### getMinVolume

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### getMaxVolume

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

W
wusongqing 已提交
911 912

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

V
Vaidegi B 已提交
918

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

V
Vaidegi B 已提交
1085

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

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

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

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

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

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

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

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

V
Vaidegi B 已提交
1112

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

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

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

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

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

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

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

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

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

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

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

1141 1142
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

W
wusongqing 已提交
1143
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1144

W
wusongqing 已提交
1145
**Parameters**
W
wusongqing 已提交
1146

W
wusongqing 已提交
1147 1148 1149 1150 1151
| 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 已提交
1152

W
wusongqing 已提交
1153
**Example**
W
wusongqing 已提交
1154 1155

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

1165
### setAudioParameter
V
Vaidegi B 已提交
1166

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

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

1171 1172
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

W
wusongqing 已提交
1173
**System capability**: SystemCapability.Multimedia.Audio.Core
1174

W
wusongqing 已提交
1175
**Parameters**
W
wusongqing 已提交
1176

W
wusongqing 已提交
1177 1178 1179 1180
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
1181

W
wusongqing 已提交
1182
**Return value**
1183

W
wusongqing 已提交
1184 1185 1186
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1187

W
wusongqing 已提交
1188
**Example**
W
wusongqing 已提交
1189 1190

```
1191
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
W
wusongqing 已提交
1192
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1193
});
W
wusongqing 已提交
1194 1195
```

1196
### getAudioParameter
V
Vaidegi B 已提交
1197

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

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

1202 1203
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

W
wusongqing 已提交
1204
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1205

W
wusongqing 已提交
1206
**Parameters**
W
wusongqing 已提交
1207

W
wusongqing 已提交
1208 1209 1210 1211
| 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 已提交
1212

W
wusongqing 已提交
1213
**Example**
W
wusongqing 已提交
1214 1215

```
1216
audioManager.getAudioParameter('key_example', (err, value) => {
W
wusongqing 已提交
1217 1218
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1219
        return;
W
wusongqing 已提交
1220 1221
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1222
});
W
wusongqing 已提交
1223 1224
```

1225
### getAudioParameter
V
Vaidegi B 已提交
1226

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

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

1231 1232
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

W
wusongqing 已提交
1233
**System capability**: SystemCapability.Multimedia.Audio.Core
1234

W
wusongqing 已提交
1235
**Parameters**
1236

W
wusongqing 已提交
1237 1238 1239
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1240

W
wusongqing 已提交
1241
**Return value**
W
wusongqing 已提交
1242

W
wusongqing 已提交
1243 1244 1245
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1246

W
wusongqing 已提交
1247
**Example**
W
wusongqing 已提交
1248 1249

```
1250
audioManager.getAudioParameter('key_example').then((value) => {
W
wusongqing 已提交
1251
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1252
});
W
wusongqing 已提交
1253 1254
```

1255 1256
### getDevices

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

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

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

W
wusongqing 已提交
1263
**Parameters**
1264

W
wusongqing 已提交
1265 1266 1267 1268
| 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 已提交
1269

W
wusongqing 已提交
1270
**Example**
W
wusongqing 已提交
1271
```
1272
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1273
   if (err) {
1274 1275
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1276 1277
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1278
});
W
wusongqing 已提交
1279 1280
```

1281
### getDevices
V
Vaidegi B 已提交
1282

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

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

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

W
wusongqing 已提交
1289
**Parameters**
W
wusongqing 已提交
1290

W
wusongqing 已提交
1291 1292 1293
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
W
wusongqing 已提交
1294

W
wusongqing 已提交
1295
**Return value**
1296

W
wusongqing 已提交
1297 1298 1299
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
W
wusongqing 已提交
1300

W
wusongqing 已提交
1301
**Example**
W
wusongqing 已提交
1302 1303

```
1304
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1305
    console.log('Promise returned to indicate that the device list is obtained.');
1306
});
W
wusongqing 已提交
1307 1308
```

1309
### setDeviceActive
V
Vaidegi B 已提交
1310

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

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

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

W
wusongqing 已提交
1317
**Parameters**
W
wusongqing 已提交
1318

W
wusongqing 已提交
1319 1320 1321 1322 1323
| 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.|
1324

W
wusongqing 已提交
1325
**Example**
W
wusongqing 已提交
1326 1327

```
J
jiao_yanlin 已提交
1328
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1329 1330
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1331
        return;
W
wusongqing 已提交
1332 1333
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1334
});
W
wusongqing 已提交
1335 1336
```

1337
### setDeviceActive
V
Vaidegi B 已提交
1338

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

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

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

W
wusongqing 已提交
1345
**Parameters**
1346

W
wusongqing 已提交
1347 1348 1349 1350
| 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 已提交
1351

W
wusongqing 已提交
1352
**Return value**
1353

W
wusongqing 已提交
1354 1355 1356
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1357

W
wusongqing 已提交
1358
**Example**
1359

W
wusongqing 已提交
1360 1361

```
J
jiao_yanlin 已提交
1362
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1363
    console.log('Promise returned to indicate that the device is set to the active status.');
1364
});
W
wusongqing 已提交
1365 1366
```

1367
### isDeviceActive
V
Vaidegi B 已提交
1368

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

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

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

W
wusongqing 已提交
1375
**Parameters**
W
wusongqing 已提交
1376

W
wusongqing 已提交
1377 1378 1379 1380
| 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.|
1381

W
wusongqing 已提交
1382
**Example**
W
wusongqing 已提交
1383 1384

```
J
jiao_yanlin 已提交
1385
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1386 1387
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1388
        return;
W
wusongqing 已提交
1389 1390
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1391
});
W
wusongqing 已提交
1392 1393
```

V
Vaidegi B 已提交
1394

1395
### isDeviceActive
V
Vaidegi B 已提交
1396

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

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

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

W
wusongqing 已提交
1403
**Parameters**
1404

W
wusongqing 已提交
1405 1406 1407
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
1408

W
wusongqing 已提交
1409
**Return value**
1410

W
wusongqing 已提交
1411 1412 1413
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1414

W
wusongqing 已提交
1415
**Example**
W
wusongqing 已提交
1416 1417

```
J
jiao_yanlin 已提交
1418
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1419
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1420
});
W
wusongqing 已提交
1421 1422
```

1423
### setMicrophoneMute
V
Vaidegi B 已提交
1424

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

1427 1428
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
1431
**Parameters**
W
wusongqing 已提交
1432

W
wusongqing 已提交
1433 1434 1435 1436
| 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 已提交
1437

W
wusongqing 已提交
1438
**Example**
W
wusongqing 已提交
1439 1440 1441 1442 1443 1444 1445 1446

```
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.');
1447
});
W
wusongqing 已提交
1448 1449
```

1450
### setMicrophoneMute
V
Vaidegi B 已提交
1451

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

1454 1455
Mutes or unmutes the microphone. This API uses a promise to return the result.

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

W
wusongqing 已提交
1458
**Parameters**
1459

W
wusongqing 已提交
1460 1461 1462
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1463

W
wusongqing 已提交
1464
**Return value**
W
wusongqing 已提交
1465

W
wusongqing 已提交
1466 1467 1468
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1469

W
wusongqing 已提交
1470
**Example**
W
wusongqing 已提交
1471 1472

```
1473
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1474
    console.log('Promise returned to indicate that the microphone is muted.');
1475
});
W
wusongqing 已提交
1476 1477
```

1478
### isMicrophoneMute
V
Vaidegi B 已提交
1479

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

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

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

W
wusongqing 已提交
1486
**Parameters**
W
wusongqing 已提交
1487

W
wusongqing 已提交
1488 1489 1490
| 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 已提交
1491

W
wusongqing 已提交
1492
**Example**
W
wusongqing 已提交
1493 1494 1495 1496 1497 1498 1499 1500

```
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);
1501
});
W
wusongqing 已提交
1502 1503
```

1504
### isMicrophoneMute
V
Vaidegi B 已提交
1505

W
wusongqing 已提交
1506 1507 1508
isMicrophoneMute(): Promise&lt;boolean&gt;

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

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

W
wusongqing 已提交
1512
**Return value**
1513

W
wusongqing 已提交
1514 1515 1516
| 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 已提交
1517

W
wusongqing 已提交
1518
**Example**
W
wusongqing 已提交
1519 1520 1521


```
1522
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1523
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1524
});
W
wusongqing 已提交
1525 1526
```

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

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

W
wusongqing 已提交
1531
Subscribes to system volume change events.
V
Vaidegi B 已提交
1532

1533
This is a system API and cannot be called by third-party applications.
1534

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

W
wusongqing 已提交
1537
**Parameters**
V
Vaidegi B 已提交
1538

W
wusongqing 已提交
1539 1540 1541 1542
| 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 已提交
1543

W
wusongqing 已提交
1544
**Example**
V
Vaidegi B 已提交
1545 1546 1547 1548 1549 1550

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

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

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

W
wusongqing 已提交
1558
Subscribes to ringer mode change events.
1559

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

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

W
wusongqing 已提交
1564
**Parameters**
V
Vaidegi B 已提交
1565

W
wusongqing 已提交
1566 1567 1568 1569
| 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 已提交
1570

W
wusongqing 已提交
1571
**Example**
V
Vaidegi B 已提交
1572 1573 1574 1575

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

1579
### on('deviceChange')
1580

1581
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1582

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

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

W
wusongqing 已提交
1587
**Parameters**
1588

W
wusongqing 已提交
1589 1590 1591 1592
| 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.                        |
1593

W
wusongqing 已提交
1594
**Example**
1595 1596 1597 1598 1599 1600 1601

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

1605 1606 1607 1608
### off('deviceChange')

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

W
wusongqing 已提交
1609
Unsubscribes from device change events.
1610

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

W
wusongqing 已提交
1613
**Parameters**
1614

W
wusongqing 已提交
1615 1616 1617 1618
| 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.                        |
1619

W
wusongqing 已提交
1620
**Example**
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631

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

### on('interrupt')

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

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

W
wusongqing 已提交
1634
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1635

W
wusongqing 已提交
1636
**Parameters**
1637

W
wusongqing 已提交
1638 1639 1640 1641 1642
| 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.                                      |
1643

W
wusongqing 已提交
1644
**Example**
1645 1646 1647 1648 1649 1650 1651

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
J
jiao_yanlin 已提交
1652
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
    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 已提交
1668
Unsubscribes from audio interruption events.
1669

W
wusongqing 已提交
1670
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1671

W
wusongqing 已提交
1672
**Parameters**
1673

W
wusongqing 已提交
1674 1675
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1676
| 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 已提交
1677 1678
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1679

W
wusongqing 已提交
1680
**Example**
1681 1682 1683 1684 1685 1686 1687

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
J
jiao_yanlin 已提交
1688
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1689 1690 1691 1692 1693 1694 1695 1696
    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>
1697

1698
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1699

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

1702
This is a system API and cannot be called by third-party applications.
1703

W
wusongqing 已提交
1704
**System capability**: SystemCapability.Multimedia.Audio.Communication
1705

W
wusongqing 已提交
1706
**Parameters**
1707

W
wusongqing 已提交
1708 1709 1710 1711
| 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.|
1712

W
wusongqing 已提交
1713
**Example**
1714 1715 1716 1717 1718 1719 1720 1721

```
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.');
1722
});
1723 1724
```

1725
### setAudioScene<sup>8+</sup>
1726

1727
setAudioScene\(scene: AudioScene\): Promise<void\>
1728

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

1731
This is a system API and cannot be called by third-party applications.
1732

W
wusongqing 已提交
1733
**System capability**: SystemCapability.Multimedia.Audio.Communication
1734

W
wusongqing 已提交
1735
**Parameters**
1736

W
wusongqing 已提交
1737 1738 1739
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1740

W
wusongqing 已提交
1741
**Return value**
1742

W
wusongqing 已提交
1743 1744 1745
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
1746

W
wusongqing 已提交
1747
**Example**
1748 1749

```
J
jiao_yanlin 已提交
1750
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1751 1752 1753 1754 1755 1756
    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');
});
```

1757
### getAudioScene<sup>8+</sup>
1758

1759
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1760

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

W
wusongqing 已提交
1763
**System capability**: SystemCapability.Multimedia.Audio.Communication
1764

W
wusongqing 已提交
1765
**Parameters**
1766

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

W
wusongqing 已提交
1771
**Example**
1772 1773 1774 1775 1776 1777 1778 1779

```
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);
1780
});
1781 1782 1783
```


1784
### getAudioScene<sup>8+</sup>
1785

1786
getAudioScene\(\): Promise<AudioScene\>
1787

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

W
wusongqing 已提交
1790
**System capability**: SystemCapability.Multimedia.Audio.Communication
1791

W
wusongqing 已提交
1792
**Return value**
1793

W
wusongqing 已提交
1794 1795 1796
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1797

W
wusongqing 已提交
1798
**Example**
1799 1800 1801 1802 1803 1804

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

1808
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1809

1810
Describes an audio device.
1811

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

W
wusongqing 已提交
1814 1815 1816 1817
| Name      | Type                   | Readable| Writable| Description      |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes  | No  | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes  | No  | Device type.|
V
Vaidegi B 已提交
1818

1819
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1820

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

W
wusongqing 已提交
1823
**Example**
V
Vaidegi B 已提交
1824

1825 1826
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1827

1828 1829 1830
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1831 1832 1833

}

1834 1835 1836 1837 1838 1839
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 已提交
1840
    if (deviceTypeValue != null && deviceRoleValue != null){
1841
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1842 1843
    }
    else{
1844 1845
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1846
});
V
Vaidegi B 已提交
1847
```
W
wusongqing 已提交
1848

1849 1850
## AudioRenderer<sup>8+</sup>

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

W
wusongqing 已提交
1853
### Attributes
V
Vaidegi B 已提交
1854

W
wusongqing 已提交
1855
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1856

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

W
wusongqing 已提交
1861
**Example**
V
Vaidegi B 已提交
1862 1863

```
W
wusongqing 已提交
1864
var state = audioRenderer.state;
V
Vaidegi B 已提交
1865 1866
```

1867
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1868

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

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

W
wusongqing 已提交
1873
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1874

W
wusongqing 已提交
1875
**Parameters**
V
Vaidegi B 已提交
1876

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

W
wusongqing 已提交
1881
**Example**
V
Vaidegi B 已提交
1882 1883

```
1884
audioRenderer.getRendererInfo((err, rendererInfo) => {
1885 1886 1887 1888
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1889
});
V
Vaidegi B 已提交
1890 1891
```

1892
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1893

1894
getRendererInfo(): Promise<AudioRendererInfo\>
1895

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

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

W
wusongqing 已提交
1900
**Return value**
V
Vaidegi B 已提交
1901

W
wusongqing 已提交
1902 1903 1904
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
V
Vaidegi B 已提交
1905

W
wusongqing 已提交
1906
**Example**
V
Vaidegi B 已提交
1907 1908

```
J
jiao_yanlin 已提交
1909
var resultFlag = true;
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919
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 已提交
1920

1921
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1922

1923
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1924

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

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

W
wusongqing 已提交
1929
**Parameters**
V
Vaidegi B 已提交
1930

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

W
wusongqing 已提交
1935
**Example**
V
Vaidegi B 已提交
1936 1937

```
1938
audioRenderer.getStreamInfo((err, streamInfo) => {
1939 1940
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1941 1942 1943
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1944
});
V
Vaidegi B 已提交
1945 1946
```

1947
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1948

1949
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1950

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

W
wusongqing 已提交
1953
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1954

W
wusongqing 已提交
1955
**Return value**
V
Vaidegi B 已提交
1956

W
wusongqing 已提交
1957 1958 1959
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
1960

W
wusongqing 已提交
1961
**Example**
V
Vaidegi B 已提交
1962 1963

```
1964 1965 1966 1967 1968 1969 1970 1971 1972
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 已提交
1973 1974
```

1975
### start<sup>8+</sup>
V
Vaidegi B 已提交
1976

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

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

W
wusongqing 已提交
1981
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1982

W
wusongqing 已提交
1983
**Parameters**
V
Vaidegi B 已提交
1984

W
wusongqing 已提交
1985 1986 1987
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
1988

W
wusongqing 已提交
1989
**Example**
V
Vaidegi B 已提交
1990 1991

```
1992
audioRenderer.start((err) => {
1993 1994
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
1995
    } else {
1996
        console.info('Renderer start success.');
V
Vaidegi B 已提交
1997
    }
1998
});
V
Vaidegi B 已提交
1999 2000
```

2001
### start<sup>8+</sup>
V
Vaidegi B 已提交
2002

2003
start(): Promise<void\>
V
Vaidegi B 已提交
2004

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

W
wusongqing 已提交
2007
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2008

W
wusongqing 已提交
2009
**Return value**
V
Vaidegi B 已提交
2010

W
wusongqing 已提交
2011 2012 2013
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2014

W
wusongqing 已提交
2015
**Example**
V
Vaidegi B 已提交
2016 2017

```
2018 2019 2020 2021 2022
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2023 2024
```

2025
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2026

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

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

W
wusongqing 已提交
2031
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2032

W
wusongqing 已提交
2033
**Parameters**
V
Vaidegi B 已提交
2034

W
wusongqing 已提交
2035 2036 2037
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2038

W
wusongqing 已提交
2039
**Example**
V
Vaidegi B 已提交
2040 2041

```
2042
audioRenderer.pause((err) => {
2043 2044
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2045
    } else {
2046
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2047
    }
2048
});
V
Vaidegi B 已提交
2049 2050
```

2051
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2052

2053
pause(): Promise\<void>
V
Vaidegi B 已提交
2054

2055
Pauses rendering. This API uses a promise to return the result.
2056

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

W
wusongqing 已提交
2059
**Return value**
V
Vaidegi B 已提交
2060

W
wusongqing 已提交
2061 2062 2063
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2064

W
wusongqing 已提交
2065
**Example**
V
Vaidegi B 已提交
2066 2067

```
2068 2069 2070 2071 2072
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2073 2074
```

2075
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2076

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

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

W
wusongqing 已提交
2081
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2082

W
wusongqing 已提交
2083
**Parameters**
V
Vaidegi B 已提交
2084

W
wusongqing 已提交
2085 2086 2087
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2088

W
wusongqing 已提交
2089
**Example**
V
Vaidegi B 已提交
2090 2091

```
2092
audioRenderer.drain((err) => {
2093 2094
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2095
    } else {
2096
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2097
    }
2098
});
V
Vaidegi B 已提交
2099 2100
```

2101
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2102

2103
drain(): Promise\<void>
V
Vaidegi B 已提交
2104

2105
Drains the playback buffer. This API uses a promise to return the result.
2106

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

W
wusongqing 已提交
2109
**Return value**
V
Vaidegi B 已提交
2110

W
wusongqing 已提交
2111 2112 2113
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2114

W
wusongqing 已提交
2115
**Example**
V
Vaidegi B 已提交
2116 2117

```
2118 2119 2120 2121 2122
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2123 2124
```

2125
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2126

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

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

W
wusongqing 已提交
2131
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2132

W
wusongqing 已提交
2133
**Parameters**
V
Vaidegi B 已提交
2134

W
wusongqing 已提交
2135 2136 2137
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2138

W
wusongqing 已提交
2139
**Example**
V
Vaidegi B 已提交
2140 2141

```
2142
audioRenderer.stop((err) => {
2143 2144
    if (err) {
        console.error('Renderer stop failed');
V
Vaidegi B 已提交
2145
    } else {
2146
        console.log('Renderer stopped.');
V
Vaidegi B 已提交
2147
    }
2148
});
V
Vaidegi B 已提交
2149 2150
```

2151
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2152

2153
stop(): Promise\<void>
V
Vaidegi B 已提交
2154

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

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

W
wusongqing 已提交
2159
**Return value**
V
Vaidegi B 已提交
2160

W
wusongqing 已提交
2161 2162 2163
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2164

W
wusongqing 已提交
2165
**Example**
V
Vaidegi B 已提交
2166 2167

```
2168 2169 2170 2171 2172
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2173 2174
```

2175
### release<sup>8+</sup>
V
Vaidegi B 已提交
2176

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

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

W
wusongqing 已提交
2181
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2182

W
wusongqing 已提交
2183
**Parameters**
V
Vaidegi B 已提交
2184

W
wusongqing 已提交
2185 2186 2187
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2188

W
wusongqing 已提交
2189
**Example**
V
Vaidegi B 已提交
2190 2191

```
2192
audioRenderer.release((err) => {
2193 2194
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2195
    } else {
2196
        console.log('Renderer released.');
V
Vaidegi B 已提交
2197
    }
2198
});
V
Vaidegi B 已提交
2199 2200
```

2201
### release<sup>8+</sup>
V
Vaidegi B 已提交
2202

2203
release(): Promise\<void>
V
Vaidegi B 已提交
2204

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

W
wusongqing 已提交
2207
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2208

W
wusongqing 已提交
2209
**Return value**
V
Vaidegi B 已提交
2210

W
wusongqing 已提交
2211 2212 2213
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2214

W
wusongqing 已提交
2215
**Example**
V
Vaidegi B 已提交
2216 2217

```
2218 2219 2220 2221 2222
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2223 2224
```

2225
### write<sup>8+</sup>
V
Vaidegi B 已提交
2226

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

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

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

W
wusongqing 已提交
2233
**Parameters**
V
Vaidegi B 已提交
2234

W
wusongqing 已提交
2235 2236 2237 2238
| 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 已提交
2239

W
wusongqing 已提交
2240
**Example**
V
Vaidegi B 已提交
2241 2242

```
2243 2244 2245
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

V
Vaidegi B 已提交
2246 2247 2248
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2249
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2250
    if (writtenbytes < 0) {
2251
        console.error('write failed.');
V
Vaidegi B 已提交
2252 2253 2254
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2255
});
V
Vaidegi B 已提交
2256 2257
```

2258
### write<sup>8+</sup>
V
Vaidegi B 已提交
2259

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

2262
Writes the buffer. This API uses a promise to return the result.
2263

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

W
wusongqing 已提交
2266
**Return value**
V
Vaidegi B 已提交
2267

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

W
wusongqing 已提交
2272
**Example**
V
Vaidegi B 已提交
2273 2274

```
2275 2276 2277 2278
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2279 2280 2281
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2282 2283 2284 2285 2286 2287 2288 2289 2290
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 已提交
2291 2292
```

2293
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2294

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

W
wusongqing 已提交
2297
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 已提交
2298

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

W
wusongqing 已提交
2301
**Parameters**
V
Vaidegi B 已提交
2302

W
wusongqing 已提交
2303 2304 2305
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
2306

W
wusongqing 已提交
2307
**Example**
V
Vaidegi B 已提交
2308 2309

```
2310
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2311
    console.log('Current timestamp: ' + timestamp);
2312
});
V
Vaidegi B 已提交
2313 2314
```

2315
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2316

2317
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2318

W
wusongqing 已提交
2319
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 已提交
2320

W
wusongqing 已提交
2321
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2322

W
wusongqing 已提交
2323
**Return value**
V
Vaidegi B 已提交
2324

W
wusongqing 已提交
2325 2326 2327
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
2328

W
wusongqing 已提交
2329
**Example**
V
Vaidegi B 已提交
2330 2331

```
2332 2333 2334 2335 2336
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2337 2338
```

2339
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2340

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

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

W
wusongqing 已提交
2345
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2346

W
wusongqing 已提交
2347
**Parameters**
V
Vaidegi B 已提交
2348

W
wusongqing 已提交
2349 2350 2351
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
2352

W
wusongqing 已提交
2353
**Example**
V
Vaidegi B 已提交
2354 2355

```
J
jiao_yanlin 已提交
2356
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
V
Vaidegi B 已提交
2357 2358 2359
    if (err) {
        console.error('getBufferSize error');
    }
2360
});
V
Vaidegi B 已提交
2361 2362
```

2363
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2364

2365
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2366

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

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

W
wusongqing 已提交
2371
**Return value**
V
Vaidegi B 已提交
2372

W
wusongqing 已提交
2373 2374 2375
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
2376

W
wusongqing 已提交
2377
**Example**
V
Vaidegi B 已提交
2378 2379

```
J
jiao_yanlin 已提交
2380 2381 2382 2383
var bufferSize;
await audioRenderer.getBufferSize().then(async function (data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
    bufferSize=data;
2384
}).catch((err) => {
J
jiao_yanlin 已提交
2385
    console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
2386
});
V
Vaidegi B 已提交
2387 2388
```

2389
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2390

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

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

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

W
wusongqing 已提交
2397
**Parameters**
2398

W
wusongqing 已提交
2399 2400 2401 2402
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2403

W
wusongqing 已提交
2404
**Example**
V
Vaidegi B 已提交
2405 2406

```
2407
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2408
    if (err) {
2409
        console.error('Failed to set params');
V
Vaidegi B 已提交
2410 2411 2412
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2413
});
V
Vaidegi B 已提交
2414 2415
```

2416
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2417

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

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

W
wusongqing 已提交
2422
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2423

W
wusongqing 已提交
2424
**Parameters**
V
Vaidegi B 已提交
2425

W
wusongqing 已提交
2426 2427 2428
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
V
Vaidegi B 已提交
2429

W
wusongqing 已提交
2430
**Return value**
V
Vaidegi B 已提交
2431

W
wusongqing 已提交
2432 2433 2434
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2435

W
wusongqing 已提交
2436
**Example**
V
Vaidegi B 已提交
2437 2438

```
2439 2440 2441 2442 2443
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2444 2445
```

2446
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2447

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

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

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

W
wusongqing 已提交
2454
**Parameters**
2455

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

W
wusongqing 已提交
2460
**Example**
V
Vaidegi B 已提交
2461 2462

```
2463
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2464
    console.log('getRenderRate: ' + renderrate);
2465
});
V
Vaidegi B 已提交
2466 2467
```

2468
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2469

2470
getRenderRate(): Promise\<AudioRendererRate>
2471

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

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

W
wusongqing 已提交
2476
**Return value**
V
Vaidegi B 已提交
2477

W
wusongqing 已提交
2478 2479 2480
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
2481

W
wusongqing 已提交
2482
**Example**
V
Vaidegi B 已提交
2483 2484

```
2485 2486 2487 2488 2489
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2490 2491
```

W
wusongqing 已提交
2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509
### 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**

```
J
jiao_yanlin 已提交
2510 2511 2512
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
W
wusongqing 已提交
2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
    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) {
J
jiao_yanlin 已提交
2525
        switch (interruptEvent.hintType) {
W
wusongqing 已提交
2526 2527
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
J
jiao_yanlin 已提交
2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540
                await audioRenderer.start().then(async function () {
                    console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
                    started = true;
                }).catch((err) => {
                    console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
                    started = false;
                });
                if (started) {
                    isPlay = true;
                    console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
                } else {
                    console.error('AudioInterruptMusic Renderer start failed');
                }
W
wusongqing 已提交
2541 2542 2543
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
J
jiao_yanlin 已提交
2544 2545 2546 2547 2548 2549 2550 2551
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
W
wusongqing 已提交
2552 2553 2554 2555 2556 2557
                break;
        }
    }
});
```

2558
### on('markReach')<sup>8+</sup>
2559

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

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

W
wusongqing 已提交
2564
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2565

W
wusongqing 已提交
2566
**Parameters**
2567

W
wusongqing 已提交
2568 2569 2570 2571 2572
| 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.                   |
2573

W
wusongqing 已提交
2574
**Example**
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584

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


2585
### off('markReach') <sup>8+</sup>
2586

2587
off(type: 'markReach'): void
2588 2589 2590

Unsubscribes from mark reached events.

W
wusongqing 已提交
2591
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2592

W
wusongqing 已提交
2593
**Parameters**
2594

W
wusongqing 已提交
2595 2596 2597
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **markReach**.|
2598

W
wusongqing 已提交
2599
**Example**
2600 2601 2602 2603 2604

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

2605
### on('periodReach') <sup>8+</sup>
2606

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

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

W
wusongqing 已提交
2611
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2612

W
wusongqing 已提交
2613
**Parameters**
2614

W
wusongqing 已提交
2615 2616 2617 2618 2619
| 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.                     |
2620

W
wusongqing 已提交
2621
**Example**
2622 2623 2624 2625 2626 2627 2628 2629 2630

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

2631
### off('periodReach') <sup>8+</sup>
2632

2633
off(type: 'periodReach'): void
2634 2635 2636

Unsubscribes from period reached events.

W
wusongqing 已提交
2637
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2638

W
wusongqing 已提交
2639
**Parameters**
2640

W
wusongqing 已提交
2641 2642 2643
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
2644

W
wusongqing 已提交
2645
**Example**
2646 2647 2648 2649

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

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

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

2655
Subscribes to state change events.
V
Vaidegi B 已提交
2656

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

W
wusongqing 已提交
2659
**Parameters**
2660

W
wusongqing 已提交
2661 2662 2663 2664
| 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.                           |
2665

W
wusongqing 已提交
2666
**Example**
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677

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

2679
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2680

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

W
wusongqing 已提交
2683
### Attributes
V
Vaidegi B 已提交
2684

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

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

W
wusongqing 已提交
2691
**Example**
V
Vaidegi B 已提交
2692 2693

```
2694
var state = audioCapturer.state;
V
Vaidegi B 已提交
2695 2696
```

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

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

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

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

W
wusongqing 已提交
2705
**Parameters**
V
Vaidegi B 已提交
2706

W
wusongqing 已提交
2707 2708 2709
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
V
Vaidegi B 已提交
2710

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

```
2714
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2715
    if (err) {
2716
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2717
    } else {
2718 2719 2720
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2721
    }
2722
});
V
Vaidegi B 已提交
2723 2724 2725
```


2726
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2727

2728
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2729

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

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

W
wusongqing 已提交
2734
**Return value**
V
Vaidegi B 已提交
2735

W
wusongqing 已提交
2736 2737 2738
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
V
Vaidegi B 已提交
2739

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

```
2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753
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);
2754
});
2755
```
V
Vaidegi B 已提交
2756

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

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

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

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

W
wusongqing 已提交
2765
**Parameters**
V
Vaidegi B 已提交
2766

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

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

```
2774
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2775
    if (err) {
2776
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2777
    } else {
2778 2779 2780 2781 2782
        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 已提交
2783
    }
2784
});
V
Vaidegi B 已提交
2785 2786
```

2787
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2788

2789
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2790

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

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

W
wusongqing 已提交
2795
**Return value**
V
Vaidegi B 已提交
2796

W
wusongqing 已提交
2797 2798 2799
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2800

W
wusongqing 已提交
2801
**Example**
V
Vaidegi B 已提交
2802 2803

```
2804 2805 2806 2807 2808 2809 2810 2811
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);
2812
});
V
Vaidegi B 已提交
2813 2814
```

2815
### start<sup>8+</sup>
V
Vaidegi B 已提交
2816

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

2819
Starts capturing. This API uses an asynchronous callback to return the result.
2820

W
wusongqing 已提交
2821
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2822

W
wusongqing 已提交
2823
**Parameters**
2824

W
wusongqing 已提交
2825 2826 2827
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2828

W
wusongqing 已提交
2829
**Example**
2830 2831

```
2832
audioCapturer.start((err) => {
2833 2834 2835 2836 2837
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2838
});
2839 2840 2841
```


2842
### start<sup>8+</sup>
2843

2844
start(): Promise<void\>
2845

2846
Starts capturing. This API uses a promise to return the result.
2847

W
wusongqing 已提交
2848
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2849

W
wusongqing 已提交
2850
**Return value**
2851

W
wusongqing 已提交
2852 2853 2854
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2855

W
wusongqing 已提交
2856
**Example**
2857 2858 2859

```
audioCapturer.start().then(() => {
2860 2861 2862 2863 2864 2865 2866 2867 2868 2869
    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;
2870 2871 2872
});
```

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

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

2877
Stops capturing. This API uses an asynchronous callback to return the result.
2878

W
wusongqing 已提交
2879
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2880

W
wusongqing 已提交
2881
**Parameters**
2882

W
wusongqing 已提交
2883 2884 2885
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2886

W
wusongqing 已提交
2887
**Example**
2888 2889

```
2890
audioCapturer.stop((err) => {
2891 2892 2893 2894 2895
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
2896
});
2897 2898 2899
```


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

2902
stop(): Promise<void\>
2903

2904
Stops capturing. This API uses a promise to return the result.
2905

W
wusongqing 已提交
2906
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2907

W
wusongqing 已提交
2908
**Return value**
2909

W
wusongqing 已提交
2910 2911 2912
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2913

W
wusongqing 已提交
2914
**Example**
2915 2916 2917

```
audioCapturer.stop().then(() => {
2918 2919 2920 2921 2922 2923 2924 2925 2926
    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;
2927 2928 2929
});
```

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

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

W
wusongqing 已提交
2934
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
2935

W
wusongqing 已提交
2936
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2937

W
wusongqing 已提交
2938
**Parameters**
2939

W
wusongqing 已提交
2940 2941 2942
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
2943

W
wusongqing 已提交
2944
**Example**
2945 2946

```
2947
audioCapturer.release((err) => {
2948 2949 2950 2951 2952
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
2953
});
2954 2955 2956
```


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

2959
release(): Promise<void\>
2960

W
wusongqing 已提交
2961
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
2962

W
wusongqing 已提交
2963
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2964

W
wusongqing 已提交
2965
**Return value**
2966

W
wusongqing 已提交
2967 2968 2969
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2970

W
wusongqing 已提交
2971
**Example**
2972 2973 2974

```
audioCapturer.release().then(() => {
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984
    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
2985 2986 2987 2988
});
```


2989
### read<sup>8+</sup>
2990

2991
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
2992

W
wusongqing 已提交
2993
Reads the buffer. This API uses an asynchronous callback to return the result.
2994

W
wusongqing 已提交
2995
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2996

W
wusongqing 已提交
2997
**Parameters**
2998

W
wusongqing 已提交
2999 3000 3001 3002 3003
| 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.|
3004

W
wusongqing 已提交
3005
**Example**
3006 3007 3008 3009 3010 3011

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
J
jiao_yanlin 已提交
3012
});
3013 3014 3015
```


3016
### read<sup>8+</sup>
3017

3018
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
3019

W
wusongqing 已提交
3020
Reads the buffer. This API uses a promise to return the result.
3021

W
wusongqing 已提交
3022
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3023

W
wusongqing 已提交
3024
**Parameters**
3025

W
wusongqing 已提交
3026 3027 3028 3029
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3030

W
wusongqing 已提交
3031
**Return value**
3032

W
wusongqing 已提交
3033 3034 3035
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3036

W
wusongqing 已提交
3037
**Example**
3038 3039

```
3040 3041 3042 3043
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3044 3045 3046 3047
});
```


3048
### getAudioTime<sup>8+</sup>
3049

3050
getAudioTime(callback: AsyncCallback<number\>): void
3051

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

W
wusongqing 已提交
3054
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3055

W
wusongqing 已提交
3056
**Parameters**
3057

W
wusongqing 已提交
3058 3059 3060
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3061

W
wusongqing 已提交
3062
**Example**
3063 3064

```
3065
audioCapturer.getAudioTime((err, timestamp) => {
3066
    console.log('Current timestamp: ' + timestamp);
3067
});
3068 3069 3070
```


3071
### getAudioTime<sup>8+</sup>
3072

3073
getAudioTime(): Promise<number\>
3074

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

W
wusongqing 已提交
3077
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3078

W
wusongqing 已提交
3079
**Return value**
3080

W
wusongqing 已提交
3081 3082 3083
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3084

W
wusongqing 已提交
3085
**Example**
3086 3087 3088

```
audioCapturer.getAudioTime().then((audioTime) => {
3089 3090 3091
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3092 3093 3094 3095
});
```


3096
### getBufferSize<sup>8+</sup>
3097

3098
getBufferSize(callback: AsyncCallback<number\>): void
3099

3100
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
3101

W
wusongqing 已提交
3102
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3103

W
wusongqing 已提交
3104
**Parameters**
3105

W
wusongqing 已提交
3106 3107 3108
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3109

W
wusongqing 已提交
3110
**Example**
3111 3112

```
3113
audioCapturer.getBufferSize((err, bufferSize) => {
3114 3115
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3116 3117 3118 3119 3120
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3121 3122 3123 3124
    }
});
```

W
wusongqing 已提交
3125

3126
### getBufferSize<sup>8+</sup>
3127

3128
getBufferSize(): Promise<number\>
3129

3130
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
3131

W
wusongqing 已提交
3132
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3133

W
wusongqing 已提交
3134
**Return value**
3135

W
wusongqing 已提交
3136 3137 3138
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3139

W
wusongqing 已提交
3140
**Example**
3141 3142 3143

```
audioCapturer.getBufferSize().then((bufferSize) => {
3144 3145 3146 3147 3148 3149 3150 3151
    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);
        });
    }
3152 3153 3154
});
```

W
wusongqing 已提交
3155

3156
### on('markReach')<sup>8+</sup>
3157

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

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

W
wusongqing 已提交
3162
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3163

W
wusongqing 已提交
3164
**Parameters**
3165

W
wusongqing 已提交
3166 3167 3168 3169 3170
| 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.|
3171

W
wusongqing 已提交
3172
**Example**
3173 3174 3175 3176 3177 3178 3179 3180 3181

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

3182
### off('markReach')<sup>8+</sup>
3183

3184
off(type: 'markReach'): void
3185

W
wusongqing 已提交
3186
Unsubscribes from mark reached events.
3187

W
wusongqing 已提交
3188
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3189

W
wusongqing 已提交
3190
**Parameters**
3191

W
wusongqing 已提交
3192 3193 3194
| 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.|
3195

W
wusongqing 已提交
3196
**Example**
3197 3198 3199 3200 3201

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

3202
### on('periodReach')<sup>8+</sup>
3203

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

W
wusongqing 已提交
3206
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3207

W
wusongqing 已提交
3208
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3209

W
wusongqing 已提交
3210
**Parameters**
3211

W
wusongqing 已提交
3212 3213 3214
| 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 已提交
3215
| frame    | number                   | Yes  | Period during which frame capturing is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3216
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3217

W
wusongqing 已提交
3218
**Example**
3219 3220 3221 3222 3223 3224 3225 3226 3227

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

3228
### off('periodReach')<sup>8+</sup>
3229

3230
off(type: 'periodReach'): void
3231 3232 3233

Unsubscribes from period reached events.

W
wusongqing 已提交
3234
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3235

W
wusongqing 已提交
3236
**Parameters**
3237

W
wusongqing 已提交
3238 3239 3240
| 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.|
3241

W
wusongqing 已提交
3242
**Example**
3243 3244 3245 3246 3247 3248 3249 3250

```
audioCapturer.off('periodReach')
```

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

on(type: 'stateChange', callback: Callback<AudioState\>): void
3251

3252
Subscribes to state change events.
3253

W
wusongqing 已提交
3254
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3255

W
wusongqing 已提交
3256
**Parameters**
3257

W
wusongqing 已提交
3258 3259 3260 3261
| 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.                           |
3262

W
wusongqing 已提交
3263
**Example**
3264 3265

```
3266 3267 3268 3269 3270 3271 3272 3273
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");
    }
});
3274
```