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

3 4
> **NOTE**
> 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.
V
Vaidegi B 已提交
5

6 7 8 9 10 11 12
This module provides the following common audio-related functions:

- [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.

## Modules to Import
W
wusongqing 已提交
13 14 15 16 17

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

18
## audio.getAudioManager
V
Vaidegi B 已提交
19

20
getAudioManager(): AudioManager
21

22
Obtains an **AudioManager** instance.
W
wusongqing 已提交
23

24
**System capability:** SystemCapability.Multimedia.Audio.Core
25

26
**Return value:**
W
wusongqing 已提交
27

28 29 30
| Type                          | Description          |
| ----------------------------- | -------------------- |
| [AudioManager](#audiomanager) | AudioManager object. |
W
wusongqing 已提交
31

32
**Example:**
W
wusongqing 已提交
33 34 35 36 37

```
var audioManager = audio.getAudioManager();
```

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

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

42
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the renderer instance.
43

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

46 47 48 49 50
**Parameters:**
| Name       | Type                                            | Mandatory | Description                                          |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
| options    | [AudioRendererOptions](#audiorendereroptions8)  | Yes       | Renderer configurations.                             |
| callback   | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes       | Callback used to return the audio renderer instance. |
51

52
**Example:**
53 54

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

86
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer>
V
Vaidegi B 已提交
87

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

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

92 93 94 95
**Parameters:**
| Name       | Type                                           | Mandatory | Description                 |
| :--------- | :--------------------------------------------- | :-------- | :---------------------------|
| options    | [AudioRendererOptions](#audiorendereroptions8) | Yes       | Renderer configurations.    |
V
Vaidegi B 已提交
96

97
**Return value:**
V
Vaidegi B 已提交
98

99 100 101
| Type                                      | Description                                         |
| ----------------------------------------- | --------------------------------------------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. |
V
Vaidegi B 已提交
102

103
**Example:**
V
Vaidegi B 已提交
104 105

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

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
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
}

126 127 128 129 130 131 132
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 已提交
133 134
```

135
## audio.createAudioCapturer<sup>8+</sup>
136

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

139
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the capturer instance.
140

141
**System capability:** SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
142

143 144 145
**Parameters:**
| Name       | Type                                            | Mandatory | Description                                          |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- |
G
Geevarghese V K 已提交
146
| options    | [AudioCapturerOptions](#audiocaptureroptions8)   | Yes       | Capturer configurations.                             |
147
| callback   | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes       | Callback used to return the audio capturer instance. |
V
Vaidegi B 已提交
148

149
**Example:**
150 151

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

181
## audio.createAudioCapturer<sup>8+</sup>
182

183
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
184

185
Obtains an **AudioCapturer** instance. This API uses a promise to return the capturer instance.
186

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

189 190 191
**Parameters:**
| Name       | Type                                          | Mandatory | Description                 |
| :--------- | :-------------------------------------------- | :-------- | :-------------------------- |
G
Geevarghese V K 已提交
192
| options    | [AudioCapturerOptions](#audiocaptureroptions8) | Yes       | Capturer configurations.    |
193

194
**Return value:**
V
Vaidegi B 已提交
195

196 197 198
| Type                                      | Description                                         |
| ----------------------------------------- | --------------------------------------------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. |
V
Vaidegi B 已提交
199

200
**Example:**
V
Vaidegi B 已提交
201 202

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

205 206 207 208 209 210 211 212 213 214 215 216 217
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 = {
218 219
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
220
}
V
Vaidegi B 已提交
221

222
var audioCapturer;
R
rahul 已提交
223
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
224 225 226 227 228
    audioCapturer = data;
    console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioCapturer Created : ERROR : '+err.message);
});
229
```
V
Vaidegi B 已提交
230

231
## AudioVolumeType
W
wusongqing 已提交
232 233 234

Enumerates audio stream types.

235
**System capability:** SystemCapability.Multimedia.Audio.Volume
Z
zengyawen 已提交
236

237 238 239 240 241 242
| 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. |
V
Vaidegi B 已提交
243

244
## DeviceFlag
W
wusongqing 已提交
245 246 247

Enumerates audio device flags.

248
**System capability:** SystemCapability.Multimedia.Audio.Device
Z
zengyawen 已提交
249

250 251 252 253 254
| 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 已提交
255

256 257

## DeviceRole
W
wusongqing 已提交
258 259 260

Enumerates audio device roles.

261
**System capability:** SystemCapability.Multimedia.Audio.Device
Z
zengyawen 已提交
262

263 264 265 266
| Name          | Default Value | Description  |
| ------------- | ------------- | ------------ |
| INPUT_DEVICE  | 1             | Input role.  |
| OUTPUT_DEVICE | 2             | Output role. |
V
Vaidegi B 已提交
267

268
## DeviceType
W
wusongqing 已提交
269 270 271

Enumerates audio device types.

272 273 274 275 276 277 278 279 280 281 282 283 284
**System capability:** SystemCapability.Multimedia.Audio.Device

| Name             | Default Value | Description                                                              |
| ---------------- | ------------- | ------------------------------------------------------------------------ |
| INVALID          | 0             | Invalid device.                                                          |
| EARPIECE         | 1             | Earpiece.                                                                |
| SPEAKER          | 2             | Speaker.                                                                 |
| WIRED_HEADSET    | 3             | Wired headset.                                                           |
| 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 已提交
285

W
wusongqing 已提交
286
## ActiveDeviceType
V
Vaidegi B 已提交
287

W
wusongqing 已提交
288 289
Enumerates the active device types.

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

292 293 294 295
| Name          | Default Value | Description                                                            |
| ------------- | ------------- | ---------------------------------------------------------------------- |
| SPEAKER       | 2             | Speaker.                                                               |
| BLUETOOTH_SCO | 7             | Bluetooth device using the SCO links.                                  |
W
wusongqing 已提交
296 297

## AudioRingMode
W
wusongqing 已提交
298 299 300

Enumerates ringer modes.

301
**System capability:** SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
302

303 304 305 306 307 308 309
| Name                | Default Value | Description      |
| ------------------- | ------------- | ---------------- |
| RINGER_MODE_SILENT  | 0             | Silent mode.     |
| RINGER_MODE_VIBRATE | 1             | Vibration mode.  |
| RINGER_MODE_NORMAL  | 2             | Normal mode.     |

## AudioSampleFormat<sup>8+</sup>
V
Vaidegi B 已提交
310 311 312

Enumerates the audio sample formats.

313 314 315 316 317 318 319 320 321 322 323
**System capability:** SystemCapability.Multimedia.Audio.Core

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

## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
324 325 326

Enumerates the audio channels.

327 328 329 330 331 332 333 334
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name      | Default Value | Description      |
| :-------- | :------------ | :--------------- |
| CHANNEL_1 | 0x1 << 0      | Channel count 1. |
| CHANNEL_2 | 0x1 << 1      | Channel count 2. |

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
335 336 337

Enumerates the audio sampling rates.

338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name              | Default Value | Description          |
| :---------------- | :------------ | :------------------- |
| SAMPLE_RATE_8000  | 8000          | Sampling rate 8000.  |
| SAMPLE_RATE_11025 | 11025         | Sampling rate 11025. |
| SAMPLE_RATE_12000 | 12000         | Sampling rate 12000. |
| SAMPLE_RATE_16000 | 16000         | Sampling rate 16000. |
| SAMPLE_RATE_22050 | 22050         | Sampling rate 22050. |
| SAMPLE_RATE_24000 | 24000         | Sampling rate 24000. |
| SAMPLE_RATE_32000 | 32000         | Sampling rate 32000. |
| SAMPLE_RATE_44100 | 44100         | Sampling rate 44100. |
| SAMPLE_RATE_48000 | 48000         | Sampling rate 48000. |
| SAMPLE_RATE_64000 | 64000         | Sampling rate 64000. |
| SAMPLE_RATE_96000 | 96000         | Sampling rate 96000. |


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

V
Vaidegi B 已提交
357 358
Enumerates the audio encoding types.

359 360 361 362 363 364
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name                  | Default Value  | Description       |
| :-------------------- | :------------- | :---------------- |
| ENCODING_TYPE_INVALID | -1             | Invalid.          |
| ENCODING_TYPE_RAW     |  0             | PCM encoding.     |
V
Vaidegi B 已提交
365 366


367 368
## ContentType

V
Vaidegi B 已提交
369 370
Enumerates the content types.

371 372 373 374 375 376 377 378 379 380
**System capability:** SystemCapability.Multimedia.Audio.Core

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


383 384
## StreamUsage

V
Vaidegi B 已提交
385 386
Enumerates the stream usage.

387 388 389 390 391 392 393 394
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name                               | Default Value | Description                       |
| :--------------------------------- | :------------ | :-------------------------------- |
| STREAM_USAGE_UNKNOWN               | 0             | Unknown usage.                    |
| STREAM_USAGE_MEDIA                 | 1             | Media usage.                      |
| STREAM_USAGE_VOICE_COMMUNICATION   | 2             | Voice communication usage.        |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6             | Notification or ringtone usage.   |
V
Vaidegi B 已提交
395 396


397 398
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
399 400
Enumerates the audio states.

401 402 403 404 405 406 407 408 409 410 411
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name           | Default Value | Description                  |
| :------------- | :------------ | :--------------------------- |
| STATE_INVALID  | -1            | Invalid state.               |
| STATE_NEW      | 0             | Creating new instance state. |
| STATE_PREPARED | 1             | Prepared state.              |
| STATE_RUNNING  | 2             | Running state.               |
| STATE_STOPPED  | 3             | Stopped state.               |
| STATE_RELEASED | 4             | Released state.              |
| STATE_PAUSED   | 5             | Paused state.                |
V
Vaidegi B 已提交
412 413


414 415
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
416 417
Enumerates the audio renderer rates.

418 419 420 421 422 423 424
**System capability:** SystemCapability.Multimedia.Audio.Renderer

| 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 已提交
425

426
## InterruptType
V
Vaidegi B 已提交
427 428 429

Enumerates the interrupt types.

430
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
431

432 433 434 435 436 437 438
| Name                 | Default Value | Description                          |
| :------------------- | :------------ | :----------------------------------- |
| INTERRUPT_TYPE_BEGIN | 1             | Audio playback interruption started. |
| INTERRUPT_TYPE_END   | 2             | Audio playback interruption ended.   |


## InterruptForceType<sup>9+</sup>
V
Vaidegi B 已提交
439 440 441

Enumerates the interrupt force types.

442
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
443

444 445 446 447 448 449
| Name            | Default Value | Description                                |
| :-------------- | :------------ | :----------------------------------------- |
| INTERRUPT_FORCE | 0             | Forced action taken by system.             |
| INTERRUPT_SHARE | 1             | App can choose to take action or ignore.   |

## InterruptHint
V
Vaidegi B 已提交
450 451 452

Enumerates the interrupt hints.

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
**System capability:** SystemCapability.Multimedia.Audio.Renderer

| 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.         |
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5             | Unducked the playback.       |

## InterruptActionType

Enumerates the interrupt event return types.

This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

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

| Name           | Default Value | Description                               |
| :------------- | :------------ | :---------------------------------------- |
| TYPE_ACTIVATED | 0             | Audio interrupt activated.                |
| TYPE_INTERRUPT | 1             | Audio interrupted.                        |

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

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

481
**System capability:** SystemCapability.Multimedia.Audio.Core
482

483 484 485 486 487 488 489 490
| Name          | Type                                      | Mandatory | Description           |
| :------------ | :---------------------------------------- | :-------- | :-------------------- |
| samplingRate  | [AudioSamplingRate](#audiosamplingrate8)  | Yes       | Sampling rate.        |
| channels      | [AudioChannel](#audiochannel8)            | Yes       | Audio channels.       |
| sampleFormat  | [AudioSampleFormat](#audiosampleformat8)  | Yes       | Audio sample format.  |
| encodingType  | [AudioEncodingType](#audioencodingtype8)  | Yes       | Audio encoding type.  |

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

Describes audio renderer information.

494 495 496 497 498 499 500
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name          | Type                        | Mandatory | Description           |
| :------------ | :-------------------------- | :-------- | :-------------------- |
| contentType   | [ContentType](#contenttype) | Yes       | Content type.         |
| usage         | [StreamUsage](#streamusage) | Yes       | Stream usage.         |
| rendererFlags | number                      | Yes       | Audio renderer flags. |
V
Vaidegi B 已提交
501

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

504 505
Describes audio renderer configuration options.

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

508 509 510 511 512
| Name          | Type                                      | Mandatory | Description           |
| :------------ | :-----------------------------------------| :-------- | :-------------------- |
| streamInfo    | [AudioStreamInfo](#audiostreaminfo8)      | Yes       | Stream information.   |
| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8)  | Yes       | Renderer information. |

G
Geevarghese V K 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>

Describes audio capturer information.

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

| Name            | Type                       | Mandatory | Description           |
| :---------------| :------------------------- | :-------- | :-------------------- |
| source          | [SourceType](#sourcetype)  | Yes       | Audio source type.    |
| capturerFlags   | number                     | Yes       | Audio capturer flags. |

## AudioCapturerOptions<sup>8+</sup>

Describes audio capturer configuration options.

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

| Name          | Type                                      | Mandatory | Description           |
| :------------ | :-----------------------------------------| :-------- | :-------------------- |
| streamInfo    | [AudioStreamInfo](#audiostreaminfo8)      | Yes       | Stream information.   |
| capturerInfo  | [AudioCapturerInfo](#audiocapturerinfo8)  | Yes       | Capturer information. |

535
## InterruptEvent<sup>9+</sup>
V
Vaidegi B 已提交
536 537 538

Describes the interrupt event received by the app when playback is interrupted.

539 540 541 542 543 544 545 546 547
**System capability:** SystemCapability.Multimedia.Audio.Renderer

| Name      | Type                                          | Mandatory | Description                                                       |
| :-------- | :-------------------------------------------- | :-------- | :---------------------------------------------------------------- |
| eventType | [InterruptType](#interrupttype)               | Yes       | Whether the interruption has started or finished.                 |
| forceType | [InterruptForceType](#interruptforcetype9)    | Yes       | Whether the action is taken by system or to be taken by the app.  |
| hintType  | [InterruptHint](#interrupthint)               | Yes       | Type of action.                                                   |

## AudioInterrupt
548

549
The parameters passed in by the audio listener event.
V
Vaidegi B 已提交
550

551
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
V
Vaidegi B 已提交
552

553
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
554

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
| Name          | Type                                      | Mandatory | Description           |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage     | [StreamUsage](#streamusage) | Yes   | Audio stream usage type.                                             |
| contentType     | [ContentType](#contenttype) | Yes   | Audio interrupt media type.                                           |
| pauseWhenDucked | boolean                     | Yes   | Whether audio playback can be paused when audio is interrupted (true means audio playback can be paused during audio interruptions and false means the opposite). |

## InterruptAction

Callback method for the audio interrupt or audio interrupt activated event.

This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

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

| Name       | Type                                        | Mandatory | Description                                                                                                                                            |
| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes       | Event return type. TYPE_ACTIVATED is the audio interrupt activated event, and TYPE_INTERRUPT is the audio interrupt event.                                         |
| type       | [InterruptType](#interrupttype)             | No        | Interrupt event type.                                                                                                                                  |
G
Geevarghese V K 已提交
573
| hint       | [InterruptHint](#interrupthint)              | No        | Interrupt event prompts.                                                                                                                               |
574 575 576
| activated  | boolean                                     | No        | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails.  |

## VolumeEvent<sup>8+</sup>
V
Vaidegi B 已提交
577 578
Describes the volume event received by the app when the volume is changed.

579
This is a system API and cannot be called by third-party applications.
580

581
**System capability:** SystemCapability.Multimedia.Audio.Volume
V
Vaidegi B 已提交
582

583 584 585 586 587
| Name       | Type                                | Mandatory | Description                              |
| :--------- | :---------------------------------- | :-------- | :--------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Volume type of the current stream.       |
| volume     | number                              | Yes       | Volume level.                            |
| updateUi   | boolean                             | Yes       | Whether to show the volume change in UI. |
V
Vaidegi B 已提交
588

589
## DeviceChangeAction
590

591 592
Describes the device change type and device information.

593
**System capability:** SystemCapability.Multimedia.Audio.Device
594

595 596
| Name                | Type                                              | Mandatory | Description         |
| :------------------ | :------------------------------------------------ | :-------- | :------------------ |
G
Geevarghese V K 已提交
597 598
| type                | [DeviceChangeType](#devicechangetype)             | Yes       | Device change type. |
| deviceDescriptors   | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes       | Device information. |
599 600 601


## DeviceChangeType
602

603 604
Enumerates device change types.

605 606 607 608 609 610
**System capability:** SystemCapability.Multimedia.Audio.Device

| Name                   | Default Value | Description           |
| :--------------------- | :------------ | :-------------------- |
| CONNECT                | 0             | Device connection.    |
| DISCONNECT             | 1             | Device disconnection. |
611 612

## SourceType<sup>8+</sup><a name="sourcetype"></a>
613

614 615
Enumerates source types.

616 617 618 619 620 621 622
**System capability:** SystemCapability.Multimedia.Audio.Core

| Name                                                                                                                                                         | Default Value | Description                      |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- |
| SOURCE_TYPE_INVALID                                                                                                                                          | -1            | Invalid source type.             |
| SOURCE_TYPE_MIC                                                                                                                                              | 0             | Mic source type.                 |
| SOURCE_TYPE_VOICE_COMMUNICATION(This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR) | 7             | Voice communication source type. |
623 624 625


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

627 628
Enumerates audio scenes.

629 630 631 632 633 634 635 636
**System capability:** SystemCapability.Multimedia.Audio.Communication

| Name                                                                                  | Default Value | Description             |
| :------------------------------------------------------------------------------------ | :------------ | :---------------------- |
| AUDIO_SCENE_DEFAULT                                                                   | 0             | Default audio scene.    |
| AUDIO_SCENE_RINGING(system API, not supported by third-party applications)       | 1             | Ringing audio scene.    |
| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications)    | 2             | Phone call audio scene. |
| AUDIO_SCENE_VOICE_CHAT                                                                | 3             | Voice chat audio scene. |
W
wusongqing 已提交
637

638
## AudioManager
W
wusongqing 已提交
639

640
Implements audio volume and audio device management. Before calling the interface of AudioManager, you need to create an instance through [getAudioManager](#audiogetaudiomanager).
W
wusongqing 已提交
641

642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
### setVolume

setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void\>\): void

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

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

**Parameters:**

| Name       | Type                                | Mandatory | Description                                                                              |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Volume stream type.                                                                      |
| volume     | number                              | Yes       | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. |
| callback   | AsyncCallback<void\>                | Yes       | Callback used to return the result.                                                      |

**Example:**
W
wusongqing 已提交
659 660

```
661 662 663 664 665 666
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.');
667
});
W
wusongqing 已提交
668
```
669
### setVolume
W
wusongqing 已提交
670

671 672 673 674 675
setVolume\(volumeType: AudioVolumeType, volume: number\): Promise<void\>

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

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

677 678 679 680 681 682 683 684 685 686 687 688 689 690
**Parameters:**

| Name       | Type                                | Mandatory | Description                                                                              |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Volume stream type.                                                                      |
| volume     | number                              | Yes       | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. |

**Return value:**

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

**Example:**
W
wusongqing 已提交
691 692

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

### getVolume
W
wusongqing 已提交
699

700
getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void
W
wusongqing 已提交
701

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

704 705 706 707 708 709 710 711 712 713
**System capability:** SystemCapability.Multimedia.Audio.Volume

**Parameters:**

| Name       | Type                                | Mandatory | Description                          |
| ---------- | ----------------------------------- | --------- | ------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                   |
| callback   | AsyncCallback<number>               | Yes       | Callback used to return the volume.  |

**Example:**
W
wusongqing 已提交
714 715 716 717

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

V
Vaidegi B 已提交
725

726
### getVolume
V
Vaidegi B 已提交
727

728
getVolume\(volumeType: AudioVolumeType\): Promise<number\>
W
wusongqing 已提交
729

730
Obtains the volume of a stream. This API uses a promise to return the query result.
W
wusongqing 已提交
731

732
**System capability:** SystemCapability.Multimedia.Audio.Volume
733

734
**Parameters:**
W
wusongqing 已提交
735

736 737 738
| Name       | Type                                | Mandatory | Description                          |
| ---------- | ----------------------------------- | --------- | ------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                   |
W
wusongqing 已提交
739

740 741 742 743 744
**Return value:**

| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<number>       | Promise used to return the result.  |
W
wusongqing 已提交
745

746
**Example:**
W
wusongqing 已提交
747 748

```
749
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
750
    console.log('Promise returned to indicate that the volume is obtained.' + value);
751 752 753 754 755 756 757 758
});
```

### getMinVolume

getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void

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

760
**System capability:** SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
761

762
**Parameters:**
W
wusongqing 已提交
763

764 765 766 767 768 769
| Name       | Type                                | Mandatory | Description                          |
| ---------- | ----------------------------------- | --------- | ------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                   |
| callback   | AsyncCallback<number>               | Yes       | Callback used to return the volume.  |

**Example:**
W
wusongqing 已提交
770 771 772 773 774

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

V
Vaidegi B 已提交
781

782
### getMinVolume
V
Vaidegi B 已提交
783 784

getMinVolume\(volumeType: AudioVolumeType\): Promise<number\><a name="section41556389511"></a>
W
wusongqing 已提交
785

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

788
**System capability:** SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
789

790 791 792 793 794
**Parameters:**

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

796
**Return value:**
W
wusongqing 已提交
797

798 799 800
| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<number>     | Promise used to return the result.  |
W
wusongqing 已提交
801

802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
**Example:**

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

### getMaxVolume

getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void

Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the query result.

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

**Parameters:**

| Name       | Type                                | Mandatory | Description                          |
| ---------- | ----------------------------------- | --------- | ------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                   |
| callback   | AsyncCallback<number>               | Yes       | Callback used to return the volume.  |

**Example:**
W
wusongqing 已提交
826 827 828 829 830 831 832 833

```
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);
834
});
W
wusongqing 已提交
835 836
```

V
Vaidegi B 已提交
837

838
### getMaxVolume
V
Vaidegi B 已提交
839

840
getMaxVolume\(volumeType: AudioVolumeType\): Promise<number\>
W
wusongqing 已提交
841

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

844
**System capability:** SystemCapability.Multimedia.Audio.Volume
845

846
**Parameters:**
W
wusongqing 已提交
847

848 849 850
| Name       | Type                                | Mandatory | Description                          |
| ---------- | ----------------------------------- | --------- | ------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                   |
W
wusongqing 已提交
851

852 853 854 855 856
**Return value:**

| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<number>       | Promise used to return the result.  |
W
wusongqing 已提交
857

858
**Example:**
W
wusongqing 已提交
859 860

```
861
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
W
wusongqing 已提交
862
    console.log('Promised returned to indicate that the maximum volume is obtained.');
863
});
W
wusongqing 已提交
864 865
```

866
### mute
V
Vaidegi B 已提交
867

W
wusongqing 已提交
868
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void
W
wusongqing 已提交
869

870
Mutes a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
871

872
**System capability:** SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
873

874
**Parameters:**
W
wusongqing 已提交
875

876 877 878 879 880 881 882
| 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<number>               | Yes       | Callback used to return the volume.                                                        |

**Example:**
W
wusongqing 已提交
883 884 885 886 887

```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
    if (err) {
        console.error('Failed to mute the stream. ${err.message}');
888
        return;
W
wusongqing 已提交
889 890
    }
    console.log('Callback invoked to indicate that the stream is muted.');
891
});
W
wusongqing 已提交
892 893 894
```


895
### mute
V
Vaidegi B 已提交
896

W
wusongqing 已提交
897
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\>
V
Vaidegi B 已提交
898

899
Mutes a stream. This API uses a promise to return the result.
W
wusongqing 已提交
900

901 902 903 904 905 906 907 908
**System capability:** SystemCapability.Multimedia.Audio.Volume

**Parameters:**

| 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. |
W
wusongqing 已提交
909

910 911 912 913 914 915 916
**Return value:**

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

**Example:**
W
wusongqing 已提交
917 918

```
919
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
W
wusongqing 已提交
920
    console.log('Promise returned to indicate that the stream is muted.');
921
});
W
wusongqing 已提交
922 923
```

V
Vaidegi B 已提交
924

925
### isMute
V
Vaidegi B 已提交
926

W
wusongqing 已提交
927
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void
W
wusongqing 已提交
928

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

931
**System capability:** SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
932

933
**Parameters:**
W
wusongqing 已提交
934

935 936 937 938 939 940
| Name       | Type                                | Mandatory | Description                                                                                                                         |
| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                                                                                                  |
| callback   | AsyncCallback<boolean>               | 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.|

**Example:**
W
wusongqing 已提交
941 942 943 944

```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
945 946
       console.error('Failed to obtain the mute status. ${err.message}');
       return;
W
wusongqing 已提交
947 948
   }
   console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
949
});
W
wusongqing 已提交
950 951 952
```


953
### isMute
V
Vaidegi B 已提交
954

W
wusongqing 已提交
955
isMute\(volumeType: AudioVolumeType\): Promise<boolean\>
V
Vaidegi B 已提交
956

957
Checks whether a stream is muted. This API uses a promise to return the result.
W
wusongqing 已提交
958

959 960 961
**System capability:** SystemCapability.Multimedia.Audio.Volume

**Parameters:**
W
wusongqing 已提交
962

963 964 965 966 967 968 969 970 971 972 973
| Name       | Type                                | Mandatory | Description         |
| ---------- | ----------------------------------- | --------- | ------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.  |

**Return value:**

| Type                | Description                                                                                                                         |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Promise<boolean>    | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.  |

**Example:**
W
wusongqing 已提交
974 975

```
976
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
977
    console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
978
});
W
wusongqing 已提交
979 980
```

981
### isActive
V
Vaidegi B 已提交
982

W
wusongqing 已提交
983
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\)
W
wusongqing 已提交
984

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

987
**System capability:** SystemCapability.Multimedia.Audio.Volume
W
wusongqing 已提交
988

989
**Parameters:**
W
wusongqing 已提交
990

991 992 993 994 995 996
| Name       | Type                                | Mandatory | Description                                                                                                                           |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                                                                                                    |
| callback   | AsyncCallback<boolean>              | 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.|

**Example:**
W
wusongqing 已提交
997 998 999 1000 1001

```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the active status of the stream. ${err.message}');
1002
        return;
W
wusongqing 已提交
1003 1004
    }
    console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
1005
});
W
wusongqing 已提交
1006 1007
```

V
Vaidegi B 已提交
1008

1009
### isActive
V
Vaidegi B 已提交
1010

W
wusongqing 已提交
1011
isActive\(volumeType: AudioVolumeType\): Promise<boolean\>
W
wusongqing 已提交
1012

1013
Checks whether a stream is active. This API uses a promise to return the query result.
W
wusongqing 已提交
1014

1015 1016 1017 1018 1019 1020 1021
**System capability:** SystemCapability.Multimedia.Audio.Volume

**Parameters:**

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

1023 1024 1025 1026 1027 1028 1029
**Return value:**

| Type                | Description                                                                                                                               |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Promise<boolean>       | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.  |

**Example:**
W
wusongqing 已提交
1030 1031

```
1032
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
1033
    console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
1034
});
W
wusongqing 已提交
1035 1036 1037
```


1038
### setRingerMode
V
Vaidegi B 已提交
1039

W
wusongqing 已提交
1040
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void
V
Vaidegi B 已提交
1041

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

1044
**System capability:** SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1045

1046
**Parameters:**
W
wusongqing 已提交
1047

1048 1049 1050 1051 1052 1053
| Name       | Type                                | Mandatory | Description                         |
| ---------- | ----------------------------------- | --------- | ----------------------------------- |
| mode       | [AudioRingMode](#audioringmode)     | Yes       | Ringer mode.                        |
| callback   | AsyncCallback<void>                 | Yes       | Callback used to return the result. |

**Example:**
W
wusongqing 已提交
1054 1055 1056 1057 1058 1059 1060 1061

```
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.');
1062
});
W
wusongqing 已提交
1063 1064 1065
```


1066
### setRingerMode
V
Vaidegi B 已提交
1067

W
wusongqing 已提交
1068
setRingerMode\(mode: AudioRingMode\): Promise<void\>
V
Vaidegi B 已提交
1069

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

1072 1073 1074
**System capability:** SystemCapability.Multimedia.Audio.Communication

**Parameters:**
W
wusongqing 已提交
1075

1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
| Name       | Type                                | Mandatory | Description                         |
| ---------- | ----------------------------------- | --------- | ----------------------------------- |
| mode       | [AudioRingMode](#audioringmode)     | Yes       | Ringer mode.                        |

**Return value:**

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

**Example:**
W
wusongqing 已提交
1087 1088

```
1089
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
W
wusongqing 已提交
1090
    console.log('Promise returned to indicate a successful setting of the ringer mode.');
1091
});
W
wusongqing 已提交
1092 1093
```

V
Vaidegi B 已提交
1094

1095
### getRingerMode
V
Vaidegi B 已提交
1096

W
wusongqing 已提交
1097
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void
W
wusongqing 已提交
1098

1099 1100 1101
Obtains the ringer mode. This API uses an asynchronous callback to return the query result.

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

1103
**Parameters:**
W
wusongqing 已提交
1104

1105 1106 1107
| Name       | Type                                            | Mandatory | Description                              |
| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- |
| callback   | AsyncCallback<[AudioRingMode](#audioringmode)>  | Yes       | Callback used to return the ringer mode. |
W
wusongqing 已提交
1108

1109
**Example:**
W
wusongqing 已提交
1110 1111 1112 1113

```
audioManager.getRingerMode((err, value) => {
   if (err) {
1114 1115
       console.error('Failed to obtain the ringer mode.​ ${err.message}');
       return;
W
wusongqing 已提交
1116 1117
   }
   console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
1118
});
W
wusongqing 已提交
1119 1120
```

V
Vaidegi B 已提交
1121

1122
### getRingerMode
V
Vaidegi B 已提交
1123

W
wusongqing 已提交
1124
getRingerMode\(\): Promise<AudioRingMode\>
W
wusongqing 已提交
1125

1126
Obtains the ringer mode. This API uses a promise to return the query result.
W
wusongqing 已提交
1127

1128
**System capability:** SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1129

1130
**Return value:**
W
wusongqing 已提交
1131

1132 1133 1134
| Type                                           | Description                             |
| ---------------------------------------------- | --------------------------------------- |
| Promise<[AudioRingMode](#audioringmode)>       | Promise used to return the ringer mode. |
W
wusongqing 已提交
1135

1136
**Example:**
W
wusongqing 已提交
1137 1138

```
1139
audioManager.getRingerMode().then((value) => {
W
wusongqing 已提交
1140
    console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
1141
});
W
wusongqing 已提交
1142 1143 1144
```


1145
### setAudioParameter
V
Vaidegi B 已提交
1146

W
wusongqing 已提交
1147
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void
V
Vaidegi B 已提交
1148

1149 1150 1151
Sets an audio parameter. This API uses an asynchronous callback to return the result.

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

1153
**Parameters:**
W
wusongqing 已提交
1154

1155 1156 1157 1158 1159
| 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<void>   | Yes       | Callback used to return the result.   |
W
wusongqing 已提交
1160

1161
**Example:**
W
wusongqing 已提交
1162 1163 1164 1165 1166

```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
1167
        return;
W
wusongqing 已提交
1168 1169
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
1170
});
W
wusongqing 已提交
1171 1172 1173
```


1174
### setAudioParameter
V
Vaidegi B 已提交
1175

W
wusongqing 已提交
1176
setAudioParameter\(key: string, value: string\): Promise<void\>
V
Vaidegi B 已提交
1177

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

1180 1181 1182
**System capability:** SystemCapability.Multimedia.Audio.Core

**Parameters:**
W
wusongqing 已提交
1183

1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
| Name      | Type                  | Mandatory | Description                           |
| --------- | ----------------------| --------- | ------------------------------------- |
| key       | string                | Yes       | Key of the audio parameter to set.    |
| value     | string                | Yes       | Value of the audio parameter to set.  |

**Return value:**

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

**Example:**
W
wusongqing 已提交
1196 1197

```
1198
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
W
wusongqing 已提交
1199
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1200
});
W
wusongqing 已提交
1201 1202
```

V
Vaidegi B 已提交
1203

1204
### getAudioParameter
V
Vaidegi B 已提交
1205

W
wusongqing 已提交
1206
getAudioParameter\(key: string, callback: AsyncCallback<string\>\)
W
wusongqing 已提交
1207

1208 1209 1210
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the query result.

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

1212
**Parameters:**
W
wusongqing 已提交
1213

1214 1215 1216 1217
| Name      | Type                  | Mandatory | Description                                                |
| --------- | ----------------------| --------- | ---------------------------------------------------------- |
| key       | string                | Yes       | Key of the audio parameter whose value is to be obtained.  |
| callback  | AsyncCallback<string> | Yes       | Callback used to return the value of the audio parameter.  |
W
wusongqing 已提交
1218

1219
**Example:**
W
wusongqing 已提交
1220 1221 1222 1223 1224

```
audioManager.getAudioParameter('PBits per sample', (err, value) => {
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1225
        return;
W
wusongqing 已提交
1226 1227
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1228
});
W
wusongqing 已提交
1229 1230
```

V
Vaidegi B 已提交
1231

1232
### getAudioParameter
V
Vaidegi B 已提交
1233

W
wusongqing 已提交
1234
getAudioParameter\(key: string\): Promise<string\>
W
wusongqing 已提交
1235

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

1238 1239 1240 1241 1242 1243 1244 1245 1246
**System capability:** SystemCapability.Multimedia.Audio.Core

**Parameters:**

| Name      | Type                  | Mandatory | Description                                                 |
| --------- | ----------------------| --------- | ----------------------------------------------------------- |
| key       | string                | Yes       | Key of the audio parameter whose value is to be obtained.   |

**Return value:**
W
wusongqing 已提交
1247

1248 1249 1250 1251 1252
| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<string>     | Promise used to return the value of the audio parameter.  |

**Example:**
W
wusongqing 已提交
1253 1254

```
1255
audioManager.getAudioParameter('PBits per sample').then((value) => {
W
wusongqing 已提交
1256
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1257
});
W
wusongqing 已提交
1258 1259
```

V
Vaidegi B 已提交
1260

1261 1262 1263 1264 1265
### getDevices

getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors\>\): void

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

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

1269
**Parameters:**
W
wusongqing 已提交
1270

1271 1272 1273 1274 1275 1276
| Name       | Type                                                             | Mandatory | Description                               |
| ---------  | ---------------------------------------------------------------- | --------- | ----------------------------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                        | Yes       | Audio device flag.                        |
| callback   | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes       | Callback used to return the device list.  |

**Example:**
W
wusongqing 已提交
1277 1278

```
1279
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1280
   if (err) {
1281 1282
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1283 1284
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1285
});
W
wusongqing 已提交
1286 1287
```

V
Vaidegi B 已提交
1288 1289


1290
### getDevices
V
Vaidegi B 已提交
1291

1292
getDevices\(deviceFlag: DeviceFlag\): Promise<AudioDeviceDescriptors\>
W
wusongqing 已提交
1293

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

1296
**System capability:** SystemCapability.Multimedia.Audio.Device
1297

1298
**Parameters:**
W
wusongqing 已提交
1299

1300 1301 1302
| Name       | Type                        | Mandatory | Description         |
| ---------  | --------------------------- | --------- | ------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)   | Yes       | Audio device flag.  |
W
wusongqing 已提交
1303

1304 1305 1306 1307 1308
**Return value:**

| Type                                                        | Description                              |
| ----------------------------------------------------------- | ---------------------------------------- |
| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)>  | Promise used to return the device list.  |
W
wusongqing 已提交
1309

1310
**Example:**
W
wusongqing 已提交
1311 1312

```
1313
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1314
    console.log('Promise returned to indicate that the device list is obtained.');
1315
});
W
wusongqing 已提交
1316 1317
```

1318
### setDeviceActive
V
Vaidegi B 已提交
1319

W
wusongqing 已提交
1320
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void
V
Vaidegi B 已提交
1321

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

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

1326
**Parameters:**
W
wusongqing 已提交
1327

1328 1329 1330 1331 1332 1333 1334
| Name       | Type                                   | Mandatory | Description                                                                                                      |
| ---------  | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- |
| deviceType | [ActiveDeviceType](#activedevicetype)  | Yes       | Audio device type.                                                                                               |
| active     | boolean                                | Yes       | Active status to set. The value true means to set the device to the active status, and false means the opposite. |
| callback   | AsyncCallback<void>                    | Yes       | Callback used to return the result.                                                                              |

**Example:**
W
wusongqing 已提交
1335 1336

```
R
rahul 已提交
1337
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1338 1339
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1340
        return;
W
wusongqing 已提交
1341 1342
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1343
});
W
wusongqing 已提交
1344 1345 1346
```


V
Vaidegi B 已提交
1347

1348
### setDeviceActive
V
Vaidegi B 已提交
1349

W
wusongqing 已提交
1350
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\>
V
Vaidegi B 已提交
1351

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

1354 1355 1356 1357 1358 1359 1360 1361
**System capability:** SystemCapability.Multimedia.Audio.Device

**Parameters:**

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

1363 1364 1365 1366 1367 1368 1369 1370
**Return value:**

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


**Example:**
W
wusongqing 已提交
1371 1372

```
R
rahul 已提交
1373
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1374
    console.log('Promise returned to indicate that the device is set to the active status.');
1375
});
W
wusongqing 已提交
1376 1377
```

V
Vaidegi B 已提交
1378

1379
### isDeviceActive
V
Vaidegi B 已提交
1380

W
wusongqing 已提交
1381
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void
W
wusongqing 已提交
1382

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

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

1387
**Parameters:**
W
wusongqing 已提交
1388

1389 1390 1391 1392 1393 1394
| Name       | Type                                   | Mandatory | Description                                              |
| ---------  | ---------------------------------------| --------- | -------------------------------------------------------- |
| deviceType | [ActiveDeviceType](#activedevicetype)  | Yes       | Audio device type.                                       |
| callback   | AsyncCallback<boolean>                 | Yes       | Callback used to return the active status of the device. |

**Example:**
W
wusongqing 已提交
1395 1396

```
R
rahul 已提交
1397
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1398 1399
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1400
        return;
W
wusongqing 已提交
1401 1402
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1403
});
W
wusongqing 已提交
1404 1405
```

V
Vaidegi B 已提交
1406

1407
### isDeviceActive
V
Vaidegi B 已提交
1408

W
wusongqing 已提交
1409
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\>
W
wusongqing 已提交
1410

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

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

1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
**Parameters:**

| Name       | Type                                   | Mandatory | Description                               |
| ---------  | ---------------------------------------| --------- | ----------------------------------------- |
| deviceType | [ActiveDeviceType](#activedevicetype)  | Yes       | Audio device type.                        |

**Return value:**

| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<boolean>    | Promise used to return the active status of the device.  |

**Example:**
W
wusongqing 已提交
1428 1429

```
R
rahul 已提交
1430
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1431
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1432
});
W
wusongqing 已提交
1433 1434 1435
```


1436
### setMicrophoneMute
V
Vaidegi B 已提交
1437

W
wusongqing 已提交
1438
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void
V
Vaidegi B 已提交
1439

1440 1441 1442
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

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

1444
**Parameters:**
W
wusongqing 已提交
1445

1446 1447 1448 1449
| 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<void>  | Yes       | Callback used to return the result.                                                            |
W
wusongqing 已提交
1450

1451
**Example:**
W
wusongqing 已提交
1452 1453 1454 1455 1456 1457 1458 1459

```
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.');
1460
});
W
wusongqing 已提交
1461 1462 1463
```


1464
### setMicrophoneMute
V
Vaidegi B 已提交
1465

W
wusongqing 已提交
1466
setMicrophoneMute\(mute: boolean\): Promise<void\>
V
Vaidegi B 已提交
1467

1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
Mutes or unmutes the microphone. This API uses a promise to return the result.

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

**Parameters:**

| Name       | Type                 | Mandatory | Description                                                                                    |
| ---------  | -------------------- | --------- | ---------------------------------------------------------------------------------------------- |
| mute       | boolean              | Yes       | Mute status to set. The value true means to mute the microphone, and false means the opposite. |

**Return value:**

| Type                | Description                         |
| ------------------- | ----------------------------------- |
| Promise<void>       | Promise used to return the result.  |
W
wusongqing 已提交
1483

Z
zengyawen 已提交
1484
</table>
W
wusongqing 已提交
1485

1486
**Example:**
W
wusongqing 已提交
1487 1488

```
1489
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1490
    console.log('Promise returned to indicate that the microphone is muted.');
1491
});
W
wusongqing 已提交
1492 1493
```

V
Vaidegi B 已提交
1494

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

W
wusongqing 已提交
1497
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void
W
wusongqing 已提交
1498

1499 1500 1501
Checks whether the microphone is muted. This API uses an asynchronous callback to return the query result.

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

1503
**Parameters:**
W
wusongqing 已提交
1504

1505 1506 1507
| Name       | Type                   | Mandatory | Description                                                                                                                                 |
| ---------  | --------------------   | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| callback   | AsyncCallback<boolean> | 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 已提交
1508

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

```
1512
var audioManager = audio.getAudioManager();
W
wusongqing 已提交
1513 1514 1515 1516 1517 1518
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);
1519
});
W
wusongqing 已提交
1520 1521
```

V
Vaidegi B 已提交
1522

1523
### isMicrophoneMute
V
Vaidegi B 已提交
1524

W
wusongqing 已提交
1525
isMicrophoneMute\(\): Promise<boolean\>
W
wusongqing 已提交
1526

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

1529
**System capability:** SystemCapability.Multimedia.Audio.Device
1530

1531
**Return value:**
W
wusongqing 已提交
1532

1533 1534 1535
| Type                | Description                                                                                                                                |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| Promise<boolean>    | 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 已提交
1536

1537
**Example:**
W
wusongqing 已提交
1538 1539

```
1540
var audioManager = audio.getAudioManager();
1541
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1542
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1543
});
W
wusongqing 已提交
1544 1545
```

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

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

1550
Subscribes to system volume change events. This API uses a callback to get volume change events.
V
Vaidegi B 已提交
1551

1552
This is a system API and cannot be called by third-party applications.
1553

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

1556
**Parameters:**
V
Vaidegi B 已提交
1557

1558 1559 1560 1561
| Name     | Type                                   | Mandatory     | Description                                                                                                                                                   |
| :------- | :--------------------------------------| :-------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| type     | string                                 | Yes           | Type of the 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 get the system volume change event.                                                                                                          |
V
Vaidegi B 已提交
1562

1563
**Example:**
V
Vaidegi B 已提交
1564 1565 1566 1567 1568 1569

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


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

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

1578
Subscribes to ringer mode change events. This API uses a callback to get ringer mode changes.
1579

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

1582
**System capability:** SystemCapability.Multimedia.Audio.Communication
V
Vaidegi B 已提交
1583

1584
**Parameters:**
V
Vaidegi B 已提交
1585

1586 1587 1588 1589
| Name     | Type                                       | Mandatory | Description                                                                                                                                                    |
| :------- | :----------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | string                                     | Yes       | Type of the 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 get the updated ringer mode.                                                                                                                  |
V
Vaidegi B 已提交
1590

1591
**Example:**
V
Vaidegi B 已提交
1592 1593 1594 1595

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

1599
### on('deviceChange')
1600

1601
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1602 1603 1604

Subscribes to device change events. When a device is connected/disconnected, registered clients will receive the callback.

1605
**System capability:** SystemCapability.Multimedia.Audio.Device
1606

1607
**Parameters:**
1608

1609 1610 1611
| Name     | Type                                                | Mandatory | Description                                                                                                                                     |
| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | string                                              | Yes       | Type of the event to subscribe to. The value 'deviceChange' means the device change event, which is triggered when a device change is detected. |
G
Geevarghese V K 已提交
1612
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | Yes       | Callback used to obtain the device update details.                                                                                              |
1613

1614
**Example:**
1615 1616 1617 1618 1619 1620 1621

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

1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639
### off('deviceChange')

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

Unsubscribes from audio device connection change events.

This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

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

**Parameters:**

| Name     | Type                                                | Mandatory | Description                                                                                                                                         |
| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- |
| type     | string                                              | Yes       | Type of the event to unsubscribe from.              |
G
Geevarghese V K 已提交
1640
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No        | Callback used to obtain the device update details.  |
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676

**Example:**

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


### on('interrupt')

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

Subscribes to audio interrupt events. When the application's audio is interrupted by another playback event, the application will receive the callback.

This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

**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 interrupt event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt                                | Yes   | Audio interrupt event type.                                                                                                                                                                       |
| callback  | Callback<[InterruptAction](#interruptaction)> | Yes   | Audio interrupt event callback method.                                                                                                                                                            |

**Example:**

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
R
rahul 已提交
1677
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
    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

Unsubscribes from audio interrupt events.

This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.

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

**Parameters:**

| Name      | Type                                          | Mandatory | Description                                                                                                                                                                                            |
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| type      | string                                        | Yes       | Type of event to unsubscribe from. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application. |
| interrupt | AudioInterrupt                                | Yes       | Audio interrupt event type.                                                                                                                                                                            |
| callback  | Callback<[InterruptAction](#interruptaction)> | No        | Audio interrupt event callback method.                                                                                                                                                                 |

**Example:**

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
R
rahul 已提交
1715
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1716 1717 1718 1719 1720 1721 1722 1723 1724
    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>
1725

1726
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1727

1728
Sets the audio scene mode to change audio strategies. This API uses an asynchronous callback to return the result.
1729

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

1732 1733 1734
**System capability:** SystemCapability.Multimedia.Audio.Communication

**Parameters:**
1735 1736 1737 1738 1739 1740

| Name     | Type                                  | Mandatory | Description                         |
| :------- | :------------------------------------ | :-------- | :---------------------------------- |
| scene    | <a href="#audioscene">AudioScene</a>  | Yes       | Audio scene mode.                   |
| callback | AsyncCallback<void\>                  | Yes       | Callback used to return the result. |

1741
**Example:**
1742 1743 1744 1745 1746 1747 1748 1749

```
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.');
1750
});
1751 1752 1753
```


1754
### setAudioScene<sup>8+</sup>
1755

1756
setAudioScene\(scene: AudioScene\): Promise<void\>
1757

1758
Sets the audio scene mode to change audio strategies. This API uses a promise to return the result.
1759

1760
This is a system API and cannot be called by third-party applications.
1761

1762 1763 1764
**System capability:** SystemCapability.Multimedia.Audio.Communication

**Parameters:**
1765 1766 1767 1768 1769 1770

| Name     | Type                                    | Mandatory | Description       |
| :------- | :-------------------------------------- | :-------- | :---------------- |
| scene    | <a href="#audioscene">AudioScene</a>    | Yes       | Audio scene mode. |


1771
**Return value:**
1772 1773 1774 1775 1776 1777

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


1778
**Example:**
1779 1780

```
R
rahul 已提交
1781
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1782 1783 1784 1785 1786 1787 1788
    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');
});
```


1789
### getAudioScene<sup>8+</sup>
1790

1791
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1792

1793
Obtains the audio scene mode. This API uses an asynchronous callback to return the query result.
1794

1795
**System capability:** SystemCapability.Multimedia.Audio.Communication
1796

1797
**Parameters:**
1798 1799 1800 1801 1802

| Name     | Type                                                | Mandatory | Description                                   |
| :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes       | Callback used to return the audio scene mode. |

1803
**Example:**
1804 1805 1806 1807 1808 1809 1810 1811

```
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);
1812
});
1813 1814 1815
```


1816
### getAudioScene<sup>8+</sup>
1817

1818
getAudioScene\(\): Promise<AudioScene\>
1819

1820
Obtains the audio scene mode. This API uses a promise to return the query result.
1821

1822
**System capability:** SystemCapability.Multimedia.Audio.Communication
1823

1824
**Return value:**
1825 1826 1827 1828 1829 1830

| Type                                          | Description                                  |
| :-------------------------------------------- | :------------------------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene mode. |


1831
**Example:**
1832 1833 1834 1835 1836 1837

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

1841
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1842

1843
Describes an audio device.
1844

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

1847 1848 1849 1850
| Name       | Type                      | Readable | Writable | Description        |
| ---------- | ------------------------- | -------- | -------- | ------------------ |
| deviceRole | [DeviceRole](#devicerole) | Yes      | No       | Audio device role. |
| deviceType | [DeviceType](#devicetype) | Yes      | No       | Audio device type. |
V
Vaidegi B 已提交
1851

1852
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1853

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

1856
**System capability:** SystemCapability.Multimedia.Audio.Device
V
Vaidegi B 已提交
1857

1858
**Example:**
V
Vaidegi B 已提交
1859

1860 1861
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1862

1863 1864 1865
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1866 1867 1868

}

1869 1870 1871 1872 1873 1874
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 已提交
1875
    if (deviceTypeValue != null && deviceRoleValue != null){
1876
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1877 1878
    }
    else{
1879 1880
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1881
});
V
Vaidegi B 已提交
1882
```
1883 1884 1885
## AudioRenderer<sup>8+</sup>

Provides related APIs for audio rendering. Before calling the AudioRenderer API, you need to create an instance through [createAudioRenderer](#audiocreateaudiorenderer8).
V
Vaidegi B 已提交
1886

1887
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
1888

1889
### state<sup>8+</sup>
V
Vaidegi B 已提交
1890

1891
readonly state: AudioState
V
Vaidegi B 已提交
1892 1893 1894

Defines the current render state.

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

1897 1898 1899
| Name  | Type                        | Readable | Writable | Description         |
| :---- | :-------------------------- | :------- | :------- | :------------------ |
| state |  [AudioState](#audiostate8) | Yes      | No       | Audio render state. |
V
Vaidegi B 已提交
1900

1901
**Example:**
V
Vaidegi B 已提交
1902 1903 1904 1905 1906

```
    var state = audioRenderer.state;
```

1907
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1908

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

1911
Obtains the renderer information provided while creating a renderer instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1912

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

1915
**Parameters:**
V
Vaidegi B 已提交
1916

1917 1918 1919
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)>  | Yes       | Callback used to return the renderer information. |
V
Vaidegi B 已提交
1920

1921
**Example:**
V
Vaidegi B 已提交
1922 1923

```
1924
audioRenderer.getRendererInfo((err, rendererInfo) => {
1925 1926 1927 1928
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1929
});
V
Vaidegi B 已提交
1930 1931 1932
```


1933
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1934

1935
getRendererInfo(): Promise<AudioRendererInfo\>
1936

1937
Obtains the renderer information provided while creating a renderer instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
1938

1939
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
1940

1941
**Return value:**
V
Vaidegi B 已提交
1942

1943 1944 1945
| Type                                                | Description                                      |
| :-------------------------------------------------- | :----------------------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)>   | Promise used to return the renderer information. |
V
Vaidegi B 已提交
1946

1947
**Example:**
V
Vaidegi B 已提交
1948 1949

```
R
rahul 已提交
1950
var resultFlag = true;
1951 1952 1953 1954 1955 1956 1957 1958 1959
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 已提交
1960

1961
```
V
Vaidegi B 已提交
1962

1963
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1964

1965
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1966

1967
Obtains the renderer stream information. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1968

1969
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
1970

1971
**Parameters:**
V
Vaidegi B 已提交
1972

1973 1974 1975
| Name     | Type                                                    | Mandatory | Description                                     |
| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\>    | Yes       | Callback used to return the stream information. |
V
Vaidegi B 已提交
1976

1977
**Example:**
V
Vaidegi B 已提交
1978 1979

```
1980
audioRenderer.getStreamInfo((err, streamInfo) => {
1981 1982
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1983 1984 1985
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1986
});
V
Vaidegi B 已提交
1987 1988
```

1989
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1990

1991
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1992

1993
Obtains the renderer stream information. This API uses a promise to return the result.
V
Vaidegi B 已提交
1994

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

1997
**Return value:**
V
Vaidegi B 已提交
1998

1999 2000 2001
| Type                                               | Description                                    |
| :------------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\>     | Promise used to return the stream information. |
V
Vaidegi B 已提交
2002

2003
**Example:**
V
Vaidegi B 已提交
2004 2005

```
2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
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 已提交
2016 2017
```

2018
### start<sup>8+</sup>
V
Vaidegi B 已提交
2019

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

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

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

2026
**Parameters:**
V
Vaidegi B 已提交
2027

2028 2029 2030 2031
| Name     | Type                    | Mandatory | Description                             |
| :------- | :---------------------- | :-------- | :-------------------------------------- |
| callback | AsyncCallback<void\>    | Yes       | Callback used to return the result.     |
|          |                         |           |                                         |
V
Vaidegi B 已提交
2032

2033
**Example:**
V
Vaidegi B 已提交
2034 2035

```
2036
audioRenderer.start((err) => {
2037 2038
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
2039
    } else {
2040
        console.info('Renderer start success.');
V
Vaidegi B 已提交
2041
    }
2042
});
V
Vaidegi B 已提交
2043 2044
```

2045
### start<sup>8+</sup>
V
Vaidegi B 已提交
2046

2047
start(): Promise<void\>
V
Vaidegi B 已提交
2048

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

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

2053
**Return value:**
V
Vaidegi B 已提交
2054

2055 2056 2057
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
2058

2059
**Example:**
V
Vaidegi B 已提交
2060 2061

```
2062 2063 2064 2065 2066
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2067 2068 2069
```


2070
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2071

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

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

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

2078
**Parameters:**
V
Vaidegi B 已提交
2079

2080 2081 2082 2083
| Name     | Type                    | Mandatory | Description                           |
| :------- | :---------------------- | :-------- | :------------------------------------ |
| callback | AsyncCallback<void\>    | Yes       | Callback used to return the result.   |
|          |                         |           |                                       |
V
Vaidegi B 已提交
2084

2085
**Example:**
V
Vaidegi B 已提交
2086 2087

```
2088
audioRenderer.pause((err) => {
2089 2090
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2091
    } else {
2092
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2093
    }
2094
});
V
Vaidegi B 已提交
2095 2096
```

2097
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2098

2099
pause(): Promise\<void>
V
Vaidegi B 已提交
2100

2101
Pauses rendering. This API uses a promise to return the result.
2102

2103
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2104

2105
**Return value:**
V
Vaidegi B 已提交
2106

2107 2108 2109
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
2110

2111
**Example:**
V
Vaidegi B 已提交
2112 2113

```
2114 2115 2116 2117 2118
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2119 2120
```

2121
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2122

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

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

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

2129
**Parameters:**
V
Vaidegi B 已提交
2130

2131 2132 2133 2134
| Name     | Type                    | Mandatory | Description                             |
| :------- | :---------------------- | :-------- | :---------------------------------------|
| callback | AsyncCallback<void\>    | Yes       | Callback used to return the result.     |
|          |                         |           |                                         |
V
Vaidegi B 已提交
2135

2136
**Example:**
V
Vaidegi B 已提交
2137 2138

```
2139
audioRenderer.drain((err) => {
2140 2141
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2142
    } else {
2143
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2144
    }
2145
});
V
Vaidegi B 已提交
2146 2147
```

2148
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2149

2150
drain(): Promise\<void>
V
Vaidegi B 已提交
2151

2152
Drains the playback buffer. This API uses a promise to return the result.
2153

2154
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2155

2156
**Return value:**
V
Vaidegi B 已提交
2157

2158 2159 2160
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
2161

2162
**Example:**
V
Vaidegi B 已提交
2163 2164

```
2165 2166 2167 2168 2169
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2170 2171 2172
```


2173
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2174

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

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

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

2181
**Parameters:**
V
Vaidegi B 已提交
2182

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

2187
**Example:**
V
Vaidegi B 已提交
2188 2189

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

2199
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2200

2201
stop(): Promise\<void>
V
Vaidegi B 已提交
2202

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

2205
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2206

2207
**Return value:**
V
Vaidegi B 已提交
2208

2209 2210 2211
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
2212

2213
**Example:**
V
Vaidegi B 已提交
2214 2215

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


2224
### release<sup>8+</sup>
V
Vaidegi B 已提交
2225

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

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

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

2232
**Parameters:**
V
Vaidegi B 已提交
2233

2234 2235 2236
| Name     | Type                    | Mandatory | Description                            |
| :------- | :---------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<void\>    | Yes       | Callback used to return the result.    |
V
Vaidegi B 已提交
2237

2238
**Example:**
V
Vaidegi B 已提交
2239 2240

```
2241
audioRenderer.release((err) => {
2242 2243
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2244
    } else {
2245
        console.log('Renderer released.');
V
Vaidegi B 已提交
2246
    }
2247
});
V
Vaidegi B 已提交
2248 2249
```

2250
### release<sup>8+</sup>
V
Vaidegi B 已提交
2251

2252
release(): Promise\<void>
V
Vaidegi B 已提交
2253

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

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

2258
**Return value:**
V
Vaidegi B 已提交
2259

2260 2261 2262
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
2263

2264
**Example:**
V
Vaidegi B 已提交
2265 2266

```
2267 2268 2269 2270 2271
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2272 2273
```

2274
### write<sup>8+</sup>
V
Vaidegi B 已提交
2275

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

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

2280
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2281

2282
**Parameters:**
V
Vaidegi B 已提交
2283 2284 2285 2286 2287 2288

| Name     | Type                    | Mandatory | Description                                                                                          |
| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- |
| buffer   | ArrayBuffer             | Yes       | Buffer to be written.                                                                                |
| callback | AsyncCallback<boolean\> | Yes       | Returns the number of bytes written if the operation is successful; returns an error code otherwise. |

2289
**Example:**
V
Vaidegi B 已提交
2290 2291

```
2292 2293 2294
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

V
Vaidegi B 已提交
2295 2296 2297
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2298
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2299
    if (writtenbytes < 0) {
2300
        console.error('write failed.');
V
Vaidegi B 已提交
2301 2302 2303
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2304
});
V
Vaidegi B 已提交
2305 2306 2307
```


2308
### write<sup>8+</sup>
V
Vaidegi B 已提交
2309

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

2312
Writes the buffer. This API uses a promise to return the result.
2313

2314
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2315

2316
**Return value:**
V
Vaidegi B 已提交
2317 2318 2319 2320 2321

| Type             | Description                                                                                          |
| :--------------- | :--------------------------------------------------------------------------------------------------- |
| Promise<number\> | Returns the number of bytes written if the operation is successful; returns an error code otherwise. |

2322
**Example:**
V
Vaidegi B 已提交
2323 2324

```
2325 2326 2327 2328
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2329 2330 2331
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2332 2333 2334 2335 2336 2337 2338 2339 2340
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 已提交
2341 2342
```

2343
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2344

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

2347
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2348

2349
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2350

2351
**Parameters:**
V
Vaidegi B 已提交
2352 2353 2354 2355 2356

| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the timestamp. |

2357
**Example:**
V
Vaidegi B 已提交
2358 2359

```
2360
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2361
    console.log('Current timestamp: ' + timestamp);
2362
});
V
Vaidegi B 已提交
2363 2364 2365
```


2366
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2367

2368
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2369

2370
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result.
V
Vaidegi B 已提交
2371

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

2374
**Return value:**
V
Vaidegi B 已提交
2375 2376 2377 2378 2379

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

2380
**Example:**
V
Vaidegi B 已提交
2381 2382

```
2383 2384 2385 2386 2387
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2388 2389 2390
```


2391
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2392

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

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

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

2399
**Parameters:**
V
Vaidegi B 已提交
2400 2401 2402 2403 2404

| Name     | Type                   | Mandatory | Description                              |
| :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |

2405
**Example:**
V
Vaidegi B 已提交
2406 2407

```
R
rahul 已提交
2408
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
V
Vaidegi B 已提交
2409 2410 2411
    if (err) {
        console.error('getBufferSize error');
    }
2412
});
V
Vaidegi B 已提交
2413 2414 2415
```


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

2418
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2419

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

2422
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2423

2424
**Return value:**
V
Vaidegi B 已提交
2425 2426 2427 2428 2429

| Type             | Description                             |
| :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size. |

2430
**Example:**
V
Vaidegi B 已提交
2431 2432

```
R
rahul 已提交
2433 2434 2435 2436
var bufferSize;
await audioRenderer.getBufferSize().then(async function (data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
    bufferSize=data;
2437
}).catch((err) => {
R
rahul 已提交
2438
    console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
2439
});
V
Vaidegi B 已提交
2440 2441
```

2442
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2443

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

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

2448
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2449

2450
**Parameters:**
2451

2452 2453 2454 2455
| Name     | Type                                        | Mandatory | Description                         |
| :------- | :------------------------------------------ | :-------- | :---------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8)    | Yes       | Audio render rate.                  |
| callback | AsyncCallback<void\>                        | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
2456

2457
**Example:**
V
Vaidegi B 已提交
2458 2459

```
2460
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2461
    if (err) {
2462
        console.error('Failed to set params');
V
Vaidegi B 已提交
2463 2464 2465
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2466
});
V
Vaidegi B 已提交
2467 2468 2469
```


2470
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2471

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

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

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

2478
**Parameters:**
V
Vaidegi B 已提交
2479

2480 2481 2482
| Name | Type                                     | Mandatory | Description        |
| :--- | :--------------------------------------- | :-------- | :----------------- |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |
V
Vaidegi B 已提交
2483

2484
**Return value:**
V
Vaidegi B 已提交
2485 2486 2487 2488 2489

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

2490
**Example:**
V
Vaidegi B 已提交
2491 2492

```
2493 2494 2495 2496 2497
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2498 2499
```

2500
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2501

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

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

2506
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2507

2508
**Parameters:**
2509

2510 2511 2512
| Name     | Type                                                     | Mandatory | Description                                    |
| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
2513

2514
**Example:**
V
Vaidegi B 已提交
2515 2516

```
2517
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2518
    console.log('getRenderRate: ' + renderrate);
2519
});
V
Vaidegi B 已提交
2520 2521 2522
```


2523
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2524

2525
getRenderRate(): Promise\<AudioRendererRate>
2526

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

2529
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2530

2531
**Return value:**
V
Vaidegi B 已提交
2532

2533 2534 2535
| Type                                                | Description                                   |
| :-------------------------------------------------- | :-------------------------------------------- |
| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. |
V
Vaidegi B 已提交
2536

2537
**Example:**
V
Vaidegi B 已提交
2538 2539

```
2540 2541 2542 2543 2544
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2545 2546 2547
```


2548
### on('interrupt')<sup>9+</sup>
V
Vaidegi B 已提交
2549

2550
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
2551

2552
Subscribes to audio interrupt events. This API uses a callback to get interrupt events. The interrupt event is triggered when audio rendering is interrupted.
2553

2554
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2555

2556
**Parameters:**
V
Vaidegi B 已提交
2557

2558 2559 2560 2561
| Name     | Type                                          | Mandatory | Description                                     |
| :------- | :-------------------------------------------- | :-------- | :---------------------------------------------- |
| type     | string                                        | Yes       | Type of the playback event to subscribe to.     |
| callback | Callback<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to listen for interrupt callback. |
V
Vaidegi B 已提交
2562

2563
**Example:**
V
Vaidegi B 已提交
2564 2565

```
R
rahul 已提交
2566 2567 2568
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
V
Vaidegi B 已提交
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580
    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) {
R
rahul 已提交
2581
        switch (interruptEvent.hintType) {
V
Vaidegi B 已提交
2582 2583
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
R
rahul 已提交
2584 2585
                await audioRenderer.start().then(async function () {
                    console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
R
rahul 已提交
2586
                    started = true;
R
rahul 已提交
2587
                }).catch((err) => {
R
rahul 已提交
2588 2589
                    console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
                    started = false;
R
rahul 已提交
2590 2591 2592 2593 2594 2595 2596
                });
                if (started) {
                    isPlay = true;
                    console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
                } else {
                    console.error('AudioInterruptMusic Renderer start failed');
                }
V
Vaidegi B 已提交
2597 2598 2599
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
R
rahul 已提交
2600 2601 2602 2603 2604 2605 2606 2607
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
V
Vaidegi B 已提交
2608 2609 2610
                break;
        }
    }
2611
});
V
Vaidegi B 已提交
2612 2613
```

2614
### on('markReach')<sup>8+</sup>
2615

2616
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
2617 2618 2619

Subscribes to mark reached events. When the number of frames rendered reaches the value of the frame parameter, the callback is invoked.

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

2622
**Parameters:**
2623 2624 2625 2626 2627

| Name     | Type                      | Mandatory | Description                                                              |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- |
| type     | string                    | Yes       | Type of the renderer event to subscribe to.                              |
| frame    | number                    | Yes       | Number of frames to trigger the event. The value must be greater than 0. |
2628
| callback | (position: number) => {}  | Yes       | Callback invoked when the event is triggered.                            |
2629

2630
**Example:**
2631 2632 2633 2634 2635 2636 2637 2638 2639 2640

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


2641
### off('markReach') <sup>8+</sup>
2642

2643
off(type: 'markReach'): void
2644 2645 2646

Unsubscribes from mark reached events.

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

2649
**Parameters:**
2650 2651 2652 2653 2654

| Name     | Type                      | Mandatory | Description                                      |
| :------- | :------------------------ | :-------- | :----------------------------------------------- |
| type     | string                    | Yes       | Type of the renderer event to unsubscribe from.  |

2655
**Example:**
2656 2657 2658 2659 2660

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

2661
### on('periodReach') <sup>8+</sup>
2662

2663
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
2664 2665 2666

Subscribes to period reached events. When the period of frame rendering reaches the value of frame parameter, the callback is invoked.

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

2669
**Parameters:**
2670 2671 2672 2673 2674

| Name     | Type                      | Mandatory | Description                                                                        |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- |
| type     | string                    | Yes       | Type of the renderer event to subscribe to.                                        |
| frame    | number                    | Yes       | Period during which frame rendering is listened. The value must be greater than 0. |
2675
| callback |  (position: number) => {} | Yes       | Callback invoked when the event is triggered.                                      |
2676

2677
**Example:**
2678 2679 2680 2681 2682 2683 2684 2685 2686

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

2687
### off('periodReach') <sup>8+</sup>
2688

2689
off(type: 'periodReach'): void
2690 2691 2692

Unsubscribes from period reached events.

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

2695
**Parameters:**
2696 2697 2698 2699 2700

| Name     | Type                      | Mandatory | Description                                      |
| :------- | :------------------------ | :-------- | :----------------------------------------------- |
| type     | string                    | Yes       | Type of the renderer event to unsubscribe from.  |

2701
**Example:**
2702 2703 2704 2705

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

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

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

2711
Subscribes to state change events.
V
Vaidegi B 已提交
2712

2713
**System capability:** SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
2714

2715 2716 2717 2718 2719
**Parameters:**

| Name     | Type                       | Mandatory | Description                                                                              |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- |
| type     | string                     | Yes       | Type of the event to subscribe to. The value 'stateChange' means the state change event. |
G
Geevarghese V K 已提交
2720
| callback | [AudioState](#audiostate8) | Yes       | Callback used to return the state change.                                                |
2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733

**Example:**

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

2735
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2736

2737
Provides related APIs for audio capture. Before calling the API of AudioCapturer, you need to create an instance through [createAudioCapturer](#audiocreateaudiocapturer8).
V
Vaidegi B 已提交
2738

2739
### state<sup>8+</sup>
V
Vaidegi B 已提交
2740

2741
readonly state: AudioState
V
Vaidegi B 已提交
2742

2743
Defines the current capture state.
V
Vaidegi B 已提交
2744

2745
**System capability:** SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2746

2747 2748 2749
| Name  | Type                       | Readable | Writable | Description          |
| :---- | :------------------------- | :------- | :------- | :------------------- |
| state | [AudioState](#audiostate8) | Yes      | No       | Audio capture state. |
V
Vaidegi B 已提交
2750

2751
**Example:**
V
Vaidegi B 已提交
2752 2753

```
2754
var state = audioCapturer.state;
V
Vaidegi B 已提交
2755 2756 2757
```


2758
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2759

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

2762
Obtains the capturer information provided while creating a capturer instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2763

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

2766
**Parameters:**
V
Vaidegi B 已提交
2767

2768 2769
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
G
Geevarghese V K 已提交
2770
| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\>  | Yes       | Callback used to return the capturer information. |
V
Vaidegi B 已提交
2771

2772
**Example:**
V
Vaidegi B 已提交
2773 2774

```
2775
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2776
    if (err) {
2777
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2778
    } else {
2779 2780 2781
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2782
    }
2783
});
V
Vaidegi B 已提交
2784 2785 2786
```


2787
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2788

2789
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2790

2791
Obtains the capturer information provided while creating a capturer instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2792

2793
**System capability:** SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2794

2795
**Return value:**
V
Vaidegi B 已提交
2796

2797 2798 2799
| Type                                                | Description                                      |
| :-------------------------------------------------- | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\>   | Promise used to return the capturer information. |
V
Vaidegi B 已提交
2800

2801
**Example:**
V
Vaidegi B 已提交
2802 2803

```
2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814
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);
2815
});
V
Vaidegi B 已提交
2816

2817
```
V
Vaidegi B 已提交
2818

2819
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2820

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

2823
Obtains the capturer stream information. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2824

2825
**System capability:** SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2826

2827
**Parameters:**
V
Vaidegi B 已提交
2828

2829 2830
| Name     | Type                                                         | Mandatory | Description                                     |
| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- |
G
Geevarghese V K 已提交
2831
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\>    | Yes       | Callback used to return the stream information. |
V
Vaidegi B 已提交
2832

2833
**Example:**
V
Vaidegi B 已提交
2834 2835

```
2836
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2837
    if (err) {
2838
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2839
    } else {
2840 2841 2842 2843 2844
        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 已提交
2845
    }
2846
});
V
Vaidegi B 已提交
2847 2848
```

2849
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2850

2851
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2852

2853
Obtains the capturer stream information. This API uses a promise to return the result.
V
Vaidegi B 已提交
2854

2855
**System capability:** SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
2856

2857
**Return value:**
V
Vaidegi B 已提交
2858

2859 2860
| Type                                                  | Description                                      |
| :---------------------------------------------------- | :----------------------------------------------- |
G
Geevarghese V K 已提交
2861
| Promise<[AudioStreamInfo](#audiostreaminfo8)\>   | Promise used to return the stream information.   |
V
Vaidegi B 已提交
2862

2863
**Example:**
V
Vaidegi B 已提交
2864 2865

```
2866 2867 2868 2869 2870 2871 2872 2873
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);
2874
});
2875

V
Vaidegi B 已提交
2876 2877
```

2878
### start<sup>8+</sup>
V
Vaidegi B 已提交
2879

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

2882
Starts capturing. This API uses an asynchronous callback to return the result.
2883

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

2886
**Parameters:**
2887 2888 2889 2890 2891

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

2892
**Example:**
2893 2894

```
2895
audioCapturer.start((err) => {
2896 2897 2898 2899 2900
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2901
});
2902 2903 2904
```


2905
### start<sup>8+</sup>
2906

2907
start(): Promise<void\>
2908

2909
Starts capturing. This API uses a promise to return the result.
2910

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

2913
**Return value:**
2914 2915 2916 2917 2918

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

2919
**Example:**
2920 2921 2922

```
audioCapturer.start().then(() => {
2923 2924 2925 2926 2927 2928 2929 2930 2931 2932
    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;
2933 2934 2935
});
```

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

2938
stop(callback: AsyncCallback<void\>): void
2939

2940
Stops capturing. This API uses an asynchronous callback to return the result.
2941

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

2944
**Parameters:**
2945 2946 2947 2948 2949

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

2950
**Example:**
2951 2952

```
2953
audioCapturer.stop((err) => {
2954 2955 2956 2957 2958
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
2959
});
2960 2961 2962
```


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

2965
stop(): Promise<void\>
2966

2967
Stops capturing. This API uses a promise to return the result.
2968

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

2971
**Return value:**
2972 2973 2974 2975 2976

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

2977
**Example:**
2978 2979 2980

```
audioCapturer.stop().then(() => {
2981 2982
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
R
rahul 已提交
2983
    if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
2984 2985 2986 2987 2988 2989
        stateFlag=true;
        console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false;
2990 2991 2992 2993
});
```


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

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

2998
Releases the capturer. This API uses an asynchronous callback to return the result.
2999

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

3002
**Parameters:**
3003 3004 3005 3006 3007

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

3008
**Example:**
3009 3010

```
3011
audioCapturer.release((err) => {
3012 3013 3014 3015 3016
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
3017
});
3018 3019 3020
```


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

3023
release(): Promise<void\>
3024

3025
Releases the capturer. This API uses a promise to return the result.
3026

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

3029
**Return value:**
3030 3031 3032 3033 3034

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

3035
**Example:**
3036 3037

```
3038

3039
audioCapturer.release().then(() => {
3040 3041 3042 3043 3044 3045 3046 3047
    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);
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false
3048
});
3049

3050 3051 3052
```


3053
### read<sup>8+</sup>
3054

3055
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
3056

3057
Reads the buffer from the audio capturer. This API uses an asynchronous callback to return the result.
3058

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

3061
**Parameters:**
3062 3063 3064 3065 3066 3067 3068

| Name           | Type                        | Mandatory | Description                                   |
| :------------- | :-------------------------- | :-------- | :-------------------------------------------- |
| size           | number                      | Yes       | Number of bytes to read.                      |
| isBlockingRead | boolean                     | Yes       | Whether the read operation should be blocked. |
| callback       | AsyncCallback<ArrayBuffer\> | Yes       | Callback used to return the buffer.           |

3069
**Example:**
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
};
```


3080
### read<sup>8+</sup>
3081

3082
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
3083

3084
Reads the buffer from the audio capturer. This API uses a promise to return the result.
3085

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

3088
**Parameters:**
3089

3090 3091 3092 3093
| Name           | Type       | Mandatory | Description                                   |
| :------------- | :--------- | :-------- | :-------------------------------------------- |
| size           | number     | Yes       | Number of bytes to read.                      |
| isBlockingRead | boolean    | Yes       | Whether the read operation should be blocked. |
3094

3095
**Return value:**
3096 3097 3098 3099 3100

| Type                  | Description                                                                                      |
| :-------------------- | :----------------------------------------------------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.    |

3101
**Example:**
3102 3103

```
3104 3105 3106 3107
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3108 3109 3110 3111
});
```


3112
### getAudioTime<sup>8+</sup>
3113

3114
getAudioTime(callback: AsyncCallback<number\>): void
3115

3116
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result.
3117

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

3120
**Parameters:**
3121 3122 3123 3124 3125 3126

| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the timestamp. |
|          |                        |           |                                        |

3127
**Example:**
3128 3129

```
3130
audioCapturer.getAudioTime((err, timestamp) => {
3131
    console.log('Current timestamp: ' + timestamp);
3132
});
3133 3134 3135
```


3136
### getAudioTime<sup>8+</sup>
3137

3138
getAudioTime(): Promise<number\>
3139

3140
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result.
3141

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

3144
**Return value:**
3145 3146 3147 3148 3149

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

3150
**Example:**
3151 3152 3153

```
audioCapturer.getAudioTime().then((audioTime) => {
3154 3155 3156
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3157
});
3158

3159 3160 3161
```


3162
### getBufferSize<sup>8+</sup>
3163

3164
getBufferSize(callback: AsyncCallback<number\>): void
3165

3166
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
3167

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

3170
**Parameters:**
3171 3172 3173 3174 3175 3176

| Name     | Type                   | Mandatory | Description                              |
| :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |
|          |                        |           |                                          |

3177
**Example:**
3178 3179

```
3180
audioCapturer.getBufferSize((err, bufferSize) => {
3181 3182
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3183 3184 3185 3186 3187
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3188 3189 3190 3191
    }
});
```

3192
### getBufferSize<sup>8+</sup>
3193

3194
getBufferSize(): Promise<number\>
3195

3196
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
3197

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

3200
**Return value:**
3201 3202 3203 3204 3205

| Type             | Description                             |
| :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size. |

3206
**Example:**
3207 3208

```
R
rahul 已提交
3209 3210 3211 3212 3213 3214
await audioCapturer.getBufferSize().then(async function (bufferSize) {
    console.info('AudioFrameworkRecordLog: getBufferSize :SUCCESS '+ bufferSize);
    var buffer = await audioCapturer.read(bufferSize, true);
    console.info('Buffer read is ' + buffer );
    }).catch((err) => {
    console.info('AudioFrameworkRecordLog: getBufferSize :ERROR : '+err.message);
3215 3216 3217
});
```

3218
### on('markReach')<sup>8+</sup>
3219

3220
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
3221 3222 3223

Subscribes to mark reached events. When the number of frames captured reaches the value of the frame parameter, the callback is invoked.

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

3226
**Parameters:**
3227 3228 3229 3230 3231

| Name     | Type                      | Mandatory | Description                                                              |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- |
| type     | string                    | Yes       | Type of the capturer event to subscribe to.                              |
| frame    | number                    | Yes       | Number of frames to trigger the event. The value must be greater than 0. |
3232
| callback | position: number) => {}   | Yes       | Callback invoked when the event is triggered.                            |
3233

3234
**Example:**
3235 3236 3237 3238 3239 3240 3241 3242 3243 3244

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


3245
### off('markReach')<sup>8+</sup>
3246

3247
off(type: 'markReach'): void
3248 3249 3250

Unsubscribes from the mark reached events.

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

3253
**Parameters:**
3254 3255 3256 3257 3258

| Name     | Type                      | Mandatory | Description                                     |
| :------- | :------------------------ | :-------- | :---------------------------------------------- |
| type     | string                    | Yes       | Type of the capturer event to unsubscribe from. |

3259
**Example:**
3260 3261 3262 3263 3264

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

3265
### on('periodReach')<sup>8+</sup>
3266

3267
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
3268 3269 3270

Subscribes to period reached events. When the period of frame capturing reaches the value of frame parameter, the callback is invoked.

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

3273
**Parameters:**
3274 3275 3276 3277 3278

| Name     | Type                      | Mandatory | Description                                                                        |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- |
| type     | string                    | Yes       | Type of the capturer event to subscribe to.                                        |
| frame    | number                    | Yes       | Period during which frame capturing is listened. The value must be greater than 0. |
3279
| callback | (position: number) => {}  | Yes       | Callback invoked when the event is triggered.                                      |
3280

3281
**Example:**
3282 3283 3284 3285 3286 3287 3288 3289 3290

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

3291
### off('periodReach')<sup>8+</sup>
3292

3293
off(type: 'periodReach'): void
3294 3295 3296

Unsubscribes from period reached events.

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

3299
**Parameters:**
3300 3301 3302 3303 3304

| Name     | Type                      | Mandatory | Description                                     |
| :------- | :------------------------ | :-------- | :---------------------------------------------- |
| type     | string                    | Yes       | Type of the capturer event to unsubscribe from. |

3305 3306 3307 3308 3309 3310 3311 3312 3313
**Example:**

```
audioCapturer.off('periodReach')
```

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

on(type: 'stateChange', callback: Callback<AudioState\>): void
3314

3315
Subscribes to state change events.
3316

3317 3318 3319 3320 3321 3322 3323
**System capability:** SystemCapability.Multimedia.Audio.Capturer

**Parameters:**

| Name     | Type                       | Mandatory | Description                                                                              |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- |
| type     | string                     | Yes       | Type of the event to subscribe to. The value 'stateChange' means the state change event. |
G
Geevarghese V K 已提交
3324
| callback | [AudioState](#audiostate8) | Yes       | Callback used to return the state change.                                                |
3325 3326

**Example:**
3327 3328

```
3329 3330 3331 3332 3333 3334 3335 3336
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");
    }
});
3337
```