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

3
The **Audio** module provides basic audio management capabilities, including audio volume and audio device management, and audio data collection and rendering.
V
Vaidegi B 已提交
4

5 6
This module provides the following common audio-related functions:

W
wusongqing 已提交
7 8 9
- [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.
10
- [TonePlayer](#toneplayer9): tone player, used to manage and play Dual Tone Multi Frequency (DTMF) tones, such as dial tones and ringback tones.
11

12 13 14 15
>  **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.

16
## Modules to Import
W
wusongqing 已提交
17

G
Gloria 已提交
18
```js
W
wusongqing 已提交
19 20 21
import audio from '@ohos.multimedia.audio';
```

G
Gloria 已提交
22 23
## Constants

24 25 26 27 28
| Name                                   | Type     | Readable | Writable| Description              |
| --------------------------------------- | ----------| ---- | ---- | ------------------ |
| LOCAL_NETWORK_ID<sup>9+</sup>           | string    | Yes  | No  | Network ID of the local device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.Audio.Device |
| DEFAULT_VOLUME_GROUP_ID<sup>9+</sup>    | number    | Yes  | No  | Default volume group ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Volume      |
| DEFAULT_INTERRUPT_GROUP_ID<sup>9+</sup> | number | Yes  | No  | Default audio interruption group ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Interrupt      |
G
Gloria 已提交
29 30 31 32 33 34 35

**Example**

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

const localNetworkId = audio.LOCAL_NETWORK_ID;
36 37
const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID;
const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID;
G
Gloria 已提交
38
```
W
wusongqing 已提交
39

40
## audio.getAudioManager
V
Vaidegi B 已提交
41

42
getAudioManager(): AudioManager
43

44
Obtains an **AudioManager** instance.
W
wusongqing 已提交
45

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

W
wusongqing 已提交
48
**Return value**
G
Gloria 已提交
49

W
wusongqing 已提交
50 51 52
| Type                         | Description        |
| ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | **AudioManager** instance.|
W
wusongqing 已提交
53

W
wusongqing 已提交
54
**Example**
G
Gloria 已提交
55
```js
56
let audioManager = audio.getAudioManager();
W
wusongqing 已提交
57 58
```

59
## audio.createAudioRenderer<sup>8+</sup>
60

61
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
62

63
Creates an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
64 65

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

W
wusongqing 已提交
67
**Parameters**
68

W
wusongqing 已提交
69 70 71 72
| Name  | Type                                           | Mandatory| Description            |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options  | [AudioRendererOptions](#audiorendereroptions8)  | Yes  | Renderer configurations.    |
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes  | Callback used to return the **AudioRenderer** instance.|
73

W
wusongqing 已提交
74
**Example**
75

G
Gloria 已提交
76
```js
77
import audio from '@ohos.multimedia.audio';
78
let audioStreamInfo = {
79 80 81 82
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
83 84
}

85
let audioRendererInfo = {
86 87 88
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
  rendererFlags: 0
89 90
}

91
let audioRendererOptions = {
92 93
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
94 95 96
}

audio.createAudioRenderer(audioRendererOptions,(err, data) => {
97
  if (err) {
G
Gloria 已提交
98
    console.error(`AudioRenderer Created: Error: ${err}`);
99
  } else {
G
Gloria 已提交
100
    console.info('AudioRenderer Created: Success: SUCCESS');
101 102
    let audioRenderer = data;
  }
103 104
});
```
W
wusongqing 已提交
105

106
## audio.createAudioRenderer<sup>8+</sup>
107

W
wusongqing 已提交
108 109
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>

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

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

W
wusongqing 已提交
114
**Parameters**
115

W
wusongqing 已提交
116 117 118
| Name | Type                                          | Mandatory| Description        |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes  | Renderer configurations.|
V
Vaidegi B 已提交
119

W
wusongqing 已提交
120
**Return value**
V
Vaidegi B 已提交
121

W
wusongqing 已提交
122 123 124
| Type                                     | Description            |
| ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
V
Vaidegi B 已提交
125

W
wusongqing 已提交
126
**Example**
V
Vaidegi B 已提交
127

G
Gloria 已提交
128
```js
129 130
import audio from '@ohos.multimedia.audio';

131
let audioStreamInfo = {
132 133 134 135
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
136 137
}

138
let audioRendererInfo = {
139 140 141
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
  rendererFlags: 0
142 143
}

144
let audioRendererOptions = {
145 146
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
147 148
}

149
let audioRenderer;
150
audio.createAudioRenderer(audioRendererOptions).then((data) => {
151
  audioRenderer = data;
G
Gloria 已提交
152
  console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
153
}).catch((err) => {
G
Gloria 已提交
154
  console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`);
155
});
V
Vaidegi B 已提交
156 157
```

158
## audio.createAudioCapturer<sup>8+</sup>
159

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

162
Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
163

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

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

W
wusongqing 已提交
168
**Parameters**
V
Vaidegi B 已提交
169

W
wusongqing 已提交
170 171 172 173 174 175
| Name  | Type                                           | Mandatory| Description            |
| :------- | :---------------------------------------------- | :--- | :--------------- |
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the **AudioCapturer** instance.|

**Example**
176

G
Gloria 已提交
177
```js
178
import audio from '@ohos.multimedia.audio';
179
let audioStreamInfo = {
180 181 182 183
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
184 185
}

186
let audioCapturerInfo = {
187 188
  source: audio.SourceType.SOURCE_TYPE_MIC,
  capturerFlags: 0
189 190
}

191
let audioCapturerOptions = {
192 193
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
194 195
}

196 197
audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
  if (err) {
G
Gloria 已提交
198
    console.error(`AudioCapturer Created : Error: ${err}`);
199
  } else {
G
Gloria 已提交
200
    console.info('AudioCapturer Created : Success : SUCCESS');
201 202
    let audioCapturer = data;
  }
203 204 205
});
```

206
## audio.createAudioCapturer<sup>8+</sup>
207

208
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
209

210
Creates an **AudioCapturer** instance. This API uses a promise to return the result.
W
wusongqing 已提交
211 212

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

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

W
wusongqing 已提交
216
**Parameters**
217

W
wusongqing 已提交
218 219 220
| Name | Type                                          | Mandatory| Description            |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
221

W
wusongqing 已提交
222
**Return value**
V
Vaidegi B 已提交
223

W
wusongqing 已提交
224 225 226
| Type                                     | Description          |
| ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
V
Vaidegi B 已提交
227

W
wusongqing 已提交
228
**Example**
V
Vaidegi B 已提交
229

G
Gloria 已提交
230
```js
231 232
import audio from '@ohos.multimedia.audio';

233
let audioStreamInfo = {
234 235 236 237
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
238 239
}

240
let audioCapturerInfo = {
241 242
  source: audio.SourceType.SOURCE_TYPE_MIC,
  capturerFlags: 0
243 244
}

245
let audioCapturerOptions = {
246 247
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
248
}
V
Vaidegi B 已提交
249

250
let audioCapturer;
W
wusongqing 已提交
251
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
252
  audioCapturer = data;
G
Gloria 已提交
253
  console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
254
}).catch((err) => {
G
Gloria 已提交
255
  console.error(`AudioCapturer Created : ERROR : ${err}`);
256
});
257
```
V
Vaidegi B 已提交
258

259 260 261 262 263 264 265 266
## audio.createTonePlayer<sup>9+</sup>

createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback&lt;TonePlayer&gt;): void

Creates a **TonePlayer** instance. This API uses an asynchronous callback to return the result.

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

267 268
**System API**: This is a system API.

269 270 271 272 273 274 275 276 277 278 279 280
**Parameters**

| Name  | Type                                            | Mandatory| Description           |
| -------- | ----------------------------------------------- | ---- | -------------- |
| options  | [AudioRendererInfo](#audiorendererinfo8)        | Yes  | Audio renderer information.|
| callback | AsyncCallback<[TonePlayer](#toneplayer9)>       | Yes  | Callback used to return the **TonePlayer** instance.|

**Example**

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

281
let audioRendererInfo = {
282 283 284 285
  "contentType": audio.ContentType.CONTENT_TYPE_MUSIC,
  "streamUsage": audio.StreamUsage.STREAM_USAGE_MEDIA,
  "rendererFlags": 0
}
286
let tonePlayer;
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

audio.createTonePlayer(audioRendererInfo, (err, data) => {
  console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
  if (err) {
    console.error(`callback call createTonePlayer return error: ${err.message}`);
  } else {
    console.info(`callback call createTonePlayer return data: ${data}`);
    tonePlayer = data;
  }
});
```

## audio.createTonePlayer<sup>9+</sup>

createTonePlayer(options: AudioRendererInfo): Promise&lt;TonePlayer&gt;

Creates a **TonePlayer** instance. This API uses a promise to return the result.

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

307 308
**System API**: This is a system API.

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
**Parameters**

| Name | Type                                          | Mandatory| Description        |
| :------ | :---------------------------------------------| :--- | :----------- |
| options | [AudioRendererInfo](#audiorendererinfo8)      | Yes  | Audio renderer information.|

**Return value**

| Type                                     | Description                            |
| ----------------------------------------- | -------------------------------- |
| Promise<[TonePlayer](#toneplayer9)>       | Promise used to return the **TonePlayer** instance.  |

**Example**

```js
import audio from '@ohos.multimedia.audio';
async function createTonePlayer(){
326
  let audioRendererInfo = {
327 328 329 330
    "contentType": audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage": audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags": 0
  }
331
  let tonePlayer = await audio.createTonePlayer(audioRendererInfo);
332 333 334
}
```

335
## AudioVolumeType
W
wusongqing 已提交
336

W
wusongqing 已提交
337
Enumerates the audio stream types.
W
wusongqing 已提交
338

W
wusongqing 已提交
339 340 341 342 343 344 345 346
**System capability**: SystemCapability.Multimedia.Audio.Volume

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
| RINGTONE                     | 2      | Audio stream for ringtones.    |
| MEDIA                        | 3      | Audio stream for media purpose.    |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
347 348 349 350 351 352 353 354 355 356 357 358 359 360
| ALL<sup>9+</sup>             | 100    | All public audio streams.<br>This is a system API.|

## InterruptRequestResultType<sup>9+</sup>

Enumerates the result types of audio interruption requests.

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

**System API**: This is a system API.

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| INTERRUPT_REQUEST_GRANT      | 0      | The audio interruption request is accepted.|
| INTERRUPT_REQUEST_REJECT     | 1      | The audio interruption request is denied. There may be a stream with a higher priority.|
V
Vaidegi B 已提交
361

W
wusongqing 已提交
362 363 364 365
## InterruptMode<sup>9+</sup>

Enumerates the audio interruption modes.

366
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
W
wusongqing 已提交
367 368 369

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
370 371
| SHARE_MODE                   | 0      | Shared mode.|
| INDEPENDENT_MODE             | 1      | Independent mode.|
W
wusongqing 已提交
372

373
## DeviceFlag
W
wusongqing 已提交
374

W
wusongqing 已提交
375
Enumerates the audio device flags.
W
wusongqing 已提交
376

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

G
Gloria 已提交
379 380
| Name                           | Default Value | Description                                             |
| ------------------------------- | ------ | ------------------------------------------------- |
381
| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | No device.<br>This is a system API.       |
G
Gloria 已提交
382 383 384
| OUTPUT_DEVICES_FLAG             | 1      | Output device.|
| INPUT_DEVICES_FLAG              | 2      | Input device.|
| ALL_DEVICES_FLAG                | 3      | All devices.|
385 386 387
| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | Distributed output device.<br>This is a system API. |
| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | Distributed input device.<br>This is a system API. |
| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | Distributed input and output device.<br>This is a system API. |
388 389

## DeviceRole
W
wusongqing 已提交
390

W
wusongqing 已提交
391 392 393
Enumerates the audio device roles.

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

W
wusongqing 已提交
395 396 397 398
| Name         | Default Value| Description          |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
399

400
## DeviceType
W
wusongqing 已提交
401

W
wusongqing 已提交
402
Enumerates the audio device types.
W
wusongqing 已提交
403

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

G
Gloria 已提交
406 407 408 409 410 411 412 413 414 415 416 417
| Name                | Default Value| Description                                                     |
| ---------------------| ------ | --------------------------------------------------------- |
| INVALID              | 0      | Invalid device.                                               |
| EARPIECE             | 1      | Earpiece.                                                   |
| SPEAKER              | 2      | Speaker.                                                 |
| WIRED_HEADSET        | 3      | Wired headset with a microphone.                                     |
| WIRED_HEADPHONES     | 4      | Wired headset without microphone.                                     |
| BLUETOOTH_SCO        | 7      | Bluetooth device using Synchronous Connection Oriented (SCO) links.     |
| BLUETOOTH_A2DP       | 8      | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
| MIC                  | 15     | Microphone.                                                 |
| USB_HEADSET          | 22     | USB Type-C headset.                                      |
| DEFAULT<sup>9+</sup> | 1000   | Default device type.                                           |
Z
zengyawen 已提交
418

419
## CommunicationDeviceType<sup>9+</sup>
V
Vaidegi B 已提交
420

421
Enumerates the device types used for communication.
W
wusongqing 已提交
422

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

425 426 427
| Name         | Default Value| Description         |
| ------------- | ------ | -------------|
| SPEAKER       | 2      | Speaker.     |
W
wusongqing 已提交
428 429

## AudioRingMode
W
wusongqing 已提交
430

W
wusongqing 已提交
431
Enumerates the ringer modes.
W
wusongqing 已提交
432

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

W
wusongqing 已提交
435 436 437 438 439
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | Silent mode.|
| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
| RINGER_MODE_NORMAL  | 2      | Normal mode.|
440 441

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

443
Enumerates the audio sample formats.
V
Vaidegi B 已提交
444

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

447 448 449 450 451 452 453 454
| 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.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_S32LE                | 3      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
455

456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
## AudioErrors<sup>9+</sup>

Enumerates the audio error codes.

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

| Error Message             | Error Code  | Error Description         |
| ---------------------| --------| ----------------- |
| ERROR_INVALID_PARAM  | 6800101 | Invalid parameter.        |
| ERROR_NO_MEMORY      | 6800102 | Memory allocation failure.    |
| ERROR_ILLEGAL_STATE  | 6800103 | Unsupported state.      |
| ERROR_UNSUPPORTED    | 6800104 | Unsupported parameter value. |
| ERROR_TIMEOUT        | 6800105 | Processing timeout.        |
| ERROR_STREAM_LIMIT   | 6800201 | Too many audio streams.|
| ERROR_SYSTEM         | 6800301 | System error. |

472
## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
473 474 475

Enumerates the audio channels.

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

W
wusongqing 已提交
478 479 480 481
| Name     | Default Value  | Description    |
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
482 483

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
484 485 486

Enumerates the audio sampling rates.

W
wusongqing 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
**System capability**: SystemCapability.Multimedia.Audio.Core

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

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

V
Vaidegi B 已提交
505 506
Enumerates the audio encoding types.

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

W
wusongqing 已提交
509 510 511 512
| Name                 | Default Value| Description     |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
513

514 515
## ContentType

W
wusongqing 已提交
516
Enumerates the audio content types.
517

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

W
wusongqing 已提交
520 521 522 523 524 525 526 527
| Name                              | Default Value| Description      |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
| CONTENT_TYPE_SONIFICATION          | 4      | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
V
Vaidegi B 已提交
528

529 530
## StreamUsage

W
wusongqing 已提交
531
Enumerates the audio stream usage.
V
Vaidegi B 已提交
532

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

535 536 537 538 539 540 541
| Name                                     | Default Value| Description      |
| ------------------------------------------| ------ | ---------- |
| STREAM_USAGE_UNKNOWN                      | 0      | Unknown usage.|
| STREAM_USAGE_MEDIA                        | 1      | Used for media.    |
| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | Used for voice communication.|
| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | Used for voice assistant.|
| STREAM_USAGE_NOTIFICATION_RINGTONE        | 6      | Used for notification.|
V
Vaidegi B 已提交
542

543
## InterruptRequestType<sup>9+</sup>
544

545
Enumerates the audio interruption request types.
546

G
Gloria 已提交
547 548
**System API**: This is a system API.

549
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
550

551 552 553
| Name                              | Default Value | Description                      |
| ---------------------------------- | ------ | ------------------------- |
| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  Default type, which can be used to interrupt audio requests. |
554

555 556
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
557 558
Enumerates the audio states.

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

W
wusongqing 已提交
561 562 563 564 565 566 567 568 569
| Name          | Default Value| Description            |
| -------------- | ------ | ---------------- |
| STATE_INVALID  | -1     | Invalid state.      |
| STATE_NEW      | 0      | Creating instance state.|
| STATE_PREPARED | 1      | Prepared.      |
| STATE_RUNNING  | 2      | Running.    |
| STATE_STOPPED  | 3      | Stopped.      |
| STATE_RELEASED | 4      | Released.      |
| STATE_PAUSED   | 5      | Paused.      |
V
Vaidegi B 已提交
570

571 572
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
573 574
Enumerates the audio renderer rates.

W
wusongqing 已提交
575
**System capability**: SystemCapability.Multimedia.Audio.Renderer
576

W
wusongqing 已提交
577 578 579 580 581
| 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 已提交
582

583
## InterruptType
V
Vaidegi B 已提交
584

W
wusongqing 已提交
585
Enumerates the audio interruption types.
V
Vaidegi B 已提交
586

W
wusongqing 已提交
587
**System capability**: SystemCapability.Multimedia.Audio.Renderer
588

W
wusongqing 已提交
589 590 591 592
| Name                | Default Value| Description                  |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
593 594

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

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

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

W
wusongqing 已提交
600 601 602 603
| Name           | Default Value| Description                                |
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
604 605

## InterruptHint
V
Vaidegi B 已提交
606

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

W
wusongqing 已提交
609
**System capability**: SystemCapability.Multimedia.Audio.Renderer
610

W
wusongqing 已提交
611 612 613 614 615 616 617 618
| Name                              | Default Value| Description                                        |
| ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | None.                                    |
| INTERRUPT_HINT_RESUME              | 1      | Resume the playback.                              |
| INTERRUPT_HINT_PAUSE               | 2      | Paused/Pause the playback.                              |
| INTERRUPT_HINT_STOP                | 3      | Stopped/Stop the playback.                              |
| INTERRUPT_HINT_DUCK                | 4      | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | Unducked the playback.                              |
619 620

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

622
Describes audio stream information.
V
Vaidegi B 已提交
623

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

626 627 628 629 630 631
| Name        | Type                                              | Mandatory| Description              |
| ------------ | ------------------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | Yes  | Audio sampling rate.|
| channels     | [AudioChannel](#audiochannel8)                    | Yes  | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | Yes  | Audio sample format.    |
| encodingType | [AudioEncodingType](#audioencodingtype8)          | Yes  | Audio encoding type.    |
632 633

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
634 635 636

Describes audio renderer information.

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

W
wusongqing 已提交
639 640 641 642 643
| Name         | Type                       | Mandatory| Description            |
| ------------- | --------------------------- | ---- | ---------------- |
| content       | [ContentType](#contenttype) | Yes  | Audio content type.      |
| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
| rendererFlags | number                      | Yes  | Audio renderer flags.|
V
Vaidegi B 已提交
644

645 646 647 648 649 650 651 652 653 654 655 656 657
## InterruptResult<sup>9+</sup>

Describes the audio interruption result.

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

**System API**: This is a system API.

| Name         | Type                                                           | Mandatory| Description            |
| --------------| -------------------------------------------------------------- | ---- | ---------------- |
| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9)     | Yes  | Audio interruption request type.|
| interruptNode | number                                                         | Yes  | Node to interrupt.|

658
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
659

W
wusongqing 已提交
660
Describes audio renderer configurations.
661

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

W
wusongqing 已提交
664 665 666 667
| Name        | Type                                    | Mandatory| Description            |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
668

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

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

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

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

W
wusongqing 已提交
681
## VolumeEvent<sup>8+</sup>
V
Vaidegi B 已提交
682

W
wusongqing 已提交
683
Describes the event received by the application when the volume is changed.
V
Vaidegi B 已提交
684

G
Gloria 已提交
685
**System API**: This is a system API.
686

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

W
wusongqing 已提交
689 690 691
| Name      | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
692
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
W
wusongqing 已提交
693
| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                    |
G
Gloria 已提交
694 695 696
| volumeGroupId<sup>9+</sup>   | number            | Yes  | Volume group ID. It can be used as an input parameter of **getGroupManager**.                     |
| networkId<sup>9+</sup>    | string               | Yes  | Network ID.                                               |

697 698 699 700 701 702 703 704 705 706
## MicStateChangeEvent<sup>9+</sup>

Describes the event received by the application when the microphone mute status changes.

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

| Name      | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| mute | boolean | Yes  | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.         |

G
Gloria 已提交
707 708 709 710
## ConnectType<sup>9+</sup>

Enumerates the types of connected devices.

711 712
**System API**: This is a system API.

713
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
714 715 716 717 718 719

| Name                           | Default Value| Description                  |
| :------------------------------ | :----- | :--------------------- |
| CONNECT_TYPE_LOCAL              | 1      | Local device.        |
| CONNECT_TYPE_DISTRIBUTED        | 2      | Distributed device.           |

720 721 722 723 724 725 726 727
## VolumeGroupInfos<sup>9+</sup>

Describes the volume group information. The value is an array of [VolumeGroupInfo](#volumegroupinfo9) and is read-only.

**System API**: This is a system API.

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

G
Gloria 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741
## VolumeGroupInfo<sup>9+</sup>

Describes the volume group information.

**System API**: This is a system API.

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

| Name                       | Type                      | Readable| Writable| Description      |
| -------------------------- | -------------------------- | ---- | ---- | ---------- |
| networkId<sup>9+</sup>     | string                     | Yes  | No  | Network ID of the device. |
| groupId<sup>9+</sup>       | number                     | Yes  | No  | Group ID of the device.|
| mappingId<sup>9+</sup>     | number                     | Yes  | No  | Group mapping ID.|
| groupName<sup>9+</sup>     | number                     | Yes  | No  | Group name.|
742
| type<sup>9+</sup>          | [ConnectType](#connecttype9)| Yes  | No  | Type of the connected device.|
G
Gloria 已提交
743

W
wusongqing 已提交
744
## DeviceChangeAction
745

W
wusongqing 已提交
746
Describes the device connection status and device information.
747

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

W
wusongqing 已提交
750 751
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
752
| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
W
wusongqing 已提交
753
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
V
Vaidegi B 已提交
754

W
wusongqing 已提交
755
## DeviceChangeType
756

W
wusongqing 已提交
757
Enumerates the device connection statuses.
V
Vaidegi B 已提交
758

W
wusongqing 已提交
759
**System capability**: SystemCapability.Multimedia.Audio.Device
V
Vaidegi B 已提交
760

W
wusongqing 已提交
761 762 763 764
| Name      | Default Value| Description          |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
765

W
wusongqing 已提交
766
## AudioCapturerOptions<sup>8+</sup>
767

W
wusongqing 已提交
768
Describes audio capturer configurations.
769

W
wusongqing 已提交
770
**System capability**: SystemCapability.Multimedia.Audio.Capturer
771

W
wusongqing 已提交
772 773 774 775
| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|
776

W
wusongqing 已提交
777
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
778

W
wusongqing 已提交
779
Describes audio capturer information.
780

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

W
wusongqing 已提交
783 784 785 786
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
787 788

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

W
wusongqing 已提交
790
Enumerates the audio source types.
791

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

794 795 796 797 798 799
| Name                                        | Default Value| Description                  |
| :------------------------------------------- | :----- | :--------------------- |
| SOURCE_TYPE_INVALID                          | -1     | Invalid audio source.        |
| SOURCE_TYPE_MIC                              | 0      | Mic source.           |
| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | Voice recognition source.       |
| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | Voice communication source.|
800 801

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

W
wusongqing 已提交
803
Enumerates the audio scenes.
804

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

W
wusongqing 已提交
807 808 809
| Name                  | Default Value| Description                                         |
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
810 811
| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API.|
| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API.|
W
wusongqing 已提交
812
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
813

814
## AudioManager
W
wusongqing 已提交
815

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

818 819 820
### setAudioParameter

setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
821

822
Sets an audio parameter. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
823

824
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.
G
Gloria 已提交
825

826 827 828
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

**System capability**: SystemCapability.Multimedia.Audio.Core
G
Gloria 已提交
829 830 831

**Parameters**

832 833 834 835 836
| Name  | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
| key      | string                    | Yes  | Key of the audio parameter to set.  |
| value    | string                    | Yes  | Value of the audio parameter to set.  |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
G
Gloria 已提交
837 838

**Example**
839

G
Gloria 已提交
840
```js
841
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
G
Gloria 已提交
842
  if (err) {
843 844
    console.error(`Failed to set the audio parameter. ${err}`);
    return;
G
Gloria 已提交
845
  }
846
  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
G
Gloria 已提交
847 848 849
});
```

850
### setAudioParameter
G
Gloria 已提交
851

852
setAudioParameter(key: string, value: string): Promise&lt;void&gt;
G
Gloria 已提交
853

854
Sets an audio parameter. This API uses a promise to return the result.
G
Gloria 已提交
855

856 857 858 859 860 861 862 863 864 865 866 867
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

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

**Parameters**

| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
G
Gloria 已提交
868 869 870

**Return value**

871 872 873
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
874 875

**Example**
876

G
Gloria 已提交
877
```js
878 879 880
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
  console.info('Promise returned to indicate a successful setting of the audio parameter.');
});
G
Gloria 已提交
881 882
```

883
### getAudioParameter
884

885
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
886

887
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
888

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

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

W
wusongqing 已提交
893
**Parameters**
894

895 896 897 898
| Name  | Type                       | Mandatory| Description                        |
| -------- | --------------------------- | ---- | ---------------------------- |
| key      | string                      | Yes  | Key of the audio parameter whose value is to be obtained.      |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the value of the audio parameter.|
899

W
wusongqing 已提交
900
**Example**
W
wusongqing 已提交
901

G
Gloria 已提交
902
```js
903
audioManager.getAudioParameter('key_example', (err, value) => {
904
  if (err) {
905
    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
906 907
    return;
  }
908
  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
909
});
W
wusongqing 已提交
910
```
W
wusongqing 已提交
911

912
### getAudioParameter
913

914
getAudioParameter(key: string): Promise&lt;string&gt;
915

916
Obtains the value of an audio parameter. This API uses a promise to return the result.
G
Gloria 已提交
917

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

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

W
wusongqing 已提交
922
**Parameters**
923

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

W
wusongqing 已提交
928
**Return value**
929

930 931 932
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
933

W
wusongqing 已提交
934
**Example**
W
wusongqing 已提交
935

G
Gloria 已提交
936
```js
937 938
audioManager.getAudioParameter('key_example').then((value) => {
  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
939 940 941
});
```

942
### setAudioScene<sup>8+</sup>
W
wusongqing 已提交
943

944
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
W
wusongqing 已提交
945

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

948 949 950
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Communication
951

W
wusongqing 已提交
952
**Parameters**
953

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

W
wusongqing 已提交
959
**Example**
W
wusongqing 已提交
960

G
Gloria 已提交
961
```js
962 963
let audioManager = audio.getAudioManager();
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
964
  if (err) {
965
    console.error(`Failed to set the audio scene mode.​ ${err}`);
966 967
    return;
  }
968
  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
969
});
W
wusongqing 已提交
970 971
```

972
### setAudioScene<sup>8+</sup>
V
Vaidegi B 已提交
973

974
setAudioScene\(scene: AudioScene\): Promise<void\>
W
wusongqing 已提交
975

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

978 979 980
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Communication
981

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

984 985 986
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
W
wusongqing 已提交
987

W
wusongqing 已提交
988
**Return value**
989

990 991 992
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
W
wusongqing 已提交
993

W
wusongqing 已提交
994
**Example**
W
wusongqing 已提交
995

G
Gloria 已提交
996
```js
997 998 999 1000 1001
let audioManager = audio.getAudioManager();
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
  console.info('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => {
  console.error(`Failed to set the audio scene mode ${err}`);
1002 1003 1004
});
```

1005
### getAudioScene<sup>8+</sup>
1006

1007
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1008

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

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

W
wusongqing 已提交
1013
**Parameters**
W
wusongqing 已提交
1014

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

**Example**
W
wusongqing 已提交
1020

G
Gloria 已提交
1021
```js
1022 1023
let audioManager = audio.getAudioManager();
audioManager.getAudioScene((err, value) => {
1024
  if (err) {
1025
    console.error(`Failed to obtain the audio scene mode.​ ${err}`);
1026 1027
    return;
  }
1028
  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1029
});
W
wusongqing 已提交
1030 1031
```

1032
### getAudioScene<sup>8+</sup>
W
wusongqing 已提交
1033

1034
getAudioScene\(\): Promise<AudioScene\>
W
wusongqing 已提交
1035

1036
Obtains the audio scene. This API uses a promise to return the result.
1037

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

W
wusongqing 已提交
1040
**Return value**
W
wusongqing 已提交
1041

1042 1043 1044
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
W
wusongqing 已提交
1045

W
wusongqing 已提交
1046
**Example**
1047

G
Gloria 已提交
1048
```js
1049 1050 1051 1052 1053
let audioManager = audio.getAudioManager();
audioManager.getAudioScene().then((value) => {
  console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
}).catch ((err) => {
  console.error(`Failed to obtain the audio scene mode ${err}`);
1054 1055 1056
});
```

1057
### getVolumeManager<sup>9+</sup>
1058

1059
getVolumeManager(): AudioVolumeManager
1060

1061
Obtains an **AudioVolumeManager** instance.
1062

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

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

G
Gloria 已提交
1067
```js
1068
let audioVolumeManager = audioManager.getVolumeManager();
W
wusongqing 已提交
1069 1070
```

1071
### getStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1072

1073
getStreamManager(): AudioStreamManager
W
wusongqing 已提交
1074

1075
Obtains an **AudioStreamManager** instance.
W
wusongqing 已提交
1076

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

1079
**Example**
W
wusongqing 已提交
1080

1081 1082 1083
```js
let audioStreamManager = audioManager.getStreamManager();
```
W
wusongqing 已提交
1084

1085
### getRoutingManager<sup>9+</sup>
1086

1087 1088 1089 1090 1091
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

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

G
Gloria 已提交
1095
```js
1096
let audioRoutingManager = audioManager.getRoutingManager();
W
wusongqing 已提交
1097 1098
```

1099
## AudioVolumeManager<sup>9+</sup>
V
Vaidegi B 已提交
1100

1101
Implements audio volume management. Before calling an API in **AudioVolumeManager**, you must use [getVolumeManager](#getvolumemanager9) to obtain an **AudioVolumeManager** instance.
W
wusongqing 已提交
1102

1103
### getVolumeGroupInfos<sup>9+</sup>
W
wusongqing 已提交
1104

1105
getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void
G
Gloria 已提交
1106

1107 1108 1109
Obtains the volume groups. This API uses an asynchronous callback to return the result.

**System API**: This is a system API.
1110

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

W
wusongqing 已提交
1113
**Parameters**
W
wusongqing 已提交
1114

1115 1116 1117 1118
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| networkId | string                                    | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.   |
| callback  | AsyncCallback&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Yes  | Callback used to return the volume group information array.|
1119

W
wusongqing 已提交
1120
**Example**
G
Gloria 已提交
1121
```js
1122
audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err, value) => {
1123
  if (err) {
1124
    console.error(`Failed to obtain the volume group infos list. ${err}`);
1125 1126
    return;
  }
1127
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
1128
});
W
wusongqing 已提交
1129 1130
```

1131
### getVolumeGroupInfos<sup>9+</sup>
W
wusongqing 已提交
1132

1133
getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
V
Vaidegi B 已提交
1134

1135
Obtains the volume groups. This API uses a promise to return the result.
G
Gloria 已提交
1136

1137
**System API**: This is a system API.
1138

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

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

1143 1144 1145
| Name    | Type              | Mandatory| Description                |
| ---------- | ------------------| ---- | -------------------- |
| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
1146

W
wusongqing 已提交
1147
**Return value**
W
wusongqing 已提交
1148

W
wusongqing 已提交
1149 1150
| Type               | Description                         |
| ------------------- | ----------------------------- |
1151
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
1152

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

G
Gloria 已提交
1155
```js
1156 1157 1158 1159
async function getVolumeGroupInfos(){
  let volumegroupinfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
}
W
wusongqing 已提交
1160 1161
```

1162
### getVolumeGroupManager<sup>9+</sup>
V
Vaidegi B 已提交
1163

1164
getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
W
wusongqing 已提交
1165

1166
Obtains the audio group manager. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1167

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

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

1172 1173 1174 1175
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| groupId    | number                                    | Yes  | Volume group ID.    |
| callback   | AsyncCallback&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Yes  | Callback used to return the audio group manager.|
1176

W
wusongqing 已提交
1177
**Example**
W
wusongqing 已提交
1178

G
Gloria 已提交
1179
```js
1180 1181
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
audioVolumeManager.getVolumeGroupManager(groupid, (err, value) => {
1182
  if (err) {
1183
    console.error(`Failed to obtain the volume group infos list. ${err}`);
1184 1185
    return;
  }
1186
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
1187
});
W
wusongqing 已提交
1188

1189
```
W
wusongqing 已提交
1190

1191
### getVolumeGroupManager<sup>9+</sup>
V
Vaidegi B 已提交
1192

1193
getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
V
Vaidegi B 已提交
1194

1195
Obtains the audio group manager. This API uses a promise to return the result.
W
wusongqing 已提交
1196

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

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

1201 1202 1203
| Name    | Type                                     | Mandatory| Description             |
| ---------- | ---------------------------------------- | ---- | ---------------- |
| groupId    | number                                   | Yes  | Volume group ID.    |
1204

W
wusongqing 已提交
1205
**Return value**
1206

1207 1208 1209
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the audio group manager.|
1210

W
wusongqing 已提交
1211
**Example**
W
wusongqing 已提交
1212

G
Gloria 已提交
1213
```js
1214 1215 1216
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
let audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
console.info('Callback invoked to indicate that the volume group infos list is obtained.');
W
wusongqing 已提交
1217 1218
```

1219
### on('volumeChange')<sup>9+</sup>
V
Vaidegi B 已提交
1220

1221
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
W
wusongqing 已提交
1222

1223
Subscribes to system volume change events. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1224

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

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

1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when the system volume changes.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |
1241

W
wusongqing 已提交
1242
**Example**
W
wusongqing 已提交
1243

G
Gloria 已提交
1244
```js
1245 1246 1247 1248
audioVolumeManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
1249
});
W
wusongqing 已提交
1250 1251
```

1252
## AudioVolumeGroupManager<sup>9+</sup>
V
Vaidegi B 已提交
1253

1254
Manages the volume of an audio group. Before calling any API in **AudioVolumeGroupManager**, you must use [getVolumeGroupManager](#getvolumegroupmanager9) to obtain an **AudioVolumeGroupManager** instance.
W
wusongqing 已提交
1255

1256
**System API**: This is a system API.
W
wusongqing 已提交
1257

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

1260
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
1261

1262
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1263

1264
Sets the volume for a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1265

G
Gloria 已提交
1266 1267
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

1268
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1269

1270 1271 1272
**System API**: This is a system API.

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

W
wusongqing 已提交
1274
**Parameters**
W
wusongqing 已提交
1275

1276 1277 1278 1279 1280
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
1281

W
wusongqing 已提交
1282
**Example**
W
wusongqing 已提交
1283

G
Gloria 已提交
1284
```js
1285
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
1286
  if (err) {
1287
    console.error(`Failed to set the volume. ${err}`);
1288 1289
    return;
  }
1290
  console.info('Callback invoked to indicate a successful volume setting.');
1291
});
W
wusongqing 已提交
1292 1293
```

1294
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
1295

1296
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
1297

1298
Sets the volume for a stream. This API uses a promise to return the result.
W
wusongqing 已提交
1299

G
Gloria 已提交
1300 1301
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

1302
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
1303

1304 1305 1306
**System API**: This is a system API.

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

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

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

W
wusongqing 已提交
1315
**Return value**
1316

1317 1318
| Type               | Description                         |
| ------------------- | ----------------------------- |
W
wusongqing 已提交
1319
| Promise&lt;void&gt; | Promise used to return the result.|
1320

W
wusongqing 已提交
1321
**Example**
W
wusongqing 已提交
1322

G
Gloria 已提交
1323
```js
1324 1325
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.info('Promise returned to indicate a successful volume setting.');
1326
});
W
wusongqing 已提交
1327 1328
```

1329
### getVolume<sup>9+</sup>
V
Vaidegi B 已提交
1330

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

1333
Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
1334

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

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

1339 1340 1341 1342 1343 1344
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|

**Example**
W
wusongqing 已提交
1345

G
Gloria 已提交
1346
```js
1347
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1348
  if (err) {
1349
    console.error(`Failed to obtain the volume. ${err}`);
1350 1351
    return;
  }
1352
  console.info('Callback invoked to indicate that the volume is obtained.');
1353
});
W
wusongqing 已提交
1354 1355
```

1356
### getVolume<sup>9+</sup>
V
Vaidegi B 已提交
1357

1358
getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
V
Vaidegi B 已提交
1359

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

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

1364 1365 1366 1367 1368
**Parameters**

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

W
wusongqing 已提交
1370
**Return value**
W
wusongqing 已提交
1371

1372 1373 1374
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
1375

W
wusongqing 已提交
1376
**Example**
W
wusongqing 已提交
1377

G
Gloria 已提交
1378
```js
1379 1380
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
1381
});
W
wusongqing 已提交
1382 1383
```

1384
### getMinVolume<sup>9+</sup>
1385

1386
getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
M
magekkkk 已提交
1387

1388
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
1389

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

W
wusongqing 已提交
1392
**Parameters**
W
wusongqing 已提交
1393

1394 1395 1396 1397
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
W
wusongqing 已提交
1398

W
wusongqing 已提交
1399
**Example**
W
wusongqing 已提交
1400

G
Gloria 已提交
1401
```js
1402
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1403
  if (err) {
1404
    console.error(`Failed to obtain the minimum volume. ${err}`);
1405 1406
    return;
  }
1407
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1408
});
W
wusongqing 已提交
1409 1410
```

1411
### getMinVolume<sup>9+</sup>
W
wusongqing 已提交
1412

1413
getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
M
magekkkk 已提交
1414

1415
Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
1416

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

W
wusongqing 已提交
1419
**Parameters**
W
wusongqing 已提交
1420

1421 1422 1423
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1424

W
wusongqing 已提交
1425
**Return value**
1426

1427 1428 1429
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
1430

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

G
Gloria 已提交
1433
```js
1434 1435
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
1436
});
W
wusongqing 已提交
1437 1438
```

1439
### getMaxVolume<sup>9+</sup>
W
wusongqing 已提交
1440

1441
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1442

1443
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
M
magekkkk 已提交
1444

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

W
wusongqing 已提交
1447
**Parameters**
W
wusongqing 已提交
1448

1449 1450 1451 1452
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
W
wusongqing 已提交
1453

W
wusongqing 已提交
1454
**Example**
W
wusongqing 已提交
1455

G
Gloria 已提交
1456
```js
1457
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1458
  if (err) {
1459
    console.error(`Failed to obtain the maximum volume. ${err}`);
1460 1461
    return;
  }
1462
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1463
});
W
wusongqing 已提交
1464 1465
```

1466
### getMaxVolume<sup>9+</sup>
W
wusongqing 已提交
1467

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

1470
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
M
magekkkk 已提交
1471

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

W
wusongqing 已提交
1474
**Parameters**
1475

1476 1477 1478
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1479

W
wusongqing 已提交
1480
**Return value**
W
wusongqing 已提交
1481

1482 1483 1484
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
1485

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

G
Gloria 已提交
1488
```js
1489 1490
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.info('Promised returned to indicate that the maximum volume is obtained.');
1491
});
W
wusongqing 已提交
1492 1493
```

1494
### mute<sup>9+</sup>
1495

1496
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1497

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

1500 1501 1502 1503 1504 1505 1506
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

**System API**: This is a system API.

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

W
wusongqing 已提交
1508
**Parameters**
W
wusongqing 已提交
1509

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

W
wusongqing 已提交
1516
**Example**
1517

G
Gloria 已提交
1518
```js
1519
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
1520
  if (err) {
1521
    console.error(`Failed to mute the stream. ${err}`);
1522 1523
    return;
  }
1524
  console.info('Callback invoked to indicate that the stream is muted.');
1525
});
W
wusongqing 已提交
1526 1527
```

1528
### mute<sup>9+</sup>
V
Vaidegi B 已提交
1529

1530
mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
W
wusongqing 已提交
1531

1532
Mutes or unmutes a stream. This API uses a promise to return the result.
W
wusongqing 已提交
1533

1534 1535 1536 1537 1538 1539 1540
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

**System API**: This is a system API.

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

W
wusongqing 已提交
1542
**Parameters**
W
wusongqing 已提交
1543

1544 1545 1546 1547
| 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 已提交
1548

W
wusongqing 已提交
1549
**Return value**
1550

1551 1552 1553
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1554

W
wusongqing 已提交
1555
**Example**
W
wusongqing 已提交
1556

G
Gloria 已提交
1557
```js
1558 1559
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.info('Promise returned to indicate that the stream is muted.');
1560
});
W
wusongqing 已提交
1561 1562
```

1563
### isMute<sup>9+</sup>
V
Vaidegi B 已提交
1564

1565
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
V
Vaidegi B 已提交
1566

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

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

W
wusongqing 已提交
1571
**Parameters**
W
wusongqing 已提交
1572

1573 1574 1575 1576
| Name    | Type                               | Mandatory| Description                                           |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
1577

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

G
Gloria 已提交
1580
```js
1581
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
1582
  if (err) {
1583
    console.error(`Failed to obtain the mute status. ${err}`);
1584 1585
    return;
  }
1586
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
1587
});
W
wusongqing 已提交
1588 1589
```

1590
### isMute<sup>9+</sup>
V
Vaidegi B 已提交
1591

1592
isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
V
Vaidegi B 已提交
1593

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

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

W
wusongqing 已提交
1598
**Parameters**
1599

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

W
wusongqing 已提交
1604
**Return value**
1605

1606 1607 1608
| Type                  | Description                                                  |
| ---------------------- | ------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
1609

W
wusongqing 已提交
1610
**Example**
1611

G
Gloria 已提交
1612
```js
1613 1614
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1615
});
W
wusongqing 已提交
1616 1617
```

1618
### setRingerMode<sup>9+</sup>
V
Vaidegi B 已提交
1619

1620
setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
W
wusongqing 已提交
1621

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

1624 1625 1626 1627 1628 1629 1630
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer.

**System API**: This is a system API.

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

W
wusongqing 已提交
1632
**Parameters**
W
wusongqing 已提交
1633

1634 1635 1636 1637
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1638

W
wusongqing 已提交
1639
**Example**
W
wusongqing 已提交
1640

G
Gloria 已提交
1641
```js
1642
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
1643
  if (err) {
1644
    console.error(`Failed to set the ringer mode.​ ${err}`);
1645 1646
    return;
  }
1647
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1648
});
W
wusongqing 已提交
1649 1650
```

1651
### setRingerMode<sup>9+</sup>
V
Vaidegi B 已提交
1652

1653
setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
V
Vaidegi B 已提交
1654

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

1657
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
W
wusongqing 已提交
1658

1659 1660 1661 1662 1663
This permission is required only for muting or unmuting the ringer.

**System API**: This is a system API.

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

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

1667 1668 1669
| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1670

W
wusongqing 已提交
1671
**Return value**
1672

1673 1674 1675
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1676

W
wusongqing 已提交
1677
**Example**
W
wusongqing 已提交
1678

G
Gloria 已提交
1679
```js
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 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```

### getRingerMode<sup>9+</sup>

getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void

Obtains the ringer mode. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name  | Type                                                | Mandatory| Description                    |
| -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the ringer mode.|

**Example**

```js
audioVolumeGroupManager.getRingerMode((err, value) => {
  if (err) {
    console.error(`Failed to obtain the ringer mode.​ ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
});
```

### getRingerMode<sup>9+</sup>

getRingerMode(): Promise&lt;AudioRingMode&gt;

Obtains the ringer mode. This API uses a promise to return the result.

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

**Return value**

| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|

**Example**

```js
audioVolumeGroupManager.getRingerMode().then((value) => {
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1730
});
W
wusongqing 已提交
1731 1732
```

1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
### on('ringerModeChange')<sup>9+</sup>

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

Subscribes to ringer mode change events.

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

**Parameters**

| Name  | Type                                     | Mandatory| Description                                                        |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                    | Yes  | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the system volume change event.                                                  |

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |

**Example**

```js
audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
```
### setMicrophoneMute<sup>9+</sup>
V
Vaidegi B 已提交
1764

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

1767 1768
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

1769
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
1770

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

W
wusongqing 已提交
1773
**Parameters**
W
wusongqing 已提交
1774

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

W
wusongqing 已提交
1780
**Example**
W
wusongqing 已提交
1781

G
Gloria 已提交
1782
```js
1783
audioVolumeGroupManager.setMicrophoneMute(true, (err) => {
1784
  if (err) {
G
Gloria 已提交
1785
    console.error(`Failed to mute the microphone. ${err}`);
1786 1787
    return;
  }
G
Gloria 已提交
1788
  console.info('Callback invoked to indicate that the microphone is muted.');
1789
});
W
wusongqing 已提交
1790 1791
```

1792
### setMicrophoneMute<sup>9+</sup>
V
Vaidegi B 已提交
1793

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

1796 1797
Mutes or unmutes the microphone. This API uses a promise to return the result.

1798
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
1799

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

W
wusongqing 已提交
1802
**Parameters**
1803

W
wusongqing 已提交
1804 1805 1806
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1807

W
wusongqing 已提交
1808
**Return value**
W
wusongqing 已提交
1809

W
wusongqing 已提交
1810 1811 1812
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1813

W
wusongqing 已提交
1814
**Example**
W
wusongqing 已提交
1815

G
Gloria 已提交
1816
```js
1817
audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
G
Gloria 已提交
1818
  console.info('Promise returned to indicate that the microphone is muted.');
1819
});
W
wusongqing 已提交
1820 1821
```

1822
### isMicrophoneMute<sup>9+</sup>
V
Vaidegi B 已提交
1823

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

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

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

W
wusongqing 已提交
1830
**Parameters**
W
wusongqing 已提交
1831

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

W
wusongqing 已提交
1836
**Example**
W
wusongqing 已提交
1837

G
Gloria 已提交
1838
```js
1839
audioVolumeGroupManager.isMicrophoneMute((err, value) => {
1840
  if (err) {
G
Gloria 已提交
1841
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
1842 1843
    return;
  }
G
Gloria 已提交
1844
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
1845
});
W
wusongqing 已提交
1846 1847
```

1848
### isMicrophoneMute<sup>9+</sup>
V
Vaidegi B 已提交
1849

W
wusongqing 已提交
1850 1851 1852
isMicrophoneMute(): Promise&lt;boolean&gt;

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

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

W
wusongqing 已提交
1856
**Return value**
1857

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

W
wusongqing 已提交
1862
**Example**
W
wusongqing 已提交
1863

G
Gloria 已提交
1864
```js
1865
audioVolumeGroupManager.isMicrophoneMute().then((value) => {
G
Gloria 已提交
1866
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
1867
});
W
wusongqing 已提交
1868 1869
```

1870
### on('micStateChange')<sup>9+</sup>
W
wusongqing 已提交
1871

1872
on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void
V
Vaidegi B 已提交
1873

1874
Subscribes to system mic state change events.
1875

1876 1877
Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance.

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

W
wusongqing 已提交
1880
**Parameters**
V
Vaidegi B 已提交
1881

W
wusongqing 已提交
1882 1883
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893
| type     | string                                 | Yes  | Event type. The value **'micStateChange'** means the system mic state change event, which is triggered when the system mic state changes.|
| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | Yes  | Callback used to return the changed micr state.                                                  |

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |
V
Vaidegi B 已提交
1894

W
wusongqing 已提交
1895
**Example**
V
Vaidegi B 已提交
1896

G
Gloria 已提交
1897
```js
1898 1899
audioVolumeGroupManager.on('micStateChange', (micStateChange) => {
  console.info(`Current microphone status is: ${micStateChange.mute} `);
1900
});
V
Vaidegi B 已提交
1901 1902
```

1903
## AudioStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1904

1905
Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance.
V
Vaidegi B 已提交
1906

1907
### getCurrentAudioRendererInfoArray<sup>9+</sup>
1908

1909
getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
V
Vaidegi B 已提交
1910

1911 1912 1913
Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
1915
**Parameters**
V
Vaidegi B 已提交
1916

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

W
wusongqing 已提交
1921
**Example**
V
Vaidegi B 已提交
1922

G
Gloria 已提交
1923
```js
1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950
audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
  if (err) {
    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
  } else {
    if (AudioRendererChangeInfoArray != null) {
      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
        let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }
1951
});
V
Vaidegi B 已提交
1952 1953
```

1954
### getCurrentAudioRendererInfoArray<sup>9+</sup>
1955

1956
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
1957

1958
Obtains the information about the current audio renderer. This API uses a promise to return the result.
1959

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

1962
**Return value**
1963

1964 1965 1966
| Type                                                                             | Description                                   |
| ---------------------------------------------------------------------------------| --------------------------------------- |
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise used to return the audio renderer information.     |
1967

W
wusongqing 已提交
1968
**Example**
1969

G
Gloria 已提交
1970
```js
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
async function getCurrentAudioRendererInfoArray(){
  await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
    if (AudioRendererChangeInfoArray != null) {
      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
        let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }).catch((err) => {
    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
  });
}
1999 2000
```

2001
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
2002

2003
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
2004

2005
Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
2006

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

W
wusongqing 已提交
2009
**Parameters**
2010

2011 2012 2013
| Name      | Type                                | Mandatory     | Description                                                     |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes   | Callback used to return the audio capturer information.|
2014

W
wusongqing 已提交
2015
**Example**
2016

G
Gloria 已提交
2017
```js
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
  if (err) {
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
  } else {
    if (AudioCapturerChangeInfoArray != null) {
      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }
2043 2044 2045
});
```

2046
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
2047

2048
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
2049

2050
Obtains the information about the current audio capturer. This API uses a promise to return the result.
2051

W
wusongqing 已提交
2052
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2053

2054
**Return value**
2055

2056 2057 2058 2059 2060
| Type                                                                        | Description                                |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise used to return the audio capturer information. |

**Example**
2061

G
Gloria 已提交
2062
```js
2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
async function getCurrentAudioCapturerInfoArray(){
  await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
    if (AudioCapturerChangeInfoArray != null) {
      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }).catch((err) => {
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
  });
}
2089 2090
```

2091
### on('audioRendererChange')<sup>9+</sup>
2092

2093
on(type: "audioRendererChange", callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
2094

2095
Subscribes to audio renderer change events.
2096

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

W
wusongqing 已提交
2099
**Parameters**
2100

2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112
| Name    | Type       | Mandatory     | Description                                                                    |
| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
| type     | string     | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.    |
| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes |  Callback used to return the result.       |

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |
2113

W
wusongqing 已提交
2114
**Example**
2115

G
Gloria 已提交
2116
```js
2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
    let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
    console.info(`## RendererChange on is called for ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
    console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
    console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
    console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
    console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
    for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
    }
2137
  }
2138 2139 2140
});
```

2141
### off('audioRendererChange')<sup>9+</sup>
2142

2143
off(type: "audioRendererChange"): void
2144

2145
Unsubscribes from audio renderer change events.
2146

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

2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176
**Parameters**

| Name    | Type    | Mandatory| Description             |
| -------- | ------- | ---- | ---------------- |
| type     | string  | Yes  | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.|

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |

**Example**

```js
audioStreamManager.off('audioRendererChange');
console.info('######### RendererChange Off is called #########');
```

### on('audioCapturerChange')<sup>9+</sup>

on(type: "audioCapturerChange", callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void

Subscribes to audio capturer change events.

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

W
wusongqing 已提交
2178
**Parameters**
2179

2180 2181 2182 2183
| Name    | Type    | Mandatory     | Description                                                                                          |
| -------- | ------- | --------- | ----------------------------------------------------------------------- |
| type     | string  | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.    |
| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes    | Callback used to return the result.  |
2184

W
wusongqing 已提交
2185
**Example**
2186

G
Gloria 已提交
2187
```js
2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
    console.info(`## CapChange on is called for element ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
    }
2207
  }
2208
});
2209 2210
```

2211
### off('audioCapturerChange')<sup>9+</sup>
2212

2213
off(type: "audioCapturerChange"): void;
2214

2215
Unsubscribes from audio capturer change events.
2216

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

W
wusongqing 已提交
2219
**Parameters**
2220

2221 2222 2223
| Name     | Type    | Mandatory| Description                                                         |
| -------- | -------- | --- | ------------------------------------------------------------- |
| type     | string   |Yes  | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.|
2224

W
wusongqing 已提交
2225
**Example**
2226

G
Gloria 已提交
2227
```js
2228 2229 2230
audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########');

2231 2232
```

2233
### isActive<sup>9+</sup>
2234

2235
isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
2236

2237
Checks whether a stream is active. This API uses an asynchronous callback to return the result.
2238

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

W
wusongqing 已提交
2241
**Parameters**
2242

2243 2244 2245 2246
| Name    | Type                               | Mandatory| Description                                             |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                     |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
2247

W
wusongqing 已提交
2248
**Example**
2249

G
Gloria 已提交
2250
```js
2251
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
2252
  if (err) {
2253
    console.error(`Failed to obtain the active status of the stream. ${err}`);
2254 2255
    return;
  }
2256
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
2257
});
2258 2259
```

2260
### isActive<sup>9+</sup>
2261

2262
isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
2263

2264
Checks whether a stream is active. This API uses a promise to return the result.
2265

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

2268 2269 2270 2271 2272
**Parameters**

| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
2273

W
wusongqing 已提交
2274
**Return value**
2275

2276 2277 2278
| Type                  | Description                                                    |
| ---------------------- | -------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
2279

W
wusongqing 已提交
2280
**Example**
2281

G
Gloria 已提交
2282
```js
2283 2284
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
2285 2286 2287
});
```

2288
## AudioRoutingManager<sup>9+</sup>
2289

2290
Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance.
2291

2292
### getDevices<sup>9+</sup>
2293

2294
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
2295

2296 2297 2298
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
2299 2300 2301

**Parameters**

G
Gloria 已提交
2302 2303
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2304 2305
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the device list.|
2306 2307

**Example**
2308

G
Gloria 已提交
2309
```js
2310
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
2311
  if (err) {
2312
    console.error(`Failed to obtain the device list. ${err}`);
G
Gloria 已提交
2313
    return;
2314
  }
2315
  console.info('Callback invoked to indicate that the device list is obtained.');
2316 2317 2318
});
```

2319
### getDevices<sup>9+</sup>
2320

2321
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
2322

2323
Obtains the audio devices with a specific flag. This API uses a promise to return the result.
G
Gloria 已提交
2324

2325
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2326 2327 2328

**Parameters**

2329 2330 2331
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
2332 2333 2334

**Return value**

2335 2336 2337
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
2338 2339

**Example**
G
Gloria 已提交
2340 2341

```js
2342 2343 2344
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
});
2345 2346
```

2347
### on<sup>9+</sup>
2348

2349
on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void
2350

2351
Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
G
Gloria 已提交
2352

2353
**System capability**: SystemCapability.Multimedia.Audio.Device
2354 2355 2356

**Parameters**

2357 2358 2359 2360 2361
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes  | Callback used to return the device update details.                        |
G
Gloria 已提交
2362

2363
**Error codes**
2364

2365
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2366

2367 2368 2369
| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |
2370 2371

**Example**
G
Gloria 已提交
2372 2373

```js
2374 2375 2376 2377 2378 2379
audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (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);
});
2380
```
2381

2382
### off<sup>9+</sup>
2383

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

2386
Unsubscribes from device change events.
2387

2388
**System capability**: SystemCapability.Multimedia.Audio.Device
2389 2390 2391

**Parameters**

2392 2393 2394 2395
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No  | Callback used to return the device update details.                        |
2396

2397
**Error codes**
2398

2399
For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).
2400

2401 2402 2403
| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error.             |
2404 2405 2406 2407

**Example**

```js
2408 2409
audioRoutingManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
2410 2411 2412
});
```

2413
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
2414

2415
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2416

2417
Selects an audio input device. Currently, only one input device can be selected. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2418 2419 2420

**System API**: This is a system API.

2421
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2422 2423 2424

**Parameters**

2425 2426 2427 2428
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
2429 2430 2431

**Example**
```js
2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
let inputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.INPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];

async function selectInputDevice(){
  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select input devices result callback: SUCCESS'); }
  });
G
Gloria 已提交
2445 2446 2447
}
```

2448
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
2449

2450
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
G
Gloria 已提交
2451 2452 2453

**System API**: This is a system API.

2454 2455 2456
Selects an audio input device. Currently, only one input device can be selected. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2457 2458 2459

**Parameters**

2460 2461 2462
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
G
Gloria 已提交
2463 2464 2465

**Return value**

2466 2467 2468
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
G
Gloria 已提交
2469 2470 2471 2472

**Example**

```js
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484
let inputAudioDeviceDescriptor =[{
  "deviceRole":audio.DeviceRole.INPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];

async function getRoutingManager(){
    audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
      console.info('Select input devices result promise: SUCCESS');
    }).catch((err) => {
      console.error(`Result ERROR: ${err}`);
    });
G
Gloria 已提交
2485 2486 2487
}
```

2488
### setCommunicationDevice<sup>9+</sup>
G
Gloria 已提交
2489

2490
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2491

2492
Sets a communication device to the active state. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2493

2494
**System capability**: SystemCapability.Multimedia.Audio.Communication
G
Gloria 已提交
2495 2496 2497

**Parameters**

2498 2499 2500 2501 2502
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.      |
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
G
Gloria 已提交
2503 2504 2505 2506

**Example**

```js
2507 2508 2509 2510
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => {
  if (err) {
    console.error(`Failed to set the active status of the device. ${err}`);
    return;
G
Gloria 已提交
2511
  }
2512 2513
  console.info('Callback invoked to indicate that the device is set to the active status.');
});
G
Gloria 已提交
2514 2515
```

2516
### setCommunicationDevice<sup>9+</sup>
G
Gloria 已提交
2517

2518
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
G
Gloria 已提交
2519

2520
Sets a communication device to the active state. This API uses a promise to return the result.
G
Gloria 已提交
2521

2522
**System capability**: SystemCapability.Multimedia.Audio.Communication
G
Gloria 已提交
2523 2524 2525

**Parameters**

2526 2527 2528 2529
| Name    | Type                                                  | Mandatory| Description              |
| ---------- | ----------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9)  | Yes  | Communication device type.|
| active     | boolean                                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
G
Gloria 已提交
2530 2531 2532

**Return value**

2533 2534 2535
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2536 2537 2538 2539

**Example**

```js
2540 2541 2542
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
});
G
Gloria 已提交
2543 2544
```

2545
### isCommunicationDeviceActive<sup>9+</sup>
G
Gloria 已提交
2546

2547
isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
G
Gloria 已提交
2548

2549
Checks whether a communication device is active. This API uses an asynchronous callback to return the result.
2550

2551
**System capability**: SystemCapability.Multimedia.Audio.Communication
G
Gloria 已提交
2552 2553 2554

**Parameters**

2555 2556 2557 2558
| Name    | Type                                                 | Mandatory| Description                    |
| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.      |
| callback   | AsyncCallback&lt;boolean&gt;                         | Yes  | Callback used to return the active state of the device.|
G
Gloria 已提交
2559 2560 2561 2562

**Example**

```js
2563
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => {
G
Gloria 已提交
2564
  if (err) {
2565
    console.error(`Failed to obtain the active status of the device. ${err}`);
G
Gloria 已提交
2566 2567
    return;
  }
2568
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
G
Gloria 已提交
2569 2570 2571
});
```

2572
### isCommunicationDeviceActive<sup>9+</sup>
G
Gloria 已提交
2573

2574
isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
G
Gloria 已提交
2575

2576
Checks whether a communication device is active. This API uses a promise to return the result.
2577

2578
**System capability**: SystemCapability.Multimedia.Audio.Communication
G
Gloria 已提交
2579 2580 2581

**Parameters**

2582 2583 2584
| Name    | Type                                                 | Mandatory| Description              |
| ---------- | ---------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.|
G
Gloria 已提交
2585 2586 2587

**Return value**

2588 2589 2590
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
G
Gloria 已提交
2591 2592 2593 2594

**Example**

```js
2595 2596
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
G
Gloria 已提交
2597 2598 2599
});
```

2600
### selectOutputDevice<sup>9+</sup>
G
Gloria 已提交
2601

2602
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2603

2604
Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2605

2606 2607
**System API**: This is a system API.

2608
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2609 2610 2611

**Parameters**

2612 2613 2614 2615
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
2616 2617 2618

**Example**
```js
2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices result callback: SUCCESS'); }
  });
}
G
Gloria 已提交
2632 2633
```

2634
### selectOutputDevice<sup>9+</sup>
G
Gloria 已提交
2635

2636
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
G
Gloria 已提交
2637

2638 2639
**System API**: This is a system API.

2640 2641 2642
Selects an audio output device. Currently, only one output device can be selected. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2643 2644 2645

**Parameters**

2646 2647 2648
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
G
Gloria 已提交
2649 2650 2651

**Return value**

2652 2653 2654
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
G
Gloria 已提交
2655 2656 2657 2658

**Example**

```js
2659 2660 2661 2662 2663
let outputAudioDeviceDescriptor =[{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
G
Gloria 已提交
2664

2665 2666 2667 2668 2669 2670 2671 2672
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  });
}
```
G
Gloria 已提交
2673

2674 2675 2676
### selectOutputDeviceByFilter<sup>9+</sup>

selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2677

2678 2679
**System API**: This is a system API.

2680 2681 2682
Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2683 2684 2685

**Parameters**

2686 2687 2688 2689 2690
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| filter                      | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
2691 2692 2693

**Example**
```js
2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];
G
Gloria 已提交
2706

2707 2708 2709 2710 2711 2712 2713 2714 2715
async function selectOutputDeviceByFilter(){
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices by filter result callback: SUCCESS'); }
  });
}
```
G
Gloria 已提交
2716

2717
### selectOutputDeviceByFilter<sup>9+</sup>
G
Gloria 已提交
2718

2719
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
G
Gloria 已提交
2720

2721 2722
**System API**: This is a system API.

2723 2724 2725
Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2726 2727 2728

**Parameters**

2729 2730 2731 2732
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
G
Gloria 已提交
2733 2734 2735

**Return value**

2736 2737 2738
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
G
Gloria 已提交
2739 2740 2741 2742

**Example**

```js
2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
let outputAudioDeviceDescriptor = [{
  "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
  "networkId":audio.LOCAL_NETWORK_ID,
  "interruptGroupId":1,
  "volumeGroupId":1 }];

async function selectOutputDeviceByFilter(){
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices by filter result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  })
}
G
Gloria 已提交
2763 2764
```

2765
## AudioRendererChangeInfoArray<sup>9+</sup>
G
Gloria 已提交
2766

2767
Defines an **AudioRenderChangeInfo** array, which is read-only.
G
Gloria 已提交
2768

2769
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
2770

2771
## AudioRendererChangeInfo<sup>9+</sup>
2772

2773
Describes the audio renderer change event.
G
Gloria 已提交
2774

2775
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
2776

2777 2778 2779 2780 2781 2782
| Name          | Type                                     | Readable | Writable | Description                                                |
| ------------- | ---------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
| streamId      | number                                   | Yes      | No       | Unique ID of an audio stream.                              |
| clientUid     | number                                   | Yes      | No       | UID of the audio renderer client.<br>This is a system API. |
| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8) | Yes      | No       | Audio renderer information.                                |
| rendererState | [AudioState](#audiostate)                | Yes      | No       | Audio state.<br>This is a system API.                      |
G
Gloria 已提交
2783 2784 2785 2786

**Example**

```js
2787 2788 2789 2790 2791 2792 2793
import audio from '@ohos.multimedia.audio';

let audioStreamManager;
let resultFlag = false;
let audioManager = audio.getAudioManager();

audioManager.getStreamManager((err, data) => {
G
Gloria 已提交
2794
  if (err) {
2795 2796 2797 2798
    console.error(`Get AudioStream Manager : ERROR : ${err}`);
  } else {
    audioStreamManager = data;
    console.info('Get AudioStream Manager : Success');
G
Gloria 已提交
2799 2800 2801
  }
});

2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828
audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
    console.info(`## RendererChange on is called for ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`);
    console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
    console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
    console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
    console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`);
  	let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
  	for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
  	  console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
  	  console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
  	  console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
  	  console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
  	  console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
  	  console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
  	  console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
  	  console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
  	}
    if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for ${i} is: ${resultFlag}`);
    }
  }
});
```
G
Gloria 已提交
2829 2830


2831
## AudioCapturerChangeInfoArray<sup>9+</sup>
G
Gloria 已提交
2832

2833
Defines an **AudioCapturerChangeInfo** array, which is read-only.
2834

2835
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
2836

2837
## AudioCapturerChangeInfo<sup>9+</sup>
G
Gloria 已提交
2838

2839
Describes the audio capturer change event.
G
Gloria 已提交
2840

2841
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
2842

2843 2844 2845 2846 2847 2848
| Name          | Type                                     | Readable | Writable | Description                                                |
| ------------- | ---------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
| streamId      | number                                   | Yes      | No       | Unique ID of an audio stream.                              |
| clientUid     | number                                   | Yes      | No       | UID of the audio capturer client.<br>This is a system API. |
| capturerInfo  | [AudioCapturerInfo](#audiocapturerinfo8) | Yes      | No       | Audio capturer information.                                |
| capturerState | [AudioState](#audiostate)                | Yes      | No       | Audio state.<br>This is a system API.                      |
G
Gloria 已提交
2849 2850 2851 2852

**Example**

```js
2853
import audio from '@ohos.multimedia.audio';
G
Gloria 已提交
2854

2855 2856 2857 2858 2859 2860 2861 2862 2863 2864
const audioManager = audio.getAudioManager();
let audioStreamManager;
audioManager.getStreamManager((err, data) => {
  if (err) {
    console.error(`getStreamManager : Error: ${err}`);
  } else {
    console.info('getStreamManager : Success : SUCCESS');
    audioStreamManager = data;
  }
});
G
Gloria 已提交
2865

2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892
let resultFlag = false;
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
    console.info(`## CapChange on is called for element ${i} ##`);
    console.info(`StrId for  ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
    console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
    console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
    console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
      console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
      console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
      console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
      console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
    }
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
    }
  }
});
```
G
Gloria 已提交
2893

2894
## AudioDeviceDescriptors
G
Gloria 已提交
2895

2896
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
G
Gloria 已提交
2897

2898
## AudioDeviceDescriptor
2899

2900
Describes an audio device.
G
Gloria 已提交
2901

2902
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
2903

2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID.                                                   |
| name<sup>9+</sup>             | string                    | Yes      | No       | Device name.                                                 |
| address<sup>9+</sup>          | string                    | Yes      | No       | Device address.                                              |
| sampleRates<sup>9+</sup>      | Array&lt;number&gt;       | Yes      | No       | Supported sampling rates.                                    |
| channelCounts<sup>9+</sup>    | Array&lt;number&gt;       | Yes      | No       | Number of channels supported.                                |
| channelMasks<sup>9+</sup>     | Array&lt;number&gt;       | Yes      | No       | Supported channel masks.                                     |
| networkId<sup>9+</sup>        | string                    | Yes      | No       | ID of the device network.<br>This is a system API.           |
| interruptGroupId<sup>9+</sup> | number                    | Yes      | No       | ID of the interruption group to which the device belongs.<br>This is a system API. |
| volumeGroupId<sup>9+</sup>    | number                    | Yes      | No       | ID of the volume group to which the device belongs.<br>This is a system API. |
G
Gloria 已提交
2917 2918 2919 2920

**Example**

```js
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937
import audio from '@ohos.multimedia.audio';

function displayDeviceProp(value) {
  deviceRoleValue = value.deviceRole;
  deviceTypeValue = value.deviceType;
}

let deviceRoleValue = null;
let deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
  console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
  value.forEach(displayDeviceProp);
  if (deviceTypeValue != null && deviceRoleValue != null){
    console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
  } else {
    console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
G
Gloria 已提交
2938 2939 2940 2941
  }
});
```

2942
## AudioRendererFilter<sup>9+</sup>
G
Gloria 已提交
2943

2944
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
G
Gloria 已提交
2945

2946 2947
**System API**: This is a system API.

2948 2949 2950 2951 2952
| Name         | Type                                     | Mandatory | Description                                                  |
| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
| uid          | number                                   | Yes       | Application ID.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No        | Audio renderer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
| rendererId   | number                                   | No        | Unique ID of an audio stream.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
G
Gloria 已提交
2953

2954
**Example**
G
Gloria 已提交
2955

2956 2957 2958 2959 2960 2961 2962 2963 2964
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
G
Gloria 已提交
2965

2966
## AudioRenderer<sup>8+</sup>
G
Gloria 已提交
2967

2968 2969 2970 2971 2972 2973 2974 2975 2976
Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.

### Attributes

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

| Name               | Type                       | Readable | Writable | Description           |
| ------------------ | -------------------------- | -------- | -------- | --------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio renderer state. |
G
Gloria 已提交
2977 2978 2979 2980

**Example**

```js
2981
let state = audioRenderer.state;
G
Gloria 已提交
2982 2983
```

2984
### getRendererInfo<sup>8+</sup>
G
Gloria 已提交
2985

2986
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
G
Gloria 已提交
2987

2988
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
2989

2990
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
2991 2992 2993

**Parameters**

2994 2995 2996
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
G
Gloria 已提交
2997 2998 2999 3000

**Example**

```js
3001 3002 3003 3004 3005
audioRenderer.getRendererInfo((err, rendererInfo) => {
  console.info('Renderer GetRendererInfo:');
  console.info(`Renderer content: ${rendererInfo.content}`);
  console.info(`Renderer usage: ${rendererInfo.usage}`);
  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
G
Gloria 已提交
3006 3007 3008
});
```

3009
### getRendererInfo<sup>8+</sup>
3010

3011
getRendererInfo(): Promise<AudioRendererInfo\>
G
Gloria 已提交
3012

3013
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
G
Gloria 已提交
3014

3015
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3016 3017 3018

**Return value**

3019 3020 3021
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
G
Gloria 已提交
3022 3023 3024 3025

**Example**

```js
3026 3027 3028 3029 3030 3031 3032
audioRenderer.getRendererInfo().then((rendererInfo) => {
  console.info('Renderer GetRendererInfo:');
  console.info(`Renderer content: ${rendererInfo.content}`);
  console.info(`Renderer usage: ${rendererInfo.usage}`);
  console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
}).catch((err) => {
  console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
G
Gloria 已提交
3033 3034 3035
});
```

3036
### getStreamInfo<sup>8+</sup>
G
Gloria 已提交
3037

3038
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
G
Gloria 已提交
3039

3040
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3041 3042 3043 3044 3045

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

**Parameters**

3046 3047 3048
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
G
Gloria 已提交
3049 3050 3051 3052

**Example**

```js
3053 3054 3055 3056 3057 3058
audioRenderer.getStreamInfo((err, streamInfo) => {
  console.info('Renderer GetStreamInfo:');
  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
  console.info(`Renderer channel: ${streamInfo.channels}`);
  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
G
Gloria 已提交
3059 3060 3061
});
```

3062
### getStreamInfo<sup>8+</sup>
G
Gloria 已提交
3063

3064
getStreamInfo(): Promise<AudioStreamInfo\>
G
Gloria 已提交
3065

3066
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
G
Gloria 已提交
3067 3068 3069 3070 3071

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

**Return value**

3072 3073 3074
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
G
Gloria 已提交
3075 3076 3077 3078

**Example**

```js
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088
audioRenderer.getStreamInfo().then((streamInfo) => {
  console.info('Renderer GetStreamInfo:');
  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
  console.info(`Renderer channel: ${streamInfo.channels}`);
  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});

G
Gloria 已提交
3089 3090
```

3091
### getAudioStreamId<sup>9+</sup>
G
Gloria 已提交
3092

3093
getAudioStreamId(callback: AsyncCallback<number\>): void
G
Gloria 已提交
3094

3095
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3096 3097 3098 3099 3100

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

**Parameters**

3101 3102 3103
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
G
Gloria 已提交
3104 3105 3106 3107

**Example**

```js
3108 3109
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
G
Gloria 已提交
3110
});
3111

G
Gloria 已提交
3112 3113
```

3114
### getAudioStreamId<sup>9+</sup>
G
Gloria 已提交
3115

3116
getAudioStreamId(): Promise<number\>
G
Gloria 已提交
3117

3118
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
G
Gloria 已提交
3119 3120 3121 3122 3123

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

**Return value**

3124 3125 3126
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
G
Gloria 已提交
3127 3128 3129 3130

**Example**

```js
3131 3132 3133 3134 3135
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
G
Gloria 已提交
3136

3137
```
G
Gloria 已提交
3138

3139 3140 3141 3142 3143
### start<sup>8+</sup>

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

Starts the renderer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3144 3145 3146 3147 3148

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

**Parameters**

3149 3150 3151
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
G
Gloria 已提交
3152 3153 3154 3155

**Example**

```js
3156 3157 3158 3159 3160
audioRenderer.start((err) => {
  if (err) {
    console.error('Renderer start failed.');
  } else {
    console.info('Renderer start success.');
G
Gloria 已提交
3161 3162
  }
});
3163

G
Gloria 已提交
3164 3165
```

3166
### start<sup>8+</sup>
G
Gloria 已提交
3167

3168
start(): Promise<void\>
G
Gloria 已提交
3169

3170
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
3171 3172 3173

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

3174
**Return value**
G
Gloria 已提交
3175

3176 3177 3178
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
3179 3180 3181 3182

**Example**

```js
3183 3184 3185 3186 3187 3188
audioRenderer.start().then(() => {
  console.info('Renderer started');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});

G
Gloria 已提交
3189 3190
```

3191
### pause<sup>8+</sup>
G
Gloria 已提交
3192

3193
pause(callback: AsyncCallback\<void>): void
G
Gloria 已提交
3194

3195
Pauses rendering. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3196

3197
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3198 3199 3200

**Parameters**

3201 3202 3203
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
G
Gloria 已提交
3204 3205 3206 3207

**Example**

```js
3208 3209 3210 3211 3212
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
G
Gloria 已提交
3213 3214
  }
});
3215

G
Gloria 已提交
3216 3217
```

3218
### pause<sup>8+</sup>
G
Gloria 已提交
3219

3220
pause(): Promise\<void>
G
Gloria 已提交
3221

3222
Pauses rendering. This API uses a promise to return the result.
G
Gloria 已提交
3223

3224
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3225

3226
**Return value**
G
Gloria 已提交
3227

3228 3229 3230
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
3231 3232 3233 3234

**Example**

```js
3235 3236 3237 3238 3239
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
G
Gloria 已提交
3240

3241 3242
```

3243
### drain<sup>8+</sup>
3244

3245
drain(callback: AsyncCallback\<void>): void
3246

3247
Drains the playback buffer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3248

3249
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3250 3251 3252

**Parameters**

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

**Example**
G
Gloria 已提交
3258 3259

```js
3260
audioRenderer.drain((err) => {
G
Gloria 已提交
3261
  if (err) {
3262
    console.error('Renderer drain failed');
3263
  } else {
3264
    console.info('Renderer drained.');
G
Gloria 已提交
3265
  }
3266
});
G
Gloria 已提交
3267

3268
```
G
Gloria 已提交
3269

3270
### drain<sup>8+</sup>
G
Gloria 已提交
3271

3272
drain(): Promise\<void>
G
Gloria 已提交
3273

3274
Drains the playback buffer. This API uses a promise to return the result.
G
Gloria 已提交
3275

3276
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3277 3278 3279

**Return value**

3280 3281 3282
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
3283 3284 3285 3286

**Example**

```js
3287 3288 3289 3290
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
3291
});
3292

3293 3294
```

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

3297
stop(callback: AsyncCallback\<void>): void
3298

3299
Stops rendering. This API uses an asynchronous callback to return the result.
3300

3301
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3302 3303 3304

**Parameters**

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

**Example**
G
Gloria 已提交
3310 3311

```js
3312
audioRenderer.stop((err) => {
G
Gloria 已提交
3313
  if (err) {
3314 3315 3316
    console.error('Renderer stop failed');
  } else {
    console.info('Renderer stopped.');
G
Gloria 已提交
3317 3318
  }
});
3319

3320 3321
```

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

3324
stop(): Promise\<void>
3325

3326
Stops rendering. This API uses a promise to return the result.
3327

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

3330
**Return value**
G
Gloria 已提交
3331

3332 3333 3334
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
3335 3336

**Example**
G
Gloria 已提交
3337 3338

```js
3339 3340 3341 3342
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
3343 3344
});

3345
```
3346

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

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

3351
Releases the renderer. This API uses an asynchronous callback to return the result.
3352

3353
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3354 3355 3356

**Parameters**

3357 3358 3359
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
3360 3361 3362

**Example**

3363 3364 3365 3366 3367 3368 3369 3370
```js
audioRenderer.release((err) => {
  if (err) {
    console.error('Renderer release failed');
  } else {
    console.info('Renderer released.');
  }
});
3371

3372
```
3373

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

3376
release(): Promise\<void>
3377

3378
Releases the renderer. This API uses a promise to return the result.
3379

3380
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3381 3382 3383

**Return value**

3384 3385 3386
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
3387 3388 3389 3390

**Example**

```js
3391 3392 3393 3394 3395
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
3396 3397 3398

```

3399
### write<sup>8+</sup>
3400

3401
write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
3402

3403
Writes the buffer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3404

3405
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3406 3407 3408

**Parameters**

3409 3410 3411 3412
| Name     | Type                   | Mandatory | Description                                                  |
| -------- | ---------------------- | --------- | ------------------------------------------------------------ |
| buffer   | ArrayBuffer            | Yes       | Buffer to be written.                                        |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
3413 3414

**Example**
3415

3416 3417 3418 3419 3420 3421 3422
```js
let bufferSize;
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
  bufferSize = data;
  }).catch((err) => {
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
G
Gloria 已提交
3423
  });
3424 3425 3426 3427 3428
console.info(`Buffer size: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
3429
}
3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf, (err, writtenbytes) => {
  if (writtenbytes < 0) {
    console.error('write failed.');
  } else {
    console.info(`Actual written bytes: ${writtenbytes}`);
  }
});
3441

3442
```
3443

3444
### write<sup>8+</sup>
3445

3446
write(buffer: ArrayBuffer): Promise\<number>
3447

3448
Writes the buffer. This API uses a promise to return the result.
3449

3450
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3451 3452 3453

**Return value**

3454 3455 3456
| Type             | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
3457 3458 3459

**Example**

G
Gloria 已提交
3460
```js
3461 3462 3463 3464 3465 3466
let bufferSize;
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
  bufferSize = data;
  }).catch((err) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
G
Gloria 已提交
3467
  });
3468 3469 3470 3471 3472
console.info(`BufferSize: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
3473
}
3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf).then((writtenbytes) => {
  if (writtenbytes < 0) {
      console.error('write failed.');
  } else {
      console.info(`Actual written bytes: ${writtenbytes}`);
  }
}).catch((err) => {
    console.error(`ERROR: ${err}`);
});
3487

3488
```
G
Gloria 已提交
3489

3490
### getAudioTime<sup>8+</sup>
G
Gloria 已提交
3491

3492
getAudioTime(callback: AsyncCallback\<number>): void
G
Gloria 已提交
3493

3494
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
3495

3496
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3497 3498 3499

**Parameters**

3500 3501 3502
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
G
Gloria 已提交
3503 3504

**Example**
3505

G
Gloria 已提交
3506
```js
3507 3508 3509
audioRenderer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
});
3510

3511 3512
```

3513
### getAudioTime<sup>8+</sup>
G
Gloria 已提交
3514

3515
getAudioTime(): Promise\<number>
3516

3517
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
3518

3519
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3520 3521 3522

**Return value**

3523 3524 3525
| Type             | Description                           |
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
3526 3527 3528

**Example**

G
Gloria 已提交
3529
```js
3530 3531 3532 3533 3534
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
3535

3536 3537
```

3538
### getBufferSize<sup>8+</sup>
3539

3540
getBufferSize(callback: AsyncCallback\<number>): void
3541

3542
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
3543

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

3546
**Parameters**
3547

3548 3549 3550
| Name     | Type                   | Mandatory | Description                              |
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
3551 3552 3553

**Example**

G
Gloria 已提交
3554
```js
3555
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
3556
  if (err) {
3557
    console.error('getBufferSize error');
3558 3559 3560
  }
});

3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855
```

### getBufferSize<sup>8+</sup>

getBufferSize(): Promise\<number>

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

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

**Return value**

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

**Example**

```js
let bufferSize;
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
});

```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void

Sets the render rate. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |

**Example**

```js
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
  if (err) {
    console.error('Failed to set params');
  } else {
    console.info('Callback invoked to indicate a successful render rate setting.');
  }
});

```

### setRenderRate<sup>8+</sup>

setRenderRate(rate: AudioRendererRate): Promise\<void>

Sets the render rate. This API uses a promise to return the result.

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

**Parameters**

| Name | Type                                     | Mandatory | Description        |
| ---- | ---------------------------------------- | --------- | ------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |

**Return value**

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

**Example**

```js
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});

```

### getRenderRate<sup>8+</sup>

getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void

Obtains the current render rate. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |

**Example**

```js
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});

```

### getRenderRate<sup>8+</sup>

getRenderRate(): Promise\<AudioRendererRate>

Obtains the current render rate. This API uses a promise to return the result.

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

**Return value**

| Type                                              | Description                                   |
| ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |

**Example**

```js
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});

```

### setInterruptMode<sup>9+</sup>

setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;

Sets the audio interruption mode for the application. This API uses a promise to return the result.

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

**Parameters**

| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |

**Return value**

| Type                | Description                                                  |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |

**Example**

```js
let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{
  console.info('setInterruptMode Success!');
}).catch((err) => {
  console.error(`setInterruptMode Fail: ${err}`);
});

```

### setInterruptMode<sup>9+</sup>

setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void

Sets the audio interruption mode for the application. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |

**Example**

```js
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
  }
  console.info('setInterruptMode Success!');
});

```

### setVolume<sup>9+</sup>

setVolume(volume: number): Promise&lt;void&gt;

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

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

**Parameters**

| Name   | Type   | Mandatory | Description    |
| ------ | ------ | --------- | -------------- |
| volume | number | Yes       | Volume to set. |

**Return value**

| Type                | Description                                                  |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |

**Example**

```js
audioRenderer.setVolume(10).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
});

```

### setVolume<sup>9+</sup>

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

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

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

**Parameters**

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

**Example**

```js
audioRenderer.setVolume(10, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
  }
  console.info('setVolume Success!');
});

```

### on('audioInterrupt')<sup>9+</sup>

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

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

Same as [on('interrupt')](#oninterruptdeprecated), this API has obtained the focus before **start**, **pause**, or **stop** of **AudioRenderer** is called. Therefore, you do not need to request the focus.

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

**Parameters**

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

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID      | Error Message                   |
| ------- | ------------------------------- |
| 6800101 | if input parameter value error. |

**Example**

```js
let isPlay;
let started;
audioRenderer.on('audioInterrupt', async(interruptEvent) => {
  if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
    switch (interruptEvent.hintType) {
      case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
        console.info('Force paused. Stop writing');
        isPlay = false;
        break;
      case audio.InterruptHint.INTERRUPT_HINT_STOP:
        console.info('Force stopped. Stop writing');
        isPlay = false;
        break;
3856
    }
3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011
  } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
    switch (interruptEvent.hintType) {
      case audio.InterruptHint.INTERRUPT_HINT_RESUME:
        console.info('Resume force paused renderer or ignore');
        await audioRenderer.start().then(async function () {
          console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
          started = true;
        }).catch((err) => {
          console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err}`);
          started = false;
        });
        if (started) {
          isPlay = true;
          console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`);
        } else {
          console.error('AudioInterruptMusic Renderer start failed');
        }
        break;
      case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
        console.info('Choose to pause or ignore');
        if (isPlay == true) {
          isPlay == false;
          console.info('AudioInterruptMusic: Media PAUSE : TRUE');
        } else {
          isPlay = true;
          console.info('AudioInterruptMusic: Media PLAY : TRUE');
        }
        break;
    }
  }
});

```

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

on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void

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

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

**Parameters**

| Name     | Type              | Mandatory | Description                                                  |
| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |

**Example**

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

```


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

off(type: 'markReach'): void

Unsubscribes from mark reached events.

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

**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |

**Example**

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

```

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

on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void

Subscribes to period reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned.

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

**Parameters**

| Name     | Type              | Mandatory | Description                                                  |
| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |

**Example**

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

```

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

off(type: 'periodReach'): void

Unsubscribes from period reached events.

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

**Parameters**

| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |

**Example**

```js
audioRenderer.off('periodReach')

```

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

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

Subscribes to state change events.

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

**Parameters**

| Name     | Type                       | Mandatory | Description                                                  |
| :------- | :------------------------- | :-------- | :----------------------------------------------------------- |
| type     | string                     | Yes       | Event type. The value **stateChange** means the state change event. |
| callback | [AudioState](#audiostate8) | Yes       | Callback used to return the state change.                    |

**Example**

```js
audioRenderer.on('stateChange', (state) => {
  if (state == 1) {
    console.info('audio renderer state is: STATE_PREPARED');
  }
  if (state == 2) {
    console.info('audio renderer state is: STATE_RUNNING');
4012 4013
  }
});
4014

4015 4016
```

4017
## AudioCapturer<sup>8+</sup>
4018

4019 4020 4021
Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.

### Attributes
4022 4023 4024

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

4025 4026 4027 4028 4029 4030 4031 4032
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |

**Example**

```js
let state = audioCapturer.state;
4033

4034
```
4035

4036 4037 4038 4039 4040
### getCapturerInfo<sup>8+</sup>

getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void

Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
4041 4042 4043

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

4044 4045 4046 4047 4048 4049
**Parameters**

| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |

4050 4051
**Example**

G
Gloria 已提交
4052
```js
4053
audioCapturer.getCapturerInfo((err, capturerInfo) => {
4054
  if (err) {
4055
    console.error('Failed to get capture info');
4056
  } else {
4057 4058 4059
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
4060 4061 4062
  }
});

4063 4064
```

V
Vaidegi B 已提交
4065

4066
### getCapturerInfo<sup>8+</sup>
4067

4068
getCapturerInfo(): Promise<AudioCapturerInfo\>
W
wusongqing 已提交
4069

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

4072 4073 4074
**System capability**: SystemCapability.Multimedia.Audio.Capturer

**Return value**
V
Vaidegi B 已提交
4075

4076 4077 4078
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
V
Vaidegi B 已提交
4079

W
wusongqing 已提交
4080
**Example**
V
Vaidegi B 已提交
4081

G
Gloria 已提交
4082
```js
4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094
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.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
});
V
Vaidegi B 已提交
4095

4096
```
V
Vaidegi B 已提交
4097

4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117
### getStreamInfo<sup>8+</sup>

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

Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |

**Example**

```js
audioCapturer.getStreamInfo((err, streamInfo) => {
  if (err) {
    console.error('Failed to get stream info');
4118
  } else {
4119 4120 4121 4122 4123
    console.info('Capturer GetStreamInfo:');
    console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
    console.info(`Capturer channel: ${streamInfo.channels}`);
    console.info(`Capturer format: ${streamInfo.sampleFormat}`);
    console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
4124
  }
4125
});
4126

V
Vaidegi B 已提交
4127 4128
```

4129
### getStreamInfo<sup>8+</sup>
G
Gloria 已提交
4130

4131
getStreamInfo(): Promise<AudioStreamInfo\>
G
Gloria 已提交
4132

4133
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
G
Gloria 已提交
4134

4135 4136 4137 4138 4139 4140 4141
**System capability**: SystemCapability.Multimedia.Audio.Capturer

**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
G
Gloria 已提交
4142 4143 4144 4145

**Example**

```js
4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230
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.error(`getStreamInfo :ERROR: ${err}`);
});

```

### getAudioStreamId<sup>9+</sup>

getAudioStreamId(callback: AsyncCallback<number\>): void

Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.

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

**Parameters**

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

**Example**

```js
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
});

```

### getAudioStreamId<sup>9+</sup>

getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.

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

**Return value**

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

**Example**

```js
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});

```

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

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

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

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

**Parameters**

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

**Example**

```js
audioCapturer.start((err) => {
  if (err) {
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
  }
});

G
Gloria 已提交
4231 4232
```

V
Vaidegi B 已提交
4233

4234
### start<sup>8+</sup>
V
Vaidegi B 已提交
4235

4236
start(): Promise<void\>
V
Vaidegi B 已提交
4237

4238
Starts capturing. This API uses a promise to return the result.
4239

4240 4241 4242 4243 4244 4245 4246
**System capability**: SystemCapability.Multimedia.Audio.Capturer

**Return value**

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

W
wusongqing 已提交
4248
**Example**
V
Vaidegi B 已提交
4249

G
Gloria 已提交
4250
```js
4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262
audioCapturer.start().then(() => {
  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)) {
    console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
  }
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
});

V
Vaidegi B 已提交
4263 4264
```

4265
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4266

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

4269
Stops capturing. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4270

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

W
wusongqing 已提交
4273
**Parameters**
V
Vaidegi B 已提交
4274

4275 4276 4277
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4278

W
wusongqing 已提交
4279
**Example**
V
Vaidegi B 已提交
4280

G
Gloria 已提交
4281
```js
4282 4283 4284 4285 4286 4287
audioCapturer.stop((err) => {
  if (err) {
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
  }
4288
});
4289

V
Vaidegi B 已提交
4290 4291 4292
```


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

4295
stop(): Promise<void\>
V
Vaidegi B 已提交
4296

4297 4298 4299
Stops capturing. This API uses a promise to return the result.

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

W
wusongqing 已提交
4301
**Return value**
V
Vaidegi B 已提交
4302

4303 4304 4305
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4306

W
wusongqing 已提交
4307
**Example**
V
Vaidegi B 已提交
4308

G
Gloria 已提交
4309
```js
4310 4311 4312 4313 4314 4315
audioCapturer.stop().then(() => {
  console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
  console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
  if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
    console.info('AudioFrameworkRecLog: State is Stopped:');
  }
4316
}).catch((err) => {
4317
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
4318
});
4319

4320
```
V
Vaidegi B 已提交
4321

4322
### release<sup>8+</sup>
V
Vaidegi B 已提交
4323

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

4326
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4327

4328
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
4329

W
wusongqing 已提交
4330
**Parameters**
V
Vaidegi B 已提交
4331

4332 4333 4334
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4335

W
wusongqing 已提交
4336
**Example**
V
Vaidegi B 已提交
4337

G
Gloria 已提交
4338
```js
4339 4340 4341 4342 4343 4344
audioCapturer.release((err) => {
  if (err) {
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
  }
4345
});
4346

V
Vaidegi B 已提交
4347 4348 4349
```


4350
### release<sup>8+</sup>
V
Vaidegi B 已提交
4351

4352
release(): Promise<void\>
V
Vaidegi B 已提交
4353

4354 4355 4356
Releases this **AudioCapturer** instance. This API uses a promise to return the result.

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

W
wusongqing 已提交
4358
**Return value**
V
Vaidegi B 已提交
4359

4360 4361 4362
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4363

W
wusongqing 已提交
4364
**Example**
V
Vaidegi B 已提交
4365

G
Gloria 已提交
4366
```js
4367 4368 4369 4370 4371 4372
let stateFlag;
audioCapturer.release().then(() => {
  console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
  console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
  console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
  console.info(`AudioFrameworkRecLog: stateFlag : ${stateFlag}`);
4373
}).catch((err) => {
4374
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
4375
});
4376

V
Vaidegi B 已提交
4377 4378
```

4379
### read<sup>8+</sup>
V
Vaidegi B 已提交
4380

4381
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
V
Vaidegi B 已提交
4382

4383
Reads the buffer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4384

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

W
wusongqing 已提交
4387
**Parameters**
V
Vaidegi B 已提交
4388

4389 4390 4391 4392 4393
| Name           | Type                        | Mandatory | Description                          |
| :------------- | :-------------------------- | :-------- | :----------------------------------- |
| size           | number                      | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean                     | Yes       | Whether to block the read operation. |
| callback       | AsyncCallback<ArrayBuffer\> | Yes       | Callback used to return the buffer.  |
V
Vaidegi B 已提交
4394

W
wusongqing 已提交
4395
**Example**
V
Vaidegi B 已提交
4396

G
Gloria 已提交
4397
```js
4398 4399 4400 4401 4402 4403 4404 4405 4406 4407
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
  bufferSize = data;
  }).catch((err) => {
    console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
  });
audioCapturer.read(bufferSize, true, async(err, buffer) => {
  if (!err) {
    console.info('Success in reading the buffer data');
4408
  }
4409
});
4410

V
Vaidegi B 已提交
4411 4412
```

4413
### read<sup>8+</sup>
V
Vaidegi B 已提交
4414

4415
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
V
Vaidegi B 已提交
4416

4417
Reads the buffer. This API uses a promise to return the result.
V
Vaidegi B 已提交
4418

4419 4420 4421 4422 4423 4424 4425 4426
**System capability**: SystemCapability.Multimedia.Audio.Capturer

**Parameters**

| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
4427

W
wusongqing 已提交
4428
**Return value**
V
Vaidegi B 已提交
4429

4430 4431 4432
| Type                  | Description                                                  |
| :-------------------- | :----------------------------------------------------------- |
| Promise<ArrayBuffer\> | Promise used to return the result. If the operation is successful, the buffer data read is returned; otherwise, an error code is returned. |
V
Vaidegi B 已提交
4433

W
wusongqing 已提交
4434
**Example**
V
Vaidegi B 已提交
4435

G
Gloria 已提交
4436
```js
4437 4438 4439 4440 4441 4442 4443 4444 4445 4446
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
  bufferSize = data;
  }).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
  });
console.info(`Buffer size: ${bufferSize}`);
audioCapturer.read(bufferSize, true).then((buffer) => {
  console.info('buffer read successfully');
4447
}).catch((err) => {
4448
  console.info(`ERROR : ${err}`);
4449
});
4450

V
Vaidegi B 已提交
4451 4452
```

4453
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4454

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

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

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

W
wusongqing 已提交
4461
**Parameters**
V
Vaidegi B 已提交
4462

4463 4464 4465
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4466

W
wusongqing 已提交
4467
**Example**
V
Vaidegi B 已提交
4468

G
Gloria 已提交
4469
```js
4470 4471
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4472
});
4473

V
Vaidegi B 已提交
4474 4475
```

4476
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4477

4478
getAudioTime(): Promise<number\>
V
Vaidegi B 已提交
4479

4480
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4481

4482
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
4483

W
wusongqing 已提交
4484
**Return value**
V
Vaidegi B 已提交
4485

4486 4487 4488
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4489

W
wusongqing 已提交
4490
**Example**
V
Vaidegi B 已提交
4491

G
Gloria 已提交
4492
```js
4493 4494
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
4495
}).catch((err) => {
4496
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
4497
});
4498

V
Vaidegi B 已提交
4499 4500
```

4501
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4502

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

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

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

W
wusongqing 已提交
4509
**Parameters**
V
Vaidegi B 已提交
4510

4511 4512 4513
| Name     | Type                   | Mandatory | Description                              |
| :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4514

W
wusongqing 已提交
4515
**Example**
V
Vaidegi B 已提交
4516

G
Gloria 已提交
4517
```js
4518 4519 4520 4521 4522 4523 4524 4525
audioCapturer.getBufferSize((err, bufferSize) => {
  if (!err) {
    console.info(`BufferSize : ${bufferSize}`);
    audioCapturer.read(bufferSize, true).then((buffer) => {
      console.info(`Buffer read is ${buffer}`);
    }).catch((err) => {
      console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
    });
4526
  }
4527
});
4528

V
Vaidegi B 已提交
4529 4530
```

4531
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4532

4533
getBufferSize(): Promise<number\>
V
Vaidegi B 已提交
4534

4535
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
4536

4537
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
4538

W
wusongqing 已提交
4539
**Return value**
V
Vaidegi B 已提交
4540

4541 4542 4543
| Type             | Description                             |
| :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4544

W
wusongqing 已提交
4545
**Example**
V
Vaidegi B 已提交
4546

G
Gloria 已提交
4547
```js
4548 4549 4550 4551
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
4552
}).catch((err) => {
4553
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
4554
});
4555

V
Vaidegi B 已提交
4556 4557
```

4558
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
4559

4560
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
4561

4562
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
V
Vaidegi B 已提交
4563

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

W
wusongqing 已提交
4566
**Parameters**
V
Vaidegi B 已提交
4567

4568 4569 4570 4571 4572
| Name     | Type              | Mandatory | Description                                                  |
| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
| type     | string            | Yes       | Event type. The value is fixed at **'markReach'**.           |
| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
V
Vaidegi B 已提交
4573

W
wusongqing 已提交
4574
**Example**
V
Vaidegi B 已提交
4575

G
Gloria 已提交
4576
```js
4577 4578 4579
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
4580
  }
4581
});
4582

V
Vaidegi B 已提交
4583 4584
```

4585
### off('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
4586

4587
off(type: 'markReach'): void
V
Vaidegi B 已提交
4588

4589
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
4590

4591
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
4592

4593
**Parameters**
V
Vaidegi B 已提交
4594

4595 4596 4597
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
4598

W
wusongqing 已提交
4599
**Example**
V
Vaidegi B 已提交
4600

G
Gloria 已提交
4601
```js
4602
audioCapturer.off('markReach');
4603

V
Vaidegi B 已提交
4604 4605
```

4606
### on('periodReach')<sup>8+</sup>
V
Vaidegi B 已提交
4607

4608
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
4609

4610
Subscribes to period reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned.
V
Vaidegi B 已提交
4611

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

W
wusongqing 已提交
4614
**Parameters**
V
Vaidegi B 已提交
4615

4616 4617 4618 4619 4620
| Name     | Type              | Mandatory | Description                                                  |
| :------- | :---------------- | :-------- | :----------------------------------------------------------- |
| type     | string            | Yes       | Event type. The value is fixed at **'periodReach'**.         |
| frame    | number            | Yes       | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback\<number> | Yes       | Callback invoked when the event is triggered.                |
V
Vaidegi B 已提交
4621

W
wusongqing 已提交
4622
**Example**
V
Vaidegi B 已提交
4623

G
Gloria 已提交
4624
```js
4625 4626 4627
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
4628
  }
4629
});
4630

V
Vaidegi B 已提交
4631 4632
```

4633
### off('periodReach')<sup>8+</sup>
V
Vaidegi B 已提交
4634

4635
off(type: 'periodReach'): void
V
Vaidegi B 已提交
4636

4637
Unsubscribes from period reached events.
V
Vaidegi B 已提交
4638

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

4641
**Parameters**
V
Vaidegi B 已提交
4642

4643 4644 4645
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
4646

W
wusongqing 已提交
4647
**Example**
V
Vaidegi B 已提交
4648

G
Gloria 已提交
4649
```js
4650
audioCapturer.off('periodReach')
4651

V
Vaidegi B 已提交
4652 4653
```

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

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

4658
Subscribes to state change events.
V
Vaidegi B 已提交
4659

4660
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
4661

W
wusongqing 已提交
4662
**Parameters**
V
Vaidegi B 已提交
4663

4664 4665 4666 4667
| Name     | Type                       | Mandatory | Description                                                  |
| :------- | :------------------------- | :-------- | :----------------------------------------------------------- |
| type     | string                     | Yes       | Event type. The value **stateChange** means the state change event. |
| callback | [AudioState](#audiostate8) | Yes       | Callback used to return the state change.                    |
V
Vaidegi B 已提交
4668

W
wusongqing 已提交
4669
**Example**
V
Vaidegi B 已提交
4670

G
Gloria 已提交
4671
```js
4672 4673 4674 4675 4676 4677
audioCapturer.on('stateChange', (state) => {
  if (state == 1) {
    console.info('audio capturer state is: STATE_PREPARED');
  }
  if (state == 2) {
    console.info('audio capturer state is: STATE_RUNNING');
4678
  }
4679
});
4680

V
Vaidegi B 已提交
4681 4682
```

4683
## ToneType<sup>9+</sup>
V
Vaidegi B 已提交
4684

4685
Enumerates the tone types of the player.
4686

4687
**System API**: This is a system API.
V
Vaidegi B 已提交
4688

4689
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4690

4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719
| Name                                             | Default Value | Description                                   |
| :----------------------------------------------- | :------------ | :-------------------------------------------- |
| TONE_TYPE_DIAL_0                                 | 0             | DTMF tone of key 0.                           |
| TONE_TYPE_DIAL_1                                 | 1             | DTMF tone of key 1.                           |
| TONE_TYPE_DIAL_2                                 | 2             | DTMF tone of key 2.                           |
| TONE_TYPE_DIAL_3                                 | 3             | DTMF tone of key 3.                           |
| TONE_TYPE_DIAL_4                                 | 4             | DTMF tone of key 4.                           |
| TONE_TYPE_DIAL_5                                 | 5             | DTMF tone of key 5.                           |
| TONE_TYPE_DIAL_6                                 | 6             | DTMF tone of key 6.                           |
| TONE_TYPE_DIAL_7                                 | 7             | DTMF tone of key 7.                           |
| TONE_TYPE_DIAL_8                                 | 8             | DTMF tone of key 8.                           |
| TONE_TYPE_DIAL_9                                 | 9             | DTMF tone of key 9.                           |
| TONE_TYPE_DIAL_S                                 | 10            | DTMF tone of the star key (*).                |
| TONE_TYPE_DIAL_P                                 | 11            | DTMF tone of the pound key (#).               |
| TONE_TYPE_DIAL_A                                 | 12            | DTMF tone of key A.                           |
| TONE_TYPE_DIAL_B                                 | 13            | DTMF tone of key B.                           |
| TONE_TYPE_DIAL_C                                 | 14            | DTMF tone of key C.                           |
| TONE_TYPE_DIAL_D                                 | 15            | DTMF tone of key D.                           |
| TONE_TYPE_COMMON_SUPERVISORY_DIAL                | 100           | Supervisory tone - dial tone.                 |
| TONE_TYPE_COMMON_SUPERVISORY_BUSY                | 101           | Supervisory tone - busy.                      |
| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION          | 102           | Supervisory tone - congestion.                |
| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK           | 103           | Supervisory tone - radio path acknowledgment. |
| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104           | Supervisory tone - radio path not available.  |
| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING        | 106           | Supervisory tone - call waiting tone.         |
| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE            | 107           | Supervisory tone - ringing tone.              |
| TONE_TYPE_COMMON_PROPRIETARY_BEEP                | 200           | Proprietary tone - beep tone.                 |
| TONE_TYPE_COMMON_PROPRIETARY_ACK                 | 201           | Proprietary tone - ACK.                       |
| TONE_TYPE_COMMON_PROPRIETARY_PROMPT              | 203           | Proprietary tone - PROMPT.                    |
| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP         | 204           | Proprietary tone - double beep tone.          |
V
Vaidegi B 已提交
4720

4721
## TonePlayer<sup>9+</sup>
V
Vaidegi B 已提交
4722

4723
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
4724

4725
**System API**: This is a system API.
V
Vaidegi B 已提交
4726

4727
### load<sup>9+</sup>
V
Vaidegi B 已提交
4728

4729
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
4730

4731
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4732

4733
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4734

W
wusongqing 已提交
4735
**Parameters**
V
Vaidegi B 已提交
4736

4737 4738 4739 4740
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4741

W
wusongqing 已提交
4742
**Example**
V
Vaidegi B 已提交
4743

G
Gloria 已提交
4744
```js
4745 4746 4747 4748 4749 4750 4751
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
  if (err) {
    console.error(`callback call load failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call load success');
  }
4752
});
4753

V
Vaidegi B 已提交
4754 4755
```

4756
### load<sup>9+</sup>
V
Vaidegi B 已提交
4757

4758
load(type: ToneType): Promise&lt;void&gt;
V
Vaidegi B 已提交
4759

4760
Loads the DTMF tone configuration. This API uses a promise to return the result.
V
Vaidegi B 已提交
4761

4762 4763 4764 4765 4766 4767 4768
**System capability**: SystemCapability.Multimedia.Audio.Tone

**Parameters**

| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
4769

W
wusongqing 已提交
4770
**Return value**
V
Vaidegi B 已提交
4771

4772 4773 4774
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4775

W
wusongqing 已提交
4776
**Example**
V
Vaidegi B 已提交
4777

G
Gloria 已提交
4778
```js
4779 4780 4781 4782
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
4783
});
4784

V
Vaidegi B 已提交
4785 4786
```

4787
### start<sup>9+</sup>
V
Vaidegi B 已提交
4788

4789
start(callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
4790

4791
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4792

4793
**System capability**: SystemCapability.Multimedia.Audio.Tone
4794

W
wusongqing 已提交
4795
**Parameters**
V
Vaidegi B 已提交
4796

4797 4798 4799
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4800

W
wusongqing 已提交
4801
**Example**
V
Vaidegi B 已提交
4802

G
Gloria 已提交
4803
```js
4804
tonePlayer.start((err) => {
4805
  if (err) {
4806 4807 4808 4809
    console.error(`callback call start failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call start success');
4810
  }
4811
});
4812

V
Vaidegi B 已提交
4813 4814
```

4815
### start<sup>9+</sup>
V
Vaidegi B 已提交
4816

4817
start(): Promise&lt;void&gt;
V
Vaidegi B 已提交
4818

4819
Starts DTMF tone playing. This API uses a promise to return the result.
4820

4821
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4822

W
wusongqing 已提交
4823
**Return value**
V
Vaidegi B 已提交
4824

4825 4826 4827
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4828

W
wusongqing 已提交
4829
**Example**
V
Vaidegi B 已提交
4830

G
Gloria 已提交
4831
```js
4832 4833 4834 4835
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
4836
});
4837

V
Vaidegi B 已提交
4838 4839
```

4840
### stop<sup>9+</sup>
V
Vaidegi B 已提交
4841

4842
stop(callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
4843

4844
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4845

4846
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4847

W
wusongqing 已提交
4848
**Parameters**
4849

4850 4851 4852
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4853

W
wusongqing 已提交
4854
**Example**
V
Vaidegi B 已提交
4855

G
Gloria 已提交
4856
```js
4857
tonePlayer.stop((err) => {
4858
  if (err) {
4859 4860
    console.error(`callback call stop error: ${err.message}`);
    return;
4861
  } else {
4862
    console.error('callback call stop success ');
4863
  }
4864
});
4865

V
Vaidegi B 已提交
4866 4867
```

4868
### stop<sup>9+</sup>
V
Vaidegi B 已提交
4869

4870
stop(): Promise&lt;void&gt;
4871

4872
Stops the tone that is being played. This API uses a promise to return the result.
V
Vaidegi B 已提交
4873

4874
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4875

W
wusongqing 已提交
4876
**Return value**
V
Vaidegi B 已提交
4877

4878
| Type           | Description                        |
4879 4880
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4881

W
wusongqing 已提交
4882
**Example**
V
Vaidegi B 已提交
4883

G
Gloria 已提交
4884
```js
4885 4886 4887 4888
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
4889
});
4890

V
Vaidegi B 已提交
4891 4892
```

4893
### release<sup>9+</sup>
V
Vaidegi B 已提交
4894

4895
release(callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
4896

4897
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4898

4899
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4900

W
wusongqing 已提交
4901
**Parameters**
4902

4903 4904 4905
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4906

W
wusongqing 已提交
4907
**Example**
V
Vaidegi B 已提交
4908

G
Gloria 已提交
4909
```js
4910 4911 4912 4913 4914 4915 4916
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
4917
});
4918

V
Vaidegi B 已提交
4919 4920
```

4921
### release<sup>9+</sup>
V
Vaidegi B 已提交
4922

4923
release(): Promise&lt;void&gt;
4924

4925
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4926

4927
**System capability**: SystemCapability.Multimedia.Audio.Tone
V
Vaidegi B 已提交
4928

W
wusongqing 已提交
4929
**Return value**
V
Vaidegi B 已提交
4930

4931 4932 4933
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
4934

W
wusongqing 已提交
4935
**Example**
V
Vaidegi B 已提交
4936

G
Gloria 已提交
4937
```js
4938 4939 4940 4941
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
4942
});
4943

V
Vaidegi B 已提交
4944
```
4945

4946
## ActiveDeviceType<sup>(deprecated)</sup>
W
wusongqing 已提交
4947

4948
Enumerates the active device types.
W
wusongqing 已提交
4949

4950 4951 4952
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
W
wusongqing 已提交
4953

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

4956 4957 4958 4959
| Name          | Default Value | Description                                                  |
| ------------- | ------------- | ------------------------------------------------------------ |
| SPEAKER       | 2             | Speaker.                                                     |
| BLUETOOTH_SCO | 7             | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
W
wusongqing 已提交
4960

4961
## InterruptActionType<sup>(deprecated)</sup>
W
wusongqing 已提交
4962

4963
Enumerates the returned event types for audio interruption events.
W
wusongqing 已提交
4964

4965 4966
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9.
W
wusongqing 已提交
4967

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

4970 4971 4972 4973
| Name           | Default Value | Description               |
| -------------- | ------------- | ------------------------- |
| TYPE_ACTIVATED | 0             | Focus gain event.         |
| TYPE_INTERRUPT | 1             | Audio interruption event. |
4974

4975
## AudioInterrupt<sup>(deprecated)</sup>
W
wusongqing 已提交
4976

4977 4978 4979
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
W
wusongqing 已提交
4980

4981
Describes input parameters of audio interruption events.
W
wusongqing 已提交
4982 4983 4984

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

4985 4986 4987 4988 4989
| Name            | Type                        | Mandatory | Description                                                  |
| --------------- | --------------------------- | --------- | ------------------------------------------------------------ |
| streamUsage     | [StreamUsage](#streamusage) | Yes       | Audio stream usage.                                          |
| contentType     | [ContentType](#contenttype) | Yes       | Audio content type.                                          |
| pauseWhenDucked | boolean                     | Yes       | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite. |
4990

4991
## InterruptAction<sup>(deprecated)</sup>
V
Vaidegi B 已提交
4992

4993 4994 4995
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
V
Vaidegi B 已提交
4996

4997
Describes the callback invoked for audio interruption or focus gain events.
4998

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

5001 5002 5003 5004 5005 5006
| Name       | Type                                        | Mandatory | Description                                                  |
| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes       | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event. |
| type       | [InterruptType](#interrupttype)             | No        | Type of the audio interruption event.                        |
| hint       | [InterruptHint](#interrupthint)             | No        | Hint provided along with the audio interruption event.       |
| activated  | boolean                                     | No        | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released. |
V
Vaidegi B 已提交
5007

5008
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5009

5010
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
5011

5012
Sets the volume for a stream. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5013

5014 5015 5016
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.
5017

5018
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
5019

5020
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
5021

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

W
wusongqing 已提交
5024
**Parameters**
5025

5026 5027 5028 5029 5030
| Name       | Type                                | Mandatory | Description                                                  |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                           |
| volume     | number                              | Yes       | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**. |
| callback   | AsyncCallback&lt;void&gt;           | Yes       | Callback used to return the result.                          |
5031

W
wusongqing 已提交
5032
**Example**
5033

G
Gloria 已提交
5034
```js
5035 5036 5037 5038
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
  if (err) {
    console.error(`Failed to set the volume. ${err}`);
    return;
5039
  }
5040
  console.info('Callback invoked to indicate a successful volume setting.');
5041
});
5042

5043 5044
```

5045
### setVolume<sup>(deprecated)</sup>
5046

5047
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
5048

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

5051 5052 5053
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.
5054

5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

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

**Parameters**

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

5068
**Return value**
5069

5070 5071 5072
| Type                | Description                        |
| ------------------- | ---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
5073

W
wusongqing 已提交
5074
**Example**
5075

G
Gloria 已提交
5076
```js
5077 5078 5079
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.info('Promise returned to indicate a successful volume setting.');
});
5080

5081 5082
```

5083
### getVolume<sup>(deprecated)</sup>
5084

5085
getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
5086

5087
Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
5088

5089 5090 5091 5092 5093
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
5095
**Parameters**
5096

5097 5098 5099 5100
| Name       | Type                                | Mandatory | Description                         |
| ---------- | ----------------------------------- | --------- | ----------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                  |
| callback   | AsyncCallback&lt;number&gt;         | Yes       | Callback used to return the volume. |
5101

W
wusongqing 已提交
5102
**Example**
5103

G
Gloria 已提交
5104
```js
5105 5106 5107 5108
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the volume. ${err}`);
    return;
5109
  }
5110
  console.info('Callback invoked to indicate that the volume is obtained.');
5111
});
5112

5113 5114
```

5115
### getVolume<sup>(deprecated)</sup>
5116

5117
getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
5118

5119
Obtains the volume of a stream. This API uses a promise to return the result.
5120

5121 5122 5123 5124 5125
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
5127
**Parameters**
5128

5129 5130 5131 5132 5133 5134 5135 5136 5137
| Name       | Type                                | Mandatory | Description        |
| ---------- | ----------------------------------- | --------- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type. |

**Return value**

| Type                  | Description                        |
| --------------------- | ---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume. |
5138

W
wusongqing 已提交
5139
**Example**
5140

G
Gloria 已提交
5141
```js
5142 5143 5144
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
});
5145

5146
```
V
Vaidegi B 已提交
5147

5148
### getMinVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5149

5150
getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
V
Vaidegi B 已提交
5151

5152
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5153

5154 5155 5156 5157 5158
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
5160
**Parameters**
5161

5162 5163 5164 5165
| Name       | Type                                | Mandatory | Description                                 |
| ---------- | ----------------------------------- | --------- | ------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                          |
| callback   | AsyncCallback&lt;number&gt;         | Yes       | Callback used to return the minimum volume. |
5166

W
wusongqing 已提交
5167
**Example**
5168

G
Gloria 已提交
5169
```js
5170 5171 5172 5173
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the minimum volume. ${err}`);
    return;
5174
  }
5175
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
5176
});
5177

5178
```
V
Vaidegi B 已提交
5179

5180
### getMinVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5181

5182
getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
V
Vaidegi B 已提交
5183

5184
Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
V
Vaidegi B 已提交
5185

5186 5187 5188
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.
V
Vaidegi B 已提交
5189

5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202
**System capability**: SystemCapability.Multimedia.Audio.Volume

**Parameters**

| Name       | Type                                | Mandatory | Description        |
| ---------- | ----------------------------------- | --------- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type. |

**Return value**

| Type                  | Description                                |
| --------------------- | ------------------------------------------ |
| Promise&lt;number&gt; | Promise used to return the minimum volume. |
V
Vaidegi B 已提交
5203

W
wusongqing 已提交
5204
**Example**
V
Vaidegi B 已提交
5205

G
Gloria 已提交
5206
```js
5207 5208 5209
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
});
5210

V
Vaidegi B 已提交
5211 5212
```

5213
### getMaxVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5214

5215
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
V
Vaidegi B 已提交
5216

5217
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5218

5219 5220 5221 5222 5223
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
5225
**Parameters**
V
Vaidegi B 已提交
5226

5227 5228 5229 5230
| Name       | Type                                | Mandatory | Description                                 |
| ---------- | ----------------------------------- | --------- | ------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                          |
| callback   | AsyncCallback&lt;number&gt;         | Yes       | Callback used to return the maximum volume. |
V
Vaidegi B 已提交
5231

W
wusongqing 已提交
5232
**Example**
V
Vaidegi B 已提交
5233

G
Gloria 已提交
5234
```js
5235
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
5236
  if (err) {
5237 5238
    console.error(`Failed to obtain the maximum volume. ${err}`);
    return;
5239
  }
5240
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
5241
});
5242

V
Vaidegi B 已提交
5243 5244
```

5245
### getMaxVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5246

5247
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
V
Vaidegi B 已提交
5248

5249
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
V
Vaidegi B 已提交
5250

5251 5252 5253
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.
V
Vaidegi B 已提交
5254

5255 5256 5257 5258 5259 5260 5261
**System capability**: SystemCapability.Multimedia.Audio.Volume

**Parameters**

| Name       | Type                                | Mandatory | Description        |
| ---------- | ----------------------------------- | --------- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type. |
V
Vaidegi B 已提交
5262

W
wusongqing 已提交
5263
**Return value**
V
Vaidegi B 已提交
5264

5265 5266 5267
| Type                  | Description                                |
| --------------------- | ------------------------------------------ |
| Promise&lt;number&gt; | Promise used to return the maximum volume. |
V
Vaidegi B 已提交
5268

W
wusongqing 已提交
5269
**Example**
V
Vaidegi B 已提交
5270

G
Gloria 已提交
5271
```js
5272 5273
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.info('Promised returned to indicate that the maximum volume is obtained.');
5274
});
5275

5276
```
V
Vaidegi B 已提交
5277

5278
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5279

5280
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
5281

5282
Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5283

5284 5285 5286 5287 5288 5289 5290 5291 5292
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.

**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

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

W
wusongqing 已提交
5294
**Parameters**
V
Vaidegi B 已提交
5295

5296 5297 5298 5299 5300
| Name       | Type                                | Mandatory | Description                                                  |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                           |
| mute       | boolean                             | Yes       | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite. |
| callback   | AsyncCallback&lt;void&gt;           | Yes       | Callback used to return the result.                          |
V
Vaidegi B 已提交
5301

W
wusongqing 已提交
5302
**Example**
V
Vaidegi B 已提交
5303

G
Gloria 已提交
5304
```js
5305
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
5306
  if (err) {
5307 5308
    console.error(`Failed to mute the stream. ${err}`);
    return;
5309
  }
5310
  console.info('Callback invoked to indicate that the stream is muted.');
5311
});
5312

V
Vaidegi B 已提交
5313 5314
```

5315
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5316

5317
mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
5318

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

5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.

**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

**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. |
V
Vaidegi B 已提交
5337

W
wusongqing 已提交
5338
**Return value**
V
Vaidegi B 已提交
5339

5340 5341 5342
| Type                | Description                        |
| ------------------- | ---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
V
Vaidegi B 已提交
5343

W
wusongqing 已提交
5344
**Example**
V
Vaidegi B 已提交
5345

5346

G
Gloria 已提交
5347
```js
5348 5349
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.info('Promise returned to indicate that the stream is muted.');
5350
});
5351

V
Vaidegi B 已提交
5352 5353
```

5354
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
5355

5356
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
V
Vaidegi B 已提交
5357

5358
Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
5359

5360 5361 5362 5363 5364
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
5366
**Parameters**
5367

5368 5369 5370 5371
| Name       | Type                                | Mandatory | Description                                                  |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                           |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes       | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite. |
5372

W
wusongqing 已提交
5373
**Example**
5374

G
Gloria 已提交
5375
```js
5376
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
5377
  if (err) {
5378 5379
    console.error(`Failed to obtain the mute status. ${err}`);
    return;
5380
  }
5381
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
5382
});
5383

5384 5385
```

5386
### isMute<sup>(deprecated)</sup>
5387

5388
isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
5389

5390
Checks whether a stream is muted. This API uses a promise to return the result.
5391

5392 5393 5394
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.
5395

5396 5397 5398 5399 5400 5401 5402
**System capability**: SystemCapability.Multimedia.Audio.Volume

**Parameters**

| Name       | Type                                | Mandatory | Description        |
| ---------- | ----------------------------------- | --------- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type. |
5403

W
wusongqing 已提交
5404
**Return value**
5405

5406 5407 5408
| Type                   | Description                                                  |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite. |
5409

W
wusongqing 已提交
5410
**Example**
5411

G
Gloria 已提交
5412
```js
5413 5414
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
5415
});
5416

5417 5418
```

5419
### isActive<sup>(deprecated)</sup>
5420

5421
isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
5422

5423
Checks whether a stream is active. This API uses an asynchronous callback to return the result.
5424

5425 5426 5427 5428 5429
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**.

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

W
wusongqing 已提交
5431
**Parameters**
5432

5433 5434 5435 5436
| Name       | Type                                | Mandatory | Description                                                  |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type.                                           |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes       | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite. |
5437

W
wusongqing 已提交
5438
**Example**
5439

G
Gloria 已提交
5440
```js
5441
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
5442
  if (err) {
5443 5444
    console.error(`Failed to obtain the active status of the stream. ${err}`);
    return;
5445
  }
5446
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
5447
});
5448

5449 5450
```

5451
### isActive<sup>(deprecated)</sup>
5452

5453
isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
5454

5455
Checks whether a stream is active. This API uses a promise to return the result.
5456

5457 5458 5459
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**.
5460

5461 5462 5463 5464 5465 5466 5467
**System capability**: SystemCapability.Multimedia.Audio.Volume

**Parameters**

| Name       | Type                                | Mandatory | Description        |
| ---------- | ----------------------------------- | --------- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes       | Audio stream type. |
5468

W
wusongqing 已提交
5469
**Return value**
5470

5471 5472 5473
| Type                   | Description                                                  |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite. |
5474

W
wusongqing 已提交
5475
**Example**
5476

G
Gloria 已提交
5477
```js
5478 5479
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
5480
});
5481

5482 5483
```

5484
### setRingerMode<sup>(deprecated)</sup>
5485

5486
setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
5487

5488
Sets the ringer mode. This API uses an asynchronous callback to return the result.
5489

5490 5491 5492 5493 5494 5495 5496 5497 5498
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.

**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer.

**System capability**: SystemCapability.Multimedia.Audio.Communication
5499

W
wusongqing 已提交
5500
**Parameters**
5501

5502 5503 5504 5505
| Name     | Type                            | Mandatory | Description                         |
| -------- | ------------------------------- | --------- | ----------------------------------- |
| mode     | [AudioRingMode](#audioringmode) | Yes       | Ringer mode.                        |
| callback | AsyncCallback&lt;void&gt;       | Yes       | Callback used to return the result. |
5506

W
wusongqing 已提交
5507
**Example**
5508

G
Gloria 已提交
5509
```js
5510
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
5511
  if (err) {
5512 5513
    console.error(`Failed to set the ringer mode.​ ${err}`);
    return;
5514
  }
5515
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
5516
});
5517

5518 5519
```

5520
### setRingerMode<sup>(deprecated)</sup>
5521

5522
setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
5523

5524
Sets the ringer mode. This API uses a promise to return the result.
5525

5526 5527 5528
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.
5529

5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

This permission is required only for muting or unmuting the ringer.

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

**Parameters**

| Name | Type                            | Mandatory | Description  |
| ---- | ------------------------------- | --------- | ------------ |
| mode | [AudioRingMode](#audioringmode) | Yes       | Ringer mode. |
5541

W
wusongqing 已提交
5542
**Return value**
5543

5544 5545 5546
| Type                | Description                        |
| ------------------- | ---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
5547

W
wusongqing 已提交
5548
**Example**
5549

G
Gloria 已提交
5550
```js
5551 5552
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
5553
});
5554

5555 5556
```

5557
### getRingerMode<sup>(deprecated)</sup>
5558

5559
getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
5560

5561
Obtains the ringer mode. This API uses an asynchronous callback to return the result.
5562

5563 5564 5565
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
5566

5567
**System capability**: SystemCapability.Multimedia.Audio.Communication
5568

W
wusongqing 已提交
5569
**Parameters**
5570

5571 5572 5573
| Name     | Type                                                 | Mandatory | Description                              |
| -------- | ---------------------------------------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes       | Callback used to return the ringer mode. |
5574

W
wusongqing 已提交
5575
**Example**
5576

G
Gloria 已提交
5577
```js
5578 5579 5580 5581
audioManager.getRingerMode((err, value) => {
  if (err) {
    console.error(`Failed to obtain the ringer mode.​ ${err}`);
    return;
5582
  }
5583
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
J
jiao_yanlin 已提交
5584
});
5585

5586 5587
```

5588
### getRingerMode<sup>(deprecated)</sup>
5589

5590
getRingerMode(): Promise&lt;AudioRingMode&gt;
5591

5592
Obtains the ringer mode. This API uses a promise to return the result.
5593

5594 5595 5596
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.
5597

5598
**System capability**: SystemCapability.Multimedia.Audio.Communication
5599

W
wusongqing 已提交
5600
**Return value**
5601

5602 5603 5604
| Type                                           | Description                             |
| ---------------------------------------------- | --------------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode. |
5605

W
wusongqing 已提交
5606
**Example**
5607

G
Gloria 已提交
5608
```js
5609 5610
audioManager.getRingerMode().then((value) => {
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
5611
});
5612

5613 5614
```

5615
### getDevices<sup>(deprecated)</sup>
5616

5617
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
5618

5619
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
5620

5621 5622 5623
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
5624

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

W
wusongqing 已提交
5627
**Parameters**
5628

5629 5630 5631 5632
| Name       | Type                                                         | Mandatory | Description                              |
| ---------- | ------------------------------------------------------------ | --------- | ---------------------------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes       | Audio device flag.                       |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes       | Callback used to return the device list. |
5633

W
wusongqing 已提交
5634
**Example**
5635

G
Gloria 已提交
5636
```js
5637 5638 5639 5640 5641 5642
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the device list. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the device list is obtained.');
5643
});
5644

5645 5646
```

5647
### getDevices<sup>(deprecated)</sup>
5648

5649
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
5650

5651
Obtains the audio devices with a specific flag. This API uses a promise to return the result.
5652

5653 5654 5655
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.
5656

5657 5658 5659 5660 5661 5662 5663
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

| Name       | Type                      | Mandatory | Description        |
| ---------- | ------------------------- | --------- | ------------------ |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes       | Audio device flag. |
5664

W
wusongqing 已提交
5665
**Return value**
5666

5667 5668 5669
| Type                                                         | Description                             |
| ------------------------------------------------------------ | --------------------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list. |
5670

W
wusongqing 已提交
5671
**Example**
5672

G
Gloria 已提交
5673
```js
5674 5675
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
5676
});
5677

5678 5679
```

5680
### setDeviceActive<sup>(deprecated)</sup>
5681

5682
setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
5683

5684
Sets a device to the active state. This API uses an asynchronous callback to return the result.
5685

5686 5687 5688
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
5689

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

W
wusongqing 已提交
5692
**Parameters**
5693

5694 5695 5696 5697 5698
| Name       | Type                                  | Mandatory | Description                                                  |
| ---------- | ------------------------------------- | --------- | ------------------------------------------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes       | Audio device type.                                           |
| active     | boolean                               | Yes       | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
| callback   | AsyncCallback&lt;void&gt;             | Yes       | Callback used to return the result.                          |
5699

W
wusongqing 已提交
5700
**Example**
5701

G
Gloria 已提交
5702
```js
5703 5704 5705 5706
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
  if (err) {
    console.error(`Failed to set the active status of the device. ${err}`);
    return;
5707
  }
5708
  console.info('Callback invoked to indicate that the device is set to the active status.');
5709
});
5710

5711 5712
```

5713
### setDeviceActive<sup>(deprecated)</sup>
W
wusongqing 已提交
5714

5715
setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
5716

5717
Sets a device to the active state. This API uses a promise to return the result.
5718

5719 5720 5721
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
5722

5723 5724 5725 5726 5727 5728 5729 5730
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

| Name       | Type                                  | Mandatory | Description                                                  |
| ---------- | ------------------------------------- | --------- | ------------------------------------------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes       | Audio device type.                                           |
| active     | boolean                               | Yes       | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
5731

W
wusongqing 已提交
5732
**Return value**
5733

5734 5735 5736
| Type                | Description                        |
| ------------------- | ---------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
5737

W
wusongqing 已提交
5738
**Example**
5739

5740

G
Gloria 已提交
5741
```js
5742 5743
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
5744
});
5745

5746 5747
```

5748
### isDeviceActive<sup>(deprecated)</sup>
W
wusongqing 已提交
5749

5750
isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
5751

5752
Checks whether a device is active. This API uses an asynchronous callback to return the result.
5753

5754 5755 5756
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
5757

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

W
wusongqing 已提交
5760
**Parameters**
5761

5762 5763 5764 5765
| Name       | Type                                  | Mandatory | Description                                             |
| ---------- | ------------------------------------- | --------- | ------------------------------------------------------- |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes       | Audio device type.                                      |
| callback   | AsyncCallback&lt;boolean&gt;          | Yes       | Callback used to return the active state of the device. |
5766

W
wusongqing 已提交
5767
**Example**
5768

G
Gloria 已提交
5769
```js
5770 5771 5772 5773
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the active status of the device. ${err}`);
    return;
5774
  }
5775
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
5776
});
5777

5778 5779
```

5780
### isDeviceActive<sup>(deprecated)</sup>
5781

5782
isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
5783

5784
Checks whether a device is active. This API uses a promise to return the result.
5785

5786 5787 5788
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.
5789

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

W
wusongqing 已提交
5792
**Parameters**
5793

5794 5795 5796 5797 5798 5799 5800 5801 5802
| Name       | Type                                  | Mandatory | Description        |
| ---------- | ------------------------------------- | --------- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes       | Audio device type. |

**Return value**

| Type                   | Description                                            |
| ---------------------- | ------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device. |
5803

W
wusongqing 已提交
5804
**Example**
5805

G
Gloria 已提交
5806
```js
5807 5808
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
5809
});
5810

5811 5812
```

5813
### setMicrophoneMute<sup>(deprecated)</sup>
5814

5815
setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
5816

5817
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
5818

5819 5820 5821 5822 5823 5824 5825
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.

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

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

W
wusongqing 已提交
5827
**Parameters**
5828

5829 5830 5831 5832
| Name     | Type                      | Mandatory | Description                                                  |
| -------- | ------------------------- | --------- | ------------------------------------------------------------ |
| mute     | boolean                   | Yes       | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite. |
| callback | AsyncCallback&lt;void&gt; | Yes       | Callback used to return the result.                          |
5833

W
wusongqing 已提交
5834
**Example**
5835

G
Gloria 已提交
5836
```js
5837 5838 5839 5840 5841 5842 5843
audioManager.setMicrophoneMute(true, (err) => {
  if (err) {
    console.error(`Failed to mute the microphone. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the microphone is muted.');
});
5844

5845 5846
```

5847
### setMicrophoneMute<sup>(deprecated)</sup>
5848

5849
setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
5850

5851
Mutes or unmutes the microphone. This API uses a promise to return the result.
5852

5853 5854 5855 5856 5857 5858 5859
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.

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

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

W
wusongqing 已提交
5861
**Parameters**
5862

5863 5864 5865 5866 5867 5868 5869 5870 5871
| 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&lt;void&gt; | Promise used to return the result. |
5872

W
wusongqing 已提交
5873
**Example**
5874

G
Gloria 已提交
5875
```js
5876 5877
audioManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
5878
});
5879

5880
```
5881

5882
### isMicrophoneMute<sup>(deprecated)</sup>
5883

5884
isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
5885

5886
Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
5887

5888 5889 5890
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
5891

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

5894
**System capability**: SystemCapability.Multimedia.Audio.Device
5895 5896 5897

**Parameters**

5898 5899 5900
| Name     | Type                         | Mandatory | Description                                                  |
| -------- | ---------------------------- | --------- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes       | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite. |
5901 5902 5903 5904

**Example**

```js
5905
audioManager.isMicrophoneMute((err, value) => {
5906
  if (err) {
5907
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
5908 5909
    return;
  }
5910
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
5911 5912 5913 5914
});

```

5915
### isMicrophoneMute<sup>(deprecated)</sup>
5916

5917
isMicrophoneMute(): Promise&lt;boolean&gt;
5918

5919
Checks whether the microphone is muted. This API uses a promise to return the result.
5920

5921 5922 5923
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
5924

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

5927
**System capability**: SystemCapability.Multimedia.Audio.Device
5928 5929 5930

**Return value**

5931 5932 5933
| Type                   | Description                                                  |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite. |
5934 5935 5936 5937

**Example**

```js
5938 5939
audioManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
5940 5941 5942 5943
});

```

5944
### on('volumeChange')<sup>(deprecated)</sup>
5945

5946
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
5947

5948 5949 5950
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioVolumeManager**.
5951

5952 5953 5954 5955 5956 5957 5958
Subscribes to system volume change events.

**System API**: This is a system API.

Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance.

**System capability**: SystemCapability.Multimedia.Audio.Volume
5959 5960 5961

**Parameters**

5962 5963 5964 5965
| Name     | Type                                   | Mandatory | Description                                                  |
| -------- | -------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                 | Yes       | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when a system volume change is detected. |
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes       | Callback used to return the result.                          |
5966 5967 5968 5969

**Example**

```js
5970 5971 5972 5973
audioManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
5974 5975 5976 5977
});

```

5978
### on('ringerModeChange')<sup>(deprecated)</sup>
5979

5980
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
5981

5982
Subscribes to ringer mode change events.
5983

5984 5985 5986
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('ringerModeChange')](#onringermodechange9) in **AudioVolumeGroupManager**.
5987

5988
**System API**: This is a system API.
5989

5990 5991 5992 5993 5994 5995 5996 5997
**System capability**: SystemCapability.Multimedia.Audio.Communication

**Parameters**

| Name     | Type                                      | Mandatory | Description                                                  |
| -------- | ----------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                    | Yes       | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected. |
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes       | Callback used to return the result.                          |
5998 5999 6000 6001

**Example**

```js
6002 6003
audioManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
6004 6005 6006 6007
});

```

6008
### on('deviceChange')<sup>(deprecated)</sup>
6009

6010
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
6011

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

6014 6015 6016 6017 6018
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioRoutingManager**.

**System capability**: SystemCapability.Multimedia.Audio.Device
6019 6020 6021

**Parameters**

6022 6023 6024 6025
| Name     | Type                                                 | Mandatory | Description                                                  |
| :------- | :--------------------------------------------------- | :-------- | :----------------------------------------------------------- |
| type     | string                                               | Yes       | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes       | Callback used to return the device update details.           |
6026 6027 6028 6029

**Example**

```js
6030 6031 6032 6033 6034
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} `);
6035 6036 6037 6038
});

```

6039
### off('deviceChange')<sup>(deprecated)</sup>
6040

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

6043
Unsubscribes from device change events.
6044

6045 6046 6047
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off](#off9) in **AudioRoutingManager**.
6048

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

6051 6052 6053 6054 6055 6056
**Parameters**

| Name     | Type                                                | Mandatory | Description                                                  |
| -------- | --------------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                              | Yes       | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No        | Callback used to return the device update details.           |
6057 6058 6059 6060

**Example**

```js
6061 6062
audioManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
6063 6064 6065
});
```

6066
### on('interrupt')<sup>(deprecated)</sup>
6067

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

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

6072 6073 6074 6075 6076 6077 6078
Same as [on('audioInterrupt')](#onaudiointerrupt9), this API is used to listen for focus changes. However, this API is used in scenarios without audio streams (no **AudioRenderer** instance is created), such as frequency modulation (FM) and voice wakeup.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

**System capability**: SystemCapability.Multimedia.Audio.Renderer
6079 6080 6081

**Parameters**

6082 6083 6084 6085 6086
| Name      | Type                                          | Mandatory | Description                                                  |
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
| type      | string                                        | Yes       | Event type. The value **'interrupt'** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application. |
| interrupt | AudioInterrupt                                | Yes       | Audio interruption event type.                               |
| callback  | Callback<[InterruptAction](#interruptaction)> | Yes       | Callback invoked for the audio interruption event.           |
6087 6088 6089 6090

**Example**

```js
6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103
let interAudioInterrupt = {
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
};
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
  if (InterruptAction.actionType === 0) {
    console.info('An event to gain the audio focus starts.');
    console.info(`Focus gain event: ${InterruptAction} `);
  }
  if (InterruptAction.actionType === 1) {
    console.info('An audio interruption event starts.');
    console.info(`Audio interruption event: ${InterruptAction} `);
6104 6105
  }
});
6106

6107 6108
```

6109
### off('interrupt')<sup>(deprecated)</sup>
6110

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

6113
Unsubscribes from audio interruption events.
6114

6115 6116 6117
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6118

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

6121 6122 6123 6124 6125 6126 6127
**Parameters**

| Name      | Type                                          | Mandatory | Description                                                  |
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------ |
| type      | string                                        | Yes       | Event type. The value **'interrupt'** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application. |
| interrupt | AudioInterrupt                                | Yes       | Audio interruption event type.                               |
| callback  | Callback<[InterruptAction](#interruptaction)> | No        | Callback invoked for the audio interruption event.           |
6128 6129 6130 6131

**Example**

```js
6132 6133 6134 6135 6136 6137 6138 6139 6140 6141
let interAudioInterrupt = {
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
};
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
  if (InterruptAction.actionType === 0) {
      console.info('An event to release the audio focus starts.');
      console.info(`Focus release event: ${InterruptAction} `);
  }
6142 6143
});
```