js-apis-audio.md 230.4 KB
Newer Older
1
# @ohos.multimedia.audio (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
> **NOTE**
13
>
14
> 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.
15

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
| Name                                   | Type     | Readable | Writable| Description              |
| --------------------------------------- | ----------| ---- | ---- | ------------------ |
G
Gloria 已提交
26 27 28
| 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 featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
78
import fs from '@ohos.file.fs';
79
import audio from '@ohos.multimedia.audio';
80

81
let audioStreamInfo = {
82 83 84 85
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
86 87
}

88
let audioRendererInfo = {
89 90 91
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
  rendererFlags: 0
92 93
}

94
let audioRendererOptions = {
95 96
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
97 98 99
}

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

109
## audio.createAudioRenderer<sup>8+</sup>
110

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

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

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

W
wusongqing 已提交
117
**Parameters**
118

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

W
wusongqing 已提交
123
**Return value**
V
Vaidegi B 已提交
124

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

W
wusongqing 已提交
129
**Example**
V
Vaidegi B 已提交
130

G
Gloria 已提交
131
```js
132
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
133
import fs from '@ohos.file.fs';
134 135
import audio from '@ohos.multimedia.audio';

136
let audioStreamInfo = {
137 138 139 140
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_1,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
141 142
}

143
let audioRendererInfo = {
144 145 146
  content: audio.ContentType.CONTENT_TYPE_SPEECH,
  usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
  rendererFlags: 0
147 148
}

149
let audioRendererOptions = {
150 151
  streamInfo: audioStreamInfo,
  rendererInfo: audioRendererInfo
152 153
}

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

163
## audio.createAudioCapturer<sup>8+</sup>
164

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

167
Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
168

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

171 172
**Required permissions**: ohos.permission.MICROPHONE

W
wusongqing 已提交
173
**Parameters**
V
Vaidegi B 已提交
174

W
wusongqing 已提交
175 176 177 178 179 180
| Name  | Type                                           | Mandatory| Description            |
| :------- | :---------------------------------------------- | :--- | :--------------- |
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the **AudioCapturer** instance.|

**Example**
181

G
Gloria 已提交
182
```js
183
import audio from '@ohos.multimedia.audio';
184
let audioStreamInfo = {
185 186 187 188
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
189 190
}

191
let audioCapturerInfo = {
192 193
  source: audio.SourceType.SOURCE_TYPE_MIC,
  capturerFlags: 0
194 195
}

196
let audioCapturerOptions = {
197 198
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
199 200
}

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

211
## audio.createAudioCapturer<sup>8+</sup>
212

213
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
214

215
Creates an **AudioCapturer** instance. This API uses a promise to return the result.
W
wusongqing 已提交
216 217

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

219 220
**Required permissions**: ohos.permission.MICROPHONE

W
wusongqing 已提交
221
**Parameters**
222

W
wusongqing 已提交
223 224 225
| Name | Type                                          | Mandatory| Description            |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
226

W
wusongqing 已提交
227
**Return value**
V
Vaidegi B 已提交
228

W
wusongqing 已提交
229 230 231
| Type                                     | Description          |
| ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
V
Vaidegi B 已提交
232

W
wusongqing 已提交
233
**Example**
V
Vaidegi B 已提交
234

G
Gloria 已提交
235
```js
236 237
import audio from '@ohos.multimedia.audio';

238
let audioStreamInfo = {
239 240 241 242
  samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
  channels: audio.AudioChannel.CHANNEL_2,
  sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
  encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
243 244
}

245
let audioCapturerInfo = {
246 247
  source: audio.SourceType.SOURCE_TYPE_MIC,
  capturerFlags: 0
248 249
}

250
let audioCapturerOptions = {
251 252
  streamInfo: audioStreamInfo,
  capturerInfo: audioCapturerInfo
253
}
V
Vaidegi B 已提交
254

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

264 265 266 267 268 269 270 271
## 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

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

274 275 276 277 278 279 280 281 282 283 284 285
**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';

286
let audioRendererInfo = {
287 288 289
  content : audio.ContentType.CONTENT_TYPE_SONIFICATION,
  usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
  rendererFlags : 0
290
}
291
let tonePlayer;
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

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

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

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
**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';
330 331
let tonePlayer;
async function createTonePlayerBefore(){
332
  let audioRendererInfo = {
333 334 335
    content : audio.ContentType.CONTENT_TYPE_SONIFICATION,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0
336
  }
337
  tonePlayer = await audio.createTonePlayer(audioRendererInfo);
338 339 340
}
```

341
## AudioVolumeType
W
wusongqing 已提交
342

W
wusongqing 已提交
343
Enumerates the audio stream types.
W
wusongqing 已提交
344

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

347
| Name                        | Value     | Description      |
W
wusongqing 已提交
348 349 350 351
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
| RINGTONE                     | 2      | Audio stream for ringtones.    |
| MEDIA                        | 3      | Audio stream for media purpose.    |
G
Gloria 已提交
352 353
| ALARM<sup>10+</sup>          | 4      | Audio stream for alarming.    |
| ACCESSIBILITY<sup>10+</sup>  | 5      | Audio stream for accessibility.  |
W
wusongqing 已提交
354
| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
G
Gloria 已提交
355
| ULTRASONIC<sup>10+</sup>     | 10     | Audio stream for ultrasonic.<br>This is a system API.|
356 357 358 359 360 361 362 363 364 365
| 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.

366
| Name                        | Value     | Description      |
367 368 369
| ---------------------------- | ------ | ---------- |
| 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 已提交
370

W
wusongqing 已提交
371 372 373 374
## InterruptMode<sup>9+</sup>

Enumerates the audio interruption modes.

375
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
W
wusongqing 已提交
376

377
| Name                        | Value     | Description      |
W
wusongqing 已提交
378
| ---------------------------- | ------ | ---------- |
379 380
| SHARE_MODE                   | 0      | Shared mode.|
| INDEPENDENT_MODE             | 1      | Independent mode.|
W
wusongqing 已提交
381

382
## DeviceFlag
W
wusongqing 已提交
383

W
wusongqing 已提交
384
Enumerates the audio device flags.
W
wusongqing 已提交
385

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

388
| Name                           |  Value    | Description                                             |
G
Gloria 已提交
389
| ------------------------------- | ------ | ------------------------------------------------- |
390
| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | No device.<br>This is a system API.       |
G
Gloria 已提交
391 392 393
| OUTPUT_DEVICES_FLAG             | 1      | Output device.|
| INPUT_DEVICES_FLAG              | 2      | Input device.|
| ALL_DEVICES_FLAG                | 3      | All devices.|
394 395 396
| 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. |
397 398

## DeviceRole
W
wusongqing 已提交
399

W
wusongqing 已提交
400 401 402
Enumerates the audio device roles.

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

404
| Name         |  Value   | Description          |
W
wusongqing 已提交
405 406 407
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
408

409
## DeviceType
W
wusongqing 已提交
410

W
wusongqing 已提交
411
Enumerates the audio device types.
W
wusongqing 已提交
412

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

415
| Name                | Value    | Description                                                     |
G
Gloria 已提交
416 417 418 419 420 421 422 423 424 425 426
| ---------------------| ------ | --------------------------------------------------------- |
| 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 已提交
427

428
## CommunicationDeviceType<sup>9+</sup>
V
Vaidegi B 已提交
429

430
Enumerates the device types used for communication.
W
wusongqing 已提交
431

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

434
| Name         | Value    | Description         |
435 436
| ------------- | ------ | -------------|
| SPEAKER       | 2      | Speaker.     |
W
wusongqing 已提交
437 438

## AudioRingMode
W
wusongqing 已提交
439

W
wusongqing 已提交
440
Enumerates the ringer modes.
W
wusongqing 已提交
441

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

444
| Name               |  Value   | Description      |
W
wusongqing 已提交
445 446 447 448
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | Silent mode.|
| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
| RINGER_MODE_NORMAL  | 2      | Normal mode.|
449 450

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

452
Enumerates the audio sample formats.
V
Vaidegi B 已提交
453

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

456
| Name                               |  Value   | Description                      |
457 458 459 460 461 462
| ---------------------------------- | ------ | -------------------------- |
| 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.|
G
Gloria 已提交
463
| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | Signed 32-bit floating point number, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
464

465 466 467 468 469 470
## AudioErrors<sup>9+</sup>

Enumerates the audio error codes.

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

471
| Name                | Value     | Description        |
472 473 474 475
| ---------------------| --------| ----------------- |
| ERROR_INVALID_PARAM  | 6800101 | Invalid parameter.        |
| ERROR_NO_MEMORY      | 6800102 | Memory allocation failure.    |
| ERROR_ILLEGAL_STATE  | 6800103 | Unsupported state.      |
476
| ERROR_UNSUPPORTED    | 6800104 | Unsupported parameter value.   |
477 478
| ERROR_TIMEOUT        | 6800105 | Processing timeout.        |
| ERROR_STREAM_LIMIT   | 6800201 | Too many audio streams.|
479
| ERROR_SYSTEM         | 6800301 | System error.    |
480

481
## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
482 483 484

Enumerates the audio channels.

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

487
| Name     |  Value      | Description    |
W
wusongqing 已提交
488 489 490
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
491 492

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
493

494
Enumerates the audio sampling rates. The sampling rates supported vary according to the device in use.
V
Vaidegi B 已提交
495

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

498
| Name             |  Value   | Description           |
W
wusongqing 已提交
499 500 501 502 503 504 505 506 507 508 509 510
| ----------------- | ------ | --------------- |
| 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.|
511 512 513

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

V
Vaidegi B 已提交
514 515
Enumerates the audio encoding types.

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

518
| Name                 |  Value   | Description     |
W
wusongqing 已提交
519 520 521
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
522

523 524
## ContentType

W
wusongqing 已提交
525
Enumerates the audio content types.
526

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

529
| Name                              |  Value   | Description      |
W
wusongqing 已提交
530 531 532 533 534
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
G
Gloria 已提交
535
| CONTENT_TYPE_SONIFICATION          | 4      | Notification tone.  |
W
wusongqing 已提交
536
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
G
Gloria 已提交
537
| CONTENT_TYPE_ULTRASONIC<sup>10+</sup>| 9      | Ultrasonic.<br>This is a system API.|
538 539
## StreamUsage

W
wusongqing 已提交
540
Enumerates the audio stream usage.
V
Vaidegi B 已提交
541

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

544
| Name                                     |  Value   | Description      |
545 546 547 548 549
| ------------------------------------------| ------ | ---------- |
| 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.|
G
Gloria 已提交
550
| STREAM_USAGE_ALARM<sup>10+</sup>          | 4      | Used for alarming.    |
551
| STREAM_USAGE_NOTIFICATION_RINGTONE        | 6      | Used for notification.|
G
Gloria 已提交
552 553
| STREAM_USAGE_ACCESSIBILITY<sup>10+</sup>  | 8     | Used for accessibility.  |
| STREAM_USAGE_SYSTEM<sup>10+</sup>         | 9     | System tone (such as screen lock or keypad tone).<br>This is a system API.|
V
Vaidegi B 已提交
554

555
## InterruptRequestType<sup>9+</sup>
556

557
Enumerates the audio interruption request types.
558

G
Gloria 已提交
559 560
**System API**: This is a system API.

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

563
| Name                              |  Value    | Description                      |
564 565
| ---------------------------------- | ------ | ------------------------- |
| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  Default type, which can be used to interrupt audio requests. |
566

567 568
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
569 570
Enumerates the audio states.

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

573
| Name          | Value    | Description            |
W
wusongqing 已提交
574 575 576 577 578 579 580 581
| -------------- | ------ | ---------------- |
| 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 已提交
582

583 584
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
585 586
Enumerates the audio renderer rates.

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

589
| Name              | Value    | Description      |
W
wusongqing 已提交
590 591 592 593
| ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0      | Normal rate.|
| RENDER_RATE_DOUBLE | 1      | Double rate.   |
| RENDER_RATE_HALF   | 2      | Half rate. |
V
Vaidegi B 已提交
594

595
## InterruptType
V
Vaidegi B 已提交
596

W
wusongqing 已提交
597
Enumerates the audio interruption types.
V
Vaidegi B 已提交
598

W
wusongqing 已提交
599
**System capability**: SystemCapability.Multimedia.Audio.Renderer
600

601
| Name                |  Value    | Description                  |
W
wusongqing 已提交
602 603 604
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
605 606

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

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

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

612
| Name           |  Value   | Description                                |
W
wusongqing 已提交
613 614 615
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
616 617

## InterruptHint
V
Vaidegi B 已提交
618

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

W
wusongqing 已提交
621
**System capability**: SystemCapability.Multimedia.Audio.Renderer
622

623
| Name                              |  Value    | Description                                        |
W
wusongqing 已提交
624 625 626 627 628 629 630
| ---------------------------------- | ------ | -------------------------------------------- |
| 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.                              |
631 632

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

634
Describes audio stream information.
V
Vaidegi B 已提交
635

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

638 639 640 641 642 643
| 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.    |
644 645

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
646 647 648

Describes audio renderer information.

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

651
| Name         | Type                       | Mandatory | Description            |
W
wusongqing 已提交
652 653 654 655
| ------------- | --------------------------- | ---- | ---------------- |
| content       | [ContentType](#contenttype) | Yes  | Audio content type.      |
| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
| rendererFlags | number                      | Yes  | Audio renderer flags.|
V
Vaidegi B 已提交
656

657 658 659 660 661 662 663 664 665 666 667 668 669
## 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.|

670
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
671

W
wusongqing 已提交
672
Describes audio renderer configurations.
673

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

676
| Name        | Type                                    | Mandatory | Description            |
W
wusongqing 已提交
677 678 679
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
680

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

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

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

687
| Name     | Type                                      |Mandatory  | Description                                |
W
wusongqing 已提交
688 689 690 691
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
| 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 已提交
692

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

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

G
Gloria 已提交
697
**System API**: This is a system API.
698

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

701
| Name      | Type                               | Mandatory  | Description                                                    |
W
wusongqing 已提交
702 703
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
704
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
W
wusongqing 已提交
705
| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                    |
G
Gloria 已提交
706 707 708
| 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.                                               |

709 710 711 712 713 714 715
## 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                                                    |
716
| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- |
717 718
| mute | boolean | Yes  | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.         |

G
Gloria 已提交
719 720 721 722
## ConnectType<sup>9+</sup>

Enumerates the types of connected devices.

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

725
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
726

727
| Name                           |  Value    | Description                  |
G
Gloria 已提交
728 729 730 731
| :------------------------------ | :----- | :--------------------- |
| CONNECT_TYPE_LOCAL              | 1      | Local device.        |
| CONNECT_TYPE_DISTRIBUTED        | 2      | Distributed device.           |

732 733 734 735 736 737 738 739
## 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 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752
## 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.|
753
| groupName<sup>9+</sup>     | string                     | Yes  | No  | Group name.|
754
| type<sup>9+</sup>          | [ConnectType](#connecttype9)| Yes  | No  | Type of the connected device.|
G
Gloria 已提交
755

W
wusongqing 已提交
756
## DeviceChangeAction
757

W
wusongqing 已提交
758
Describes the device connection status and device information.
759

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

W
wusongqing 已提交
762 763
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
764
| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
W
wusongqing 已提交
765
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
V
Vaidegi B 已提交
766

W
wusongqing 已提交
767
## DeviceChangeType
768

W
wusongqing 已提交
769
Enumerates the device connection statuses.
V
Vaidegi B 已提交
770

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

773
| Name      |  Value    | Description          |
W
wusongqing 已提交
774 775 776
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
777

W
wusongqing 已提交
778
## AudioCapturerOptions<sup>8+</sup>
779

W
wusongqing 已提交
780
Describes audio capturer configurations.
781

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

W
wusongqing 已提交
784 785 786 787
| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|
788

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

W
wusongqing 已提交
791
Describes audio capturer information.
792

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

W
wusongqing 已提交
795 796 797 798
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
799 800

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

W
wusongqing 已提交
802
Enumerates the audio source types.
803

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

806
| Name                                        |  Value    | Description                  |
807 808 809 810 811
| :------------------------------------------- | :----- | :--------------------- |
| 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.|
812 813

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

W
wusongqing 已提交
815
Enumerates the audio scenes.
816

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

819
| Name                  |  Value    | Description                                         |
W
wusongqing 已提交
820 821
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
822 823
| 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 已提交
824
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
825

826
## AudioManager
W
wusongqing 已提交
827

W
wusongqing 已提交
828
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 已提交
829

830 831 832
### setAudioParameter

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

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

836
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 已提交
837

838 839 840
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

**System capability**: SystemCapability.Multimedia.Audio.Core
G
Gloria 已提交
841 842 843

**Parameters**

844 845 846 847 848
| 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 已提交
849 850

**Example**
851

G
Gloria 已提交
852
```js
853
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
G
Gloria 已提交
854
  if (err) {
855 856
    console.error(`Failed to set the audio parameter. ${err}`);
    return;
G
Gloria 已提交
857
  }
858
  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
G
Gloria 已提交
859 860 861
});
```

862
### setAudioParameter
G
Gloria 已提交
863

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

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

868 869 870 871 872 873 874 875 876 877 878 879
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 已提交
880 881 882

**Return value**

883 884 885
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
886 887

**Example**
888

G
Gloria 已提交
889
```js
890 891 892
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
  console.info('Promise returned to indicate a successful setting of the audio parameter.');
});
G
Gloria 已提交
893 894
```

895
### getAudioParameter
896

897
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
898

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

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

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

W
wusongqing 已提交
905
**Parameters**
906

907 908 909 910
| 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.|
911

W
wusongqing 已提交
912
**Example**
W
wusongqing 已提交
913

G
Gloria 已提交
914
```js
915
audioManager.getAudioParameter('key_example', (err, value) => {
916
  if (err) {
917
    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
918 919
    return;
  }
920
  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
921
});
W
wusongqing 已提交
922
```
W
wusongqing 已提交
923

924
### getAudioParameter
925

926
getAudioParameter(key: string): Promise&lt;string&gt;
927

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

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

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

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

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

W
wusongqing 已提交
940
**Return value**
941

942 943 944
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
945

W
wusongqing 已提交
946
**Example**
W
wusongqing 已提交
947

G
Gloria 已提交
948
```js
949 950
audioManager.getAudioParameter('key_example').then((value) => {
  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
951 952 953
});
```

954
### setAudioScene<sup>8+</sup>
W
wusongqing 已提交
955

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

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

960 961 962
**System API**: This is a system API.

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

W
wusongqing 已提交
964
**Parameters**
965

966 967 968 969
| 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.|
970

W
wusongqing 已提交
971
**Example**
W
wusongqing 已提交
972

G
Gloria 已提交
973
```js
974
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
975
  if (err) {
976
    console.error(`Failed to set the audio scene mode.​ ${err}`);
977 978
    return;
  }
979
  console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
980
});
W
wusongqing 已提交
981 982
```

983
### setAudioScene<sup>8+</sup>
V
Vaidegi B 已提交
984

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

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

989 990 991
**System API**: This is a system API.

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

W
wusongqing 已提交
993
**Parameters**
W
wusongqing 已提交
994

995 996 997
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
W
wusongqing 已提交
998

W
wusongqing 已提交
999
**Return value**
1000

1001 1002 1003
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
W
wusongqing 已提交
1004

W
wusongqing 已提交
1005
**Example**
W
wusongqing 已提交
1006

G
Gloria 已提交
1007
```js
1008 1009 1010 1011
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}`);
1012 1013 1014
});
```

1015
### getAudioScene<sup>8+</sup>
1016

1017
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1018

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

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

W
wusongqing 已提交
1023
**Parameters**
W
wusongqing 已提交
1024

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

**Example**
W
wusongqing 已提交
1030

G
Gloria 已提交
1031
```js
1032
audioManager.getAudioScene((err, value) => {
1033
  if (err) {
1034
    console.error(`Failed to obtain the audio scene mode.​ ${err}`);
1035 1036
    return;
  }
1037
  console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
1038
});
W
wusongqing 已提交
1039 1040
```

1041
### getAudioScene<sup>8+</sup>
W
wusongqing 已提交
1042

1043
getAudioScene\(\): Promise<AudioScene\>
W
wusongqing 已提交
1044

1045
Obtains the audio scene. This API uses a promise to return the result.
1046

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

W
wusongqing 已提交
1049
**Return value**
W
wusongqing 已提交
1050

1051 1052 1053
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
W
wusongqing 已提交
1054

W
wusongqing 已提交
1055
**Example**
1056

G
Gloria 已提交
1057
```js
1058 1059 1060 1061
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}`);
1062 1063 1064
});
```

1065
### getVolumeManager<sup>9+</sup>
1066

1067
getVolumeManager(): AudioVolumeManager
1068

1069
Obtains an **AudioVolumeManager** instance.
1070

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

W
wusongqing 已提交
1073
**Example**
W
wusongqing 已提交
1074

G
Gloria 已提交
1075
```js
1076
let audioVolumeManager = audioManager.getVolumeManager();
W
wusongqing 已提交
1077 1078
```

1079
### getStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1080

1081
getStreamManager(): AudioStreamManager
W
wusongqing 已提交
1082

1083
Obtains an **AudioStreamManager** instance.
W
wusongqing 已提交
1084

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

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

1089 1090 1091
```js
let audioStreamManager = audioManager.getStreamManager();
```
W
wusongqing 已提交
1092

1093
### getRoutingManager<sup>9+</sup>
1094

1095 1096 1097 1098 1099
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

W
wusongqing 已提交
1101
**Example**
W
wusongqing 已提交
1102

G
Gloria 已提交
1103
```js
1104
let audioRoutingManager = audioManager.getRoutingManager();
W
wusongqing 已提交
1105 1106
```

1107
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1108

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

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

1113 1114 1115 1116
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.

G
Gloria 已提交
1117 1118
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1123
**Parameters**
W
wusongqing 已提交
1124

1125 1126 1127 1128 1129
| 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.                                  |
1130

W
wusongqing 已提交
1131
**Example**
W
wusongqing 已提交
1132

G
Gloria 已提交
1133
```js
1134
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
1135
  if (err) {
1136
    console.error(`Failed to set the volume. ${err}`);
1137 1138
    return;
  }
1139
  console.info('Callback invoked to indicate a successful volume setting.');
1140
});
W
wusongqing 已提交
1141 1142
```

1143
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1144

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

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

1149 1150 1151 1152
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.

G
Gloria 已提交
1153 1154
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1159
**Parameters**
W
wusongqing 已提交
1160

1161 1162 1163 1164
| 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**.|
1165

W
wusongqing 已提交
1166
**Return value**
1167

1168 1169
| Type               | Description                         |
| ------------------- | ----------------------------- |
W
wusongqing 已提交
1170
| Promise&lt;void&gt; | Promise used to return the result.|
1171

W
wusongqing 已提交
1172
**Example**
W
wusongqing 已提交
1173

G
Gloria 已提交
1174
```js
1175
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1176
  console.info('Promise returned to indicate a successful volume setting.');
1177
});
W
wusongqing 已提交
1178 1179
```

1180
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1181

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

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

1186 1187 1188 1189
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1192
**Parameters**
W
wusongqing 已提交
1193

1194 1195 1196 1197 1198 1199
| 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 已提交
1200

G
Gloria 已提交
1201
```js
1202
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1203
  if (err) {
1204
    console.error(`Failed to obtain the volume. ${err}`);
1205 1206
    return;
  }
1207
  console.info('Callback invoked to indicate that the volume is obtained.');
1208
});
W
wusongqing 已提交
1209 1210
```

1211
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1212

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

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

1217 1218 1219 1220
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

1223 1224 1225 1226 1227
**Parameters**

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

W
wusongqing 已提交
1229
**Return value**
W
wusongqing 已提交
1230

1231 1232 1233
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
1234

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

G
Gloria 已提交
1237
```js
1238 1239
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1240
});
W
wusongqing 已提交
1241 1242
```

1243
### getMinVolume<sup>(deprecated)</sup>
1244

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

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

1249 1250 1251 1252
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.

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

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

1257 1258 1259 1260
| 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 已提交
1261

W
wusongqing 已提交
1262
**Example**
W
wusongqing 已提交
1263

G
Gloria 已提交
1264
```js
1265
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1266
  if (err) {
1267
    console.error(`Failed to obtain the minimum volume. ${err}`);
1268 1269
    return;
  }
1270
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1271
});
W
wusongqing 已提交
1272 1273
```

1274
### getMinVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1275

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

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

1280 1281 1282 1283
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1286
**Parameters**
W
wusongqing 已提交
1287

1288 1289 1290
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1291

W
wusongqing 已提交
1292
**Return value**
1293

1294 1295 1296
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
1297

W
wusongqing 已提交
1298
**Example**
W
wusongqing 已提交
1299

G
Gloria 已提交
1300
```js
1301 1302
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1303
});
W
wusongqing 已提交
1304 1305
```

1306
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1307

1308
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1309

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

1312 1313 1314 1315
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.

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

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

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

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

G
Gloria 已提交
1327
```js
1328
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1329
  if (err) {
1330
    console.error(`Failed to obtain the maximum volume. ${err}`);
1331 1332
    return;
  }
1333
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1334
});
W
wusongqing 已提交
1335 1336
```

1337
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1338

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

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

1343 1344 1345 1346
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.

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

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

1351 1352 1353
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
1354

W
wusongqing 已提交
1355
**Return value**
W
wusongqing 已提交
1356

1357 1358 1359
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
1360

W
wusongqing 已提交
1361
**Example**
W
wusongqing 已提交
1362

G
Gloria 已提交
1363
```js
1364
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
1365
  console.info('Promised returned to indicate that the maximum volume is obtained.');
1366
});
W
wusongqing 已提交
1367 1368
```

1369
### mute<sup>(deprecated)</sup>
1370

1371
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1372

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

1375 1376 1377
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.
1378 1379

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

W
wusongqing 已提交
1381
**Parameters**
W
wusongqing 已提交
1382

1383 1384 1385 1386 1387
| 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 已提交
1388

W
wusongqing 已提交
1389
**Example**
1390

G
Gloria 已提交
1391
```js
1392
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
1393
  if (err) {
1394
    console.error(`Failed to mute the stream. ${err}`);
1395 1396
    return;
  }
1397
  console.info('Callback invoked to indicate that the stream is muted.');
1398
});
W
wusongqing 已提交
1399 1400
```

1401
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1402

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

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

1407 1408 1409
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.
1410 1411

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

W
wusongqing 已提交
1413
**Parameters**
W
wusongqing 已提交
1414

1415 1416 1417 1418
| 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 已提交
1419

W
wusongqing 已提交
1420
**Return value**
1421

1422 1423 1424
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1425

W
wusongqing 已提交
1426
**Example**
W
wusongqing 已提交
1427

1428

G
Gloria 已提交
1429
```js
1430
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1431
  console.info('Promise returned to indicate that the stream is muted.');
1432
});
W
wusongqing 已提交
1433 1434
```

1435
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1436

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

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

1441 1442 1443 1444
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.

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

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

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

1466
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1467

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

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

1472 1473 1474 1475
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.

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

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

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

W
wusongqing 已提交
1484
**Return value**
1485

1486 1487 1488
| 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.|
1489

W
wusongqing 已提交
1490
**Example**
1491

G
Gloria 已提交
1492
```js
1493
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
1494
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1495
});
W
wusongqing 已提交
1496 1497
```

1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
### isActive<sup>(deprecated)</sup>

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

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

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

**Parameters**

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

**Example**

```js
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the active status of the stream. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
});
```

### isActive<sup>(deprecated)</sup>

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

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

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

**Parameters**

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

**Return value**

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

**Example**

```js
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
});
```

### setRingerMode<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1562

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

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

1567 1568 1569 1570
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.

1571 1572 1573 1574
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

1579 1580 1581 1582
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1583

W
wusongqing 已提交
1584
**Example**
W
wusongqing 已提交
1585

G
Gloria 已提交
1586
```js
1587
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
1588
  if (err) {
1589
    console.error(`Failed to set the ringer mode.​ ${err}`);
1590 1591
    return;
  }
1592
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
1593
});
W
wusongqing 已提交
1594 1595
```

1596
### setRingerMode<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1597

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

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

1602 1603 1604 1605
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.

1606
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
W
wusongqing 已提交
1607

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

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

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

1614 1615 1616
| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1617

W
wusongqing 已提交
1618
**Return value**
1619

1620 1621 1622
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1623

W
wusongqing 已提交
1624
**Example**
W
wusongqing 已提交
1625

G
Gloria 已提交
1626
```js
1627
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1628 1629 1630 1631
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```

1632
### getRingerMode<sup>(deprecated)</sup>
1633 1634 1635 1636 1637

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

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

1638 1639 1640 1641 1642
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.

**System capability**: SystemCapability.Multimedia.Audio.Communication
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652

**Parameters**

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

**Example**

```js
1653
audioManager.getRingerMode((err, value) => {
1654 1655 1656 1657 1658 1659 1660 1661
  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}.`);
});
```

1662
### getRingerMode<sup>(deprecated)</sup>
1663 1664 1665 1666 1667

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

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

1668 1669 1670 1671 1672
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.

**System capability**: SystemCapability.Multimedia.Audio.Communication
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682

**Return value**

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

**Example**

```js
1683
audioManager.getRingerMode().then((value) => {
1684
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1685
});
W
wusongqing 已提交
1686 1687
```

1688
### getDevices<sup>(deprecated)</sup>
1689

1690
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1691

1692
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
1693

1694 1695 1696 1697 1698
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.

**System capability**: SystemCapability.Multimedia.Audio.Device
1699 1700 1701

**Parameters**

1702 1703 1704 1705
| 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.|
1706

1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
**Example**
```js
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.');
});
```
1717

1718
### getDevices<sup>(deprecated)</sup>
1719

1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;

Obtains the audio devices with a specific flag. This API uses a promise to return the result.

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**.

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

**Parameters**

| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|

**Return value**

| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
1741 1742 1743 1744

**Example**

```js
1745 1746
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
1747 1748
});
```
V
Vaidegi B 已提交
1749

1750
### setDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1751

1752
setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
1753

1754
Sets a device to the active state. This API uses an asynchronous callback to return the result.
1755

1756 1757 1758 1759 1760
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.

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

W
wusongqing 已提交
1762
**Parameters**
W
wusongqing 已提交
1763

1764 1765
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
G
Gloria 已提交
1766
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
1767 1768
| 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.|
W
wusongqing 已提交
1769

W
wusongqing 已提交
1770
**Example**
W
wusongqing 已提交
1771

G
Gloria 已提交
1772
```js
1773
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
1774
  if (err) {
1775
    console.error(`Failed to set the active status of the device. ${err}`);
1776 1777
    return;
  }
1778
  console.info('Callback invoked to indicate that the device is set to the active status.');
1779
});
W
wusongqing 已提交
1780 1781
```

1782
### setDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1783

1784
setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
1785

1786
Sets a device to the active state. This API uses a promise to return the result.
1787

1788 1789 1790
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
1791

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

W
wusongqing 已提交
1794
**Parameters**
1795

1796 1797
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
G
Gloria 已提交
1798
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
1799
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
1800

W
wusongqing 已提交
1801
**Return value**
W
wusongqing 已提交
1802

W
wusongqing 已提交
1803 1804 1805
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1806

W
wusongqing 已提交
1807
**Example**
W
wusongqing 已提交
1808

1809

G
Gloria 已提交
1810
```js
1811 1812
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
1813
});
W
wusongqing 已提交
1814 1815
```

1816
### isDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1817

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

1820
Checks whether a device is active. This API uses an asynchronous callback to return the result.
1821

1822 1823 1824 1825 1826
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.

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

W
wusongqing 已提交
1828
**Parameters**
W
wusongqing 已提交
1829

1830 1831
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
G
Gloria 已提交
1832
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
1833
| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the active state of the device.|
W
wusongqing 已提交
1834

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

G
Gloria 已提交
1837
```js
1838
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
1839
  if (err) {
1840
    console.error(`Failed to obtain the active status of the device. ${err}`);
1841 1842
    return;
  }
1843
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
1844
});
W
wusongqing 已提交
1845 1846
```

1847
### isDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1848

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

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

1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.

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

**Parameters**

| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
G
Gloria 已提交
1863
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.|
W
wusongqing 已提交
1864

W
wusongqing 已提交
1865
**Return value**
1866

1867 1868 1869
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
W
wusongqing 已提交
1870

W
wusongqing 已提交
1871
**Example**
W
wusongqing 已提交
1872

G
Gloria 已提交
1873
```js
1874 1875
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
1876
});
W
wusongqing 已提交
1877 1878
```

1879
### setMicrophoneMute<sup>(deprecated)</sup>
W
wusongqing 已提交
1880

1881
setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1882

1883
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
1884

1885 1886 1887
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
1888

1889 1890 1891
**Required permissions**: ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1893
**Parameters**
V
Vaidegi B 已提交
1894

1895 1896 1897 1898
| 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.                     |
1899

1900
**Example**
1901

1902 1903 1904 1905 1906 1907 1908 1909 1910
```js
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.');
});
```
1911

1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
### setMicrophoneMute<sup>(deprecated)</sup>

setMicrophoneMute(mute: boolean): Promise&lt;void&gt;

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

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

**Parameters**

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

**Return value**

| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
V
Vaidegi B 已提交
1937

W
wusongqing 已提交
1938
**Example**
V
Vaidegi B 已提交
1939

G
Gloria 已提交
1940
```js
1941 1942
audioManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
1943
});
V
Vaidegi B 已提交
1944 1945
```

1946
### isMicrophoneMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1947

1948
isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
V
Vaidegi B 已提交
1949

1950
Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
1951

1952 1953 1954
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.
V
Vaidegi B 已提交
1955

1956
**Required permissions**: ohos.permission.MICROPHONE
1957

1958
**System capability**: SystemCapability.Multimedia.Audio.Device
V
Vaidegi B 已提交
1959

W
wusongqing 已提交
1960
**Parameters**
V
Vaidegi B 已提交
1961

1962 1963 1964
| 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.|
V
Vaidegi B 已提交
1965

W
wusongqing 已提交
1966
**Example**
V
Vaidegi B 已提交
1967

G
Gloria 已提交
1968
```js
1969
audioManager.isMicrophoneMute((err, value) => {
1970
  if (err) {
1971 1972
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
    return;
1973
  }
1974
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
1975
});
V
Vaidegi B 已提交
1976 1977
```

1978
### isMicrophoneMute<sup>(deprecated)</sup>
1979

1980
isMicrophoneMute(): Promise&lt;boolean&gt;
1981

1982
Checks whether the microphone is muted. This API uses a promise to return the result.
1983

1984 1985 1986 1987 1988 1989 1990
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.

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

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

1992
**Return value**
1993

1994 1995 1996
| 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.|
1997

W
wusongqing 已提交
1998
**Example**
1999

G
Gloria 已提交
2000
```js
2001 2002 2003
audioManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
});
2004 2005
```

2006
### on('volumeChange')<sup>(deprecated)</sup>
2007

2008
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2009

2010 2011 2012
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioVolumeManager**.
2013

2014 2015 2016 2017 2018 2019 2020
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
2021

W
wusongqing 已提交
2022
**Parameters**
2023

2024 2025 2026 2027
| 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 system volume change event.                                                  |
2028

W
wusongqing 已提交
2029
**Example**
2030

G
Gloria 已提交
2031
```js
2032 2033 2034 2035
audioManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2036 2037 2038
});
```

2039
### on('ringerModeChange')<sup>(deprecated)</sup>
2040

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

2043
Subscribes to ringer mode change events.
2044

2045 2046 2047
> **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**.
2048

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

2051 2052 2053 2054 2055 2056 2057 2058
**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 ringer mode change event.                                                  |
2059 2060

**Example**
2061

G
Gloria 已提交
2062
```js
2063 2064 2065
audioManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
2066 2067
```

2068
### on('deviceChange')<sup>(deprecated)</sup>
2069

2070
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2071

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

2074 2075 2076
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioRoutingManager**.
2077

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

2080
**Parameters**
2081

2082 2083 2084 2085
| 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.                        |
2086

W
wusongqing 已提交
2087
**Example**
2088

G
Gloria 已提交
2089
```js
2090 2091 2092 2093 2094
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} `);
2095 2096 2097
});
```

2098
### off('deviceChange')<sup>(deprecated)</sup>
2099

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

2102
Unsubscribes from device change events.
2103

2104 2105 2106
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off](#off9) in **AudioRoutingManager**.
2107

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

2110
**Parameters**
2111

2112 2113 2114 2115
| 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.                        |
2116 2117 2118 2119

**Example**

```js
2120 2121 2122
audioManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
});
2123 2124
```

2125
### on('interrupt')<sup>(deprecated)</sup>
2126

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

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

2131 2132 2133 2134 2135 2136 2137
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
2138

W
wusongqing 已提交
2139
**Parameters**
2140

2141 2142 2143 2144 2145
| 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](#interruptactiondeprecated)> | Yes  | Callback invoked for the audio interruption event.                                      |
2146

W
wusongqing 已提交
2147
**Example**
2148

G
Gloria 已提交
2149
```js
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162
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} `);
2163
  }
2164
});
2165 2166
```

2167
### off('interrupt')<sup>(deprecated)</sup>
2168

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

2171
Unsubscribes from audio interruption events.
2172

2173 2174 2175 2176 2177
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

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

2181 2182 2183 2184 2185
| 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](#interruptactiondeprecated)> | No  | Callback invoked for the audio interruption event.                                      |
2186

W
wusongqing 已提交
2187
**Example**
2188

G
Gloria 已提交
2189
```js
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
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} `);
  }
});
2201 2202
```

2203
## AudioVolumeManager<sup>9+</sup>
2204

2205
Implements audio volume management. Before calling an API in **AudioVolumeManager**, you must use [getVolumeManager](#getvolumemanager9) to obtain an **AudioVolumeManager** instance.
2206

2207
### getVolumeGroupInfos<sup>9+</sup>
2208

2209 2210 2211 2212 2213 2214 2215
getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void

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

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

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

W
wusongqing 已提交
2217
**Parameters**
2218

2219 2220 2221 2222
| 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.|
2223

W
wusongqing 已提交
2224
**Example**
G
Gloria 已提交
2225
```js
2226
audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err, value) => {
2227
  if (err) {
2228
    console.error(`Failed to obtain the volume group infos list. ${err}`);
2229 2230
    return;
  }
2231
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2232
});
2233 2234
```

2235
### getVolumeGroupInfos<sup>9+</sup>
2236

2237
getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2238

2239
Obtains the volume groups. This API uses a promise to return the result.
2240

2241 2242 2243
**System API**: This is a system API.

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

2245 2246
**Parameters**

2247 2248 2249
| Name    | Type              | Mandatory| Description                |
| ---------- | ------------------| ---- | -------------------- |
| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2250

W
wusongqing 已提交
2251
**Return value**
2252

2253 2254 2255
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
2256

W
wusongqing 已提交
2257
**Example**
2258

G
Gloria 已提交
2259
```js
2260 2261 2262 2263 2264
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))
}
```
2265

2266
### getVolumeGroupManager<sup>9+</sup>
2267

2268
getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2269

2270
Obtains the audio group manager. This API uses an asynchronous callback to return the result.
2271

2272
**System capability**: SystemCapability.Multimedia.Audio.Volume
2273 2274 2275

**Parameters**

G
Gloria 已提交
2276 2277
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2278 2279
| groupId    | number                                    | Yes  | Volume group ID.    |
| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | Yes  | Callback used to return the audio group manager.|
2280 2281

**Example**
2282

G
Gloria 已提交
2283
```js
2284 2285
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
audioVolumeManager.getVolumeGroupManager(groupid, (err, value) => {
2286
  if (err) {
2287
    console.error(`Failed to obtain the volume group infos list. ${err}`);
G
Gloria 已提交
2288
    return;
2289
  }
2290
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
2291
});
2292

2293 2294
```

2295
### getVolumeGroupManager<sup>9+</sup>
2296

2297
getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2298

2299
Obtains the audio group manager. This API uses a promise to return the result.
G
Gloria 已提交
2300

2301
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2302 2303 2304

**Parameters**

2305 2306 2307
| Name    | Type                                     | Mandatory| Description             |
| ---------- | ---------------------------------------- | ---- | ---------------- |
| groupId    | number                                   | Yes  | Volume group ID.    |
2308 2309 2310

**Return value**

2311 2312 2313
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the audio group manager.|
2314 2315

**Example**
G
Gloria 已提交
2316 2317

```js
2318 2319 2320 2321 2322 2323 2324 2325
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
let audioVolumeGroupManager;
getVolumeGroupManager();
async function getVolumeGroupManager(){
  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
}

2326 2327
```

2328
### on('volumeChange')<sup>9+</sup>
2329

2330
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2331

2332
Subscribes to system volume change events. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2333

2334
**System capability**: SystemCapability.Multimedia.Audio.Volume
2335 2336 2337

**Parameters**

2338 2339 2340 2341
| 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.                                                  |
G
Gloria 已提交
2342

2343
**Error codes**
2344

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

2347 2348
| ID| Error Message|
| ------- | --------------------------------------------|
2349
| 6800101 | if input parameter value error              |
2350 2351

**Example**
G
Gloria 已提交
2352 2353

```js
2354 2355 2356 2357
audioVolumeManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2358
});
2359
```
2360

2361
## AudioVolumeGroupManager<sup>9+</sup>
2362

2363
Manages the volume of an audio group. Before calling any API in **AudioVolumeGroupManager**, you must use [getVolumeGroupManager](#getvolumegroupmanager9) to obtain an **AudioVolumeGroupManager** instance.
2364

2365
### setVolume<sup>9+</sup>
2366

2367
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
2368

2369
Sets the volume for a stream. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2370

2371
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2372

2373
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
G
Gloria 已提交
2374 2375 2376

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

2377
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2378 2379 2380

**Parameters**

2381 2382 2383 2384 2385
| 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.                                  |
G
Gloria 已提交
2386 2387

**Example**
2388

2389 2390 2391 2392 2393 2394 2395 2396
```js
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
  if (err) {
    console.error(`Failed to set the volume. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate a successful volume setting.');
});
G
Gloria 已提交
2397 2398
```

2399
### setVolume<sup>9+</sup>
G
Gloria 已提交
2400

2401
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
G
Gloria 已提交
2402

2403
Sets the volume for a stream. This API uses a promise to return the result.
G
Gloria 已提交
2404

2405
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2406

2407 2408 2409 2410 2411
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
G
Gloria 已提交
2412 2413 2414

**Parameters**

2415 2416 2417 2418
| 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**.|
G
Gloria 已提交
2419 2420 2421

**Return value**

2422 2423 2424
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2425 2426 2427 2428

**Example**

```js
2429 2430 2431
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.info('Promise returned to indicate a successful volume setting.');
});
G
Gloria 已提交
2432 2433
```

2434
### getVolume<sup>9+</sup>
G
Gloria 已提交
2435

2436
getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
G
Gloria 已提交
2437

2438
Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2439

2440
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2441 2442 2443

**Parameters**

2444 2445 2446 2447
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
G
Gloria 已提交
2448 2449 2450 2451

**Example**

```js
2452
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
2453
  if (err) {
2454
    console.error(`Failed to obtain the volume. ${err}`);
2455
    return;
G
Gloria 已提交
2456
  }
2457
  console.info('Callback invoked to indicate that the volume is obtained.');
2458
});
G
Gloria 已提交
2459 2460
```

2461
### getVolume<sup>9+</sup>
G
Gloria 已提交
2462

2463
getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
G
Gloria 已提交
2464

2465
Obtains the volume of a stream. This API uses a promise to return the result.
G
Gloria 已提交
2466

2467
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2468 2469 2470

**Parameters**

2471 2472 2473
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2474 2475 2476

**Return value**

2477 2478 2479
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
G
Gloria 已提交
2480 2481 2482 2483

**Example**

```js
2484 2485
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2486
});
G
Gloria 已提交
2487 2488
```

2489
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2490

2491
getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
G
Gloria 已提交
2492

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

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

**Parameters**

2499 2500 2501 2502
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
G
Gloria 已提交
2503 2504 2505 2506

**Example**

```js
2507
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2508
  if (err) {
2509
    console.error(`Failed to obtain the minimum volume. ${err}`);
G
Gloria 已提交
2510 2511
    return;
  }
2512
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
G
Gloria 已提交
2513 2514 2515
});
```

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

2518
getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
G
Gloria 已提交
2519

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

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

**Parameters**

2526 2527 2528
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2529 2530 2531

**Return value**

2532 2533 2534
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
G
Gloria 已提交
2535 2536 2537 2538

**Example**

```js
2539 2540
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
G
Gloria 已提交
2541 2542 2543
});
```

2544
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2545

2546
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
G
Gloria 已提交
2547

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

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

**Parameters**

2554 2555 2556 2557
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
G
Gloria 已提交
2558 2559

**Example**
2560

G
Gloria 已提交
2561
```js
2562 2563 2564 2565 2566 2567 2568
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the maximum volume. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
});
G
Gloria 已提交
2569 2570
```

2571
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2572

2573
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2574

2575
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
2576

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

**Parameters**

2581 2582 2583
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2584 2585 2586

**Return value**

2587 2588 2589
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
G
Gloria 已提交
2590 2591 2592 2593

**Example**

```js
2594 2595 2596
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.info('Promised returned to indicate that the maximum volume is obtained.');
});
2597
```
G
Gloria 已提交
2598

2599
### mute<sup>9+</sup>
2600

2601
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2602

2603
Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
2604

2605
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2606

2607 2608 2609 2610 2611
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
G
Gloria 已提交
2612 2613 2614

**Parameters**

2615 2616 2617 2618 2619
| 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.               |
G
Gloria 已提交
2620 2621 2622

**Example**

2623 2624 2625 2626 2627 2628 2629 2630
```js
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
  if (err) {
    console.error(`Failed to mute the stream. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the stream is muted.');
});
2631
```
G
Gloria 已提交
2632

2633
### mute<sup>9+</sup>
G
Gloria 已提交
2634

2635
mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
G
Gloria 已提交
2636

2637
Mutes or unmutes a stream. This API uses a promise to return the result.
2638

2639
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2640

2641 2642 2643 2644 2645
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
G
Gloria 已提交
2646 2647 2648

**Parameters**

2649 2650 2651 2652
| 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.|
G
Gloria 已提交
2653 2654 2655

**Return value**

2656 2657 2658
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2659 2660 2661 2662

**Example**

```js
2663 2664 2665
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.info('Promise returned to indicate that the stream is muted.');
});
G
Gloria 已提交
2666 2667
```

2668
### isMute<sup>9+</sup>
G
Gloria 已提交
2669

2670
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
G
Gloria 已提交
2671

2672
Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
2673

2674
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2675

2676
**Parameters**
G
Gloria 已提交
2677

2678 2679 2680 2681
| 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.|
G
Gloria 已提交
2682 2683 2684 2685

**Example**

```js
2686
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2687
  if (err) {
2688 2689
    console.error(`Failed to obtain the mute status. ${err}`);
    return;
G
Gloria 已提交
2690
  }
2691
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
G
Gloria 已提交
2692
});
2693
```
G
Gloria 已提交
2694

2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719
### isMute<sup>9+</sup>

isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;

Checks whether a stream is muted. This API uses a promise to return the result.

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

**Parameters**

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

**Return value**

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

**Example**

```js
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
2720 2721
});
```
G
Gloria 已提交
2722

2723
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2724

2725
setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2726

2727
Sets the ringer mode. This API uses an asynchronous callback to return the result.
2728

2729
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2730

2731
This permission is required only for muting or unmuting the ringer.
G
Gloria 已提交
2732

2733
**System API**: This is a system API.
G
Gloria 已提交
2734

2735
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2736

2737 2738 2739 2740 2741 2742
**Parameters**

| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
G
Gloria 已提交
2743 2744 2745 2746

**Example**

```js
2747
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
2748
  if (err) {
2749 2750
    console.error(`Failed to set the ringer mode.​ ${err}`);
    return;
2751
  }
2752
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
2753 2754
});
```
G
Gloria 已提交
2755

2756
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2757

2758
setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
G
Gloria 已提交
2759

2760
Sets the ringer mode. This API uses a promise to return the result.
2761

2762
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2763

2764
This permission is required only for muting or unmuting the ringer.
G
Gloria 已提交
2765

2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780
**System API**: This is a system API.

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

**Parameters**

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

**Return value**

| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2781 2782 2783 2784

**Example**

```js
2785 2786 2787 2788
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```
2789

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

2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810
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;
G
Gloria 已提交
2811
  }
2812
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
G
Gloria 已提交
2813 2814 2815
});
```

2816 2817 2818 2819 2820
### getRingerMode<sup>9+</sup>

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

Obtains the ringer mode. This API uses a promise to return the result.
G
Gloria 已提交
2821

2822
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2823

2824
**Return value**
2825

2826 2827 2828
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
G
Gloria 已提交
2829

2830
**Example**
G
Gloria 已提交
2831

2832
```js
2833 2834 2835
audioVolumeGroupManager.getRingerMode().then((value) => {
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
});
2836
```
G
Gloria 已提交
2837

2838
### on('ringerModeChange')<sup>9+</sup>
G
Gloria 已提交
2839

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

2842
Subscribes to ringer mode change events.
2843

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

2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
**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              |
G
Gloria 已提交
2860 2861 2862 2863

**Example**

```js
2864 2865 2866
audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
G
Gloria 已提交
2867
```
2868
### setMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2869

2870
setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
G
Gloria 已提交
2871

2872
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2873

2874
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
2875

2876
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2877 2878 2879

**Parameters**

2880 2881 2882 2883
| 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.                     |
G
Gloria 已提交
2884 2885 2886 2887

**Example**

```js
2888 2889 2890 2891 2892 2893
audioVolumeGroupManager.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.');
G
Gloria 已提交
2894 2895 2896
});
```

2897
### setMicrophoneMute<sup>9+</sup>
2898

2899
setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
G
Gloria 已提交
2900

2901
Mutes or unmutes the microphone. This API uses a promise to return the result.
G
Gloria 已提交
2902

2903 2904 2905 2906 2907 2908 2909 2910 2911
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG

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

**Parameters**

| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
G
Gloria 已提交
2912 2913 2914

**Return value**

2915 2916 2917
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2918 2919 2920 2921

**Example**

```js
2922 2923
audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
G
Gloria 已提交
2924 2925 2926
});
```

2927
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2928

2929
isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
G
Gloria 已提交
2930

2931
Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
2932

2933
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2934 2935 2936

**Parameters**

2937 2938 2939
| 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.|
G
Gloria 已提交
2940 2941 2942 2943

**Example**

```js
2944 2945 2946 2947 2948 2949
audioVolumeGroupManager.isMicrophoneMute((err, value) => {
  if (err) {
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
G
Gloria 已提交
2950 2951 2952
});
```

2953
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2954

2955
isMicrophoneMute(): Promise&lt;boolean&gt;
G
Gloria 已提交
2956

2957
Checks whether the microphone is muted. This API uses a promise to return the result.
G
Gloria 已提交
2958

2959
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2960 2961 2962

**Return value**

2963 2964 2965
| 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.|
G
Gloria 已提交
2966 2967 2968 2969

**Example**

```js
2970 2971
audioVolumeGroupManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2972
});
2973 2974 2975
```

### on('micStateChange')<sup>9+</sup>
2976

2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005
on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void

Subscribes to system microphone state change events.

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

**Parameters**

| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Event type. The value **'micStateChange'** means the system microphone state change event, which is triggered when the system microphone state changes.|
| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | Yes  | Callback used to return the changed microphone 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              |

**Example**

```js
audioVolumeGroupManager.on('micStateChange', (micStateChange) => {
  console.info(`Current microphone status is: ${micStateChange.mute} `);
});
G
Gloria 已提交
3006 3007
```

3008
## AudioStreamManager<sup>9+</sup>
G
Gloria 已提交
3009

3010
Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance.
G
Gloria 已提交
3011

3012 3013 3014 3015 3016
### getCurrentAudioRendererInfoArray<sup>9+</sup>

getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void

Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3017 3018 3019 3020 3021

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

**Parameters**

3022 3023 3024
| Name    | Type                                | Mandatory    | Description                        |
| -------- | ----------------------------------- | -------- | --------------------------- |
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes    |  Callback used to return the audio renderer information.|
G
Gloria 已提交
3025 3026 3027 3028

**Example**

```js
3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055
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}`);
        }
      }
    }
  }
G
Gloria 已提交
3056 3057 3058
});
```

3059
### getCurrentAudioRendererInfoArray<sup>9+</sup>
G
Gloria 已提交
3060

3061
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
G
Gloria 已提交
3062

3063
Obtains the information about the current audio renderer. This API uses a promise to return the result.
G
Gloria 已提交
3064 3065 3066 3067 3068

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

**Return value**

3069 3070 3071
| Type                                                                             | Description                                   |
| ---------------------------------------------------------------------------------| --------------------------------------- |
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise used to return the audio renderer information.     |
G
Gloria 已提交
3072 3073 3074 3075

**Example**

```js
3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103
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}`);
  });
}
3104
```
G
Gloria 已提交
3105

3106
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3107

3108
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3109

3110
Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3111 3112 3113 3114 3115

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

**Parameters**

3116 3117 3118
| Name       | Type                                | Mandatory     | Description                                                     |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes   | Callback used to return the audio capturer information.|
G
Gloria 已提交
3119 3120 3121 3122

**Example**

```js
3123 3124
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
3125
  if (err) {
3126
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3127
  } else {
3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146
    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}`);
        }
      }
    }
G
Gloria 已提交
3147 3148 3149 3150
  }
});
```

3151
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
G
Gloria 已提交
3152

3153
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
G
Gloria 已提交
3154

3155
Obtains the information about the current audio capturer. This API uses a promise to return the result.
G
Gloria 已提交
3156 3157 3158

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

3159
**Return value**
G
Gloria 已提交
3160

3161 3162 3163
| Type                                                                        | Description                                |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise used to return the audio capturer information. |
G
Gloria 已提交
3164 3165 3166 3167

**Example**

```js
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193
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}`);
  });
}
G
Gloria 已提交
3194 3195
```

3196
### on('audioRendererChange')<sup>9+</sup>
G
Gloria 已提交
3197

3198
on(type: "audioRendererChange", callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
G
Gloria 已提交
3199

3200
Subscribes to audio renderer change events.
G
Gloria 已提交
3201

3202
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3203 3204 3205

**Parameters**

3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217
| 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              |
G
Gloria 已提交
3218 3219 3220 3221

**Example**

```js
3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241
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}`);
    }
G
Gloria 已提交
3242 3243 3244 3245
  }
});
```

3246
### off('audioRendererChange')<sup>9+</sup>
G
Gloria 已提交
3247

3248
off(type: "audioRendererChange"): void
G
Gloria 已提交
3249

3250
Unsubscribes from audio renderer change events.
G
Gloria 已提交
3251

3252
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3253

3254
**Parameters**
G
Gloria 已提交
3255

3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266
| 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              |
G
Gloria 已提交
3267 3268 3269 3270

**Example**

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

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

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

3279
Subscribes to audio capturer change events.
G
Gloria 已提交
3280

3281
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3282 3283 3284

**Parameters**

3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296
| 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.  |

**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              |
3297 3298

**Example**
G
Gloria 已提交
3299 3300

```js
3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319
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}`);
    }
G
Gloria 已提交
3320
  }
3321 3322
});
```
G
Gloria 已提交
3323

3324
### off('audioCapturerChange')<sup>9+</sup>
G
Gloria 已提交
3325

3326
off(type: "audioCapturerChange"): void;
G
Gloria 已提交
3327

3328
Unsubscribes from audio capturer change events.
G
Gloria 已提交
3329

3330
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
3331

3332
**Parameters**
G
Gloria 已提交
3333

3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344
| Name      | Type    | Mandatory| Description                                                         |
| -------- | -------- | --- | ------------------------------------------------------------- |
| type     | string   |Yes  | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer 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              |
G
Gloria 已提交
3345 3346 3347 3348

**Example**

```js
3349 3350
audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########');
3351

3352 3353
```

3354
### isActive<sup>9+</sup>
3355

3356
isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
3357

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

3360
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3361 3362 3363

**Parameters**

3364 3365 3366 3367
| Name    | Type                               | Mandatory| Description                                             |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream types.                                     |
| 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.|
3368 3369

**Example**
G
Gloria 已提交
3370 3371

```js
3372
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
3373
  if (err) {
3374 3375
    console.error(`Failed to obtain the active status of the stream. ${err}`);
    return;
G
Gloria 已提交
3376
  }
3377
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
G
Gloria 已提交
3378
});
3379 3380
```

3381
### isActive<sup>9+</sup>
3382

3383
isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
3384

3385
Checks whether a stream is active. This API uses a promise to return the result.
3386

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

3389 3390 3391 3392 3393 3394
**Parameters**

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

3395
**Return value**
G
Gloria 已提交
3396

3397 3398 3399
| 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.|
3400 3401

**Example**
G
Gloria 已提交
3402 3403

```js
3404 3405
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
3406
});
3407
```
3408

3409
## AudioRoutingManager<sup>9+</sup>
3410

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

3413
### getDevices<sup>9+</sup>
3414

3415 3416 3417 3418 3419
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void

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

**System capability**: SystemCapability.Multimedia.Audio.Device
3420 3421 3422

**Parameters**

3423 3424 3425 3426
| 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.|
3427 3428 3429

**Example**

3430
```js
3431
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
3432
  if (err) {
3433 3434
    console.error(`Failed to obtain the device list. ${err}`);
    return;
3435
  }
3436
  console.info('Callback invoked to indicate that the device list is obtained.');
3437 3438
});
```
3439

3440
### getDevices<sup>9+</sup>
3441

3442
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
3443

3444
Obtains the audio devices with a specific flag. This API uses a promise to return the result.
3445

3446 3447 3448 3449 3450 3451 3452
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
3453 3454 3455

**Return value**

3456 3457 3458
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
3459 3460 3461 3462

**Example**

```js
3463 3464
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
3465
});
3466 3467
```

3468
### on<sup>9+</sup>
3469

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

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

3474
**System capability**: SystemCapability.Multimedia.Audio.Device
3475 3476 3477

**Parameters**

3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490
| 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.                        |

**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              |
3491 3492

**Example**
3493

3494
```js
3495 3496 3497 3498 3499
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);
3500 3501
});
```
3502

3503
### off<sup>9+</sup>
3504

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

3507
Unsubscribes from device change events.
3508

3509
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3510

3511
**Parameters**
G
Gloria 已提交
3512

3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524
| 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.                        |

**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              |
3525 3526 3527

**Example**

G
Gloria 已提交
3528
```js
3529 3530
audioRoutingManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
3531 3532
});
```
G
Gloria 已提交
3533

3534
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3535

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

3538
Selects an audio input device. Only one input device can be selected. This API uses an asynchronous callback to return the result.
3539

3540 3541 3542
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3543 3544 3545

**Parameters**

3546 3547 3548 3549
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
3550 3551 3552

**Example**
```js
3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565
let inputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.INPUT_DEVICE,
    deviceType : audio.DeviceType.EARPIECE,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3566

3567 3568 3569 3570 3571 3572 3573 3574
async function selectInputDevice(){
  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select input devices result callback: SUCCESS'); }
  });
}
3575 3576
```

3577
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3578

3579
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3580

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

3583 3584 3585 3586 3587 3588 3589 3590 3591
Selects an audio input device. Only one input device can be selected. This API uses a promise to return the result.

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

**Parameters**

| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
3592 3593 3594

**Return value**

3595 3596 3597
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3598 3599 3600

**Example**

G
Gloria 已提交
3601
```js
3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614
let inputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.INPUT_DEVICE,
    deviceType : audio.DeviceType.EARPIECE,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3615

3616 3617 3618 3619 3620 3621 3622
async function getRoutingManager(){
    audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
      console.info('Select input devices result promise: SUCCESS');
    }).catch((err) => {
      console.error(`Result ERROR: ${err}`);
    });
}
3623 3624
```

3625
### setCommunicationDevice<sup>9+</sup>
3626

3627
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
3628

3629
Sets a communication device to the active state. This API uses an asynchronous callback to return the result.
3630

3631
**System capability**: SystemCapability.Multimedia.Audio.Communication
3632

3633
**Parameters**
3634

3635 3636 3637 3638 3639
| 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.|
3640 3641 3642

**Example**

G
Gloria 已提交
3643
```js
3644
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => {
3645
  if (err) {
3646 3647
    console.error(`Failed to set the active status of the device. ${err}`);
    return;
3648
  }
3649
  console.info('Callback invoked to indicate that the device is set to the active status.');
3650
});
3651 3652
```

3653
### setCommunicationDevice<sup>9+</sup>
3654

3655
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
3656

3657
Sets a communication device to the active state. This API uses a promise to return the result.
3658

3659 3660 3661 3662 3663 3664 3665 3666
**System capability**: SystemCapability.Multimedia.Audio.Communication

**Parameters**

| 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.    |
3667 3668 3669

**Return value**

3670 3671 3672
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
3673 3674 3675 3676

**Example**

```js
3677 3678
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
3679 3680 3681
});
```

3682
### isCommunicationDeviceActive<sup>9+</sup>
3683

3684
isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
3685

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

3688
**System capability**: SystemCapability.Multimedia.Audio.Communication
3689 3690 3691

**Parameters**

3692 3693 3694 3695
| 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.|
3696 3697 3698 3699

**Example**

```js
3700
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => {
3701
  if (err) {
3702 3703
    console.error(`Failed to obtain the active status of the device. ${err}`);
    return;
3704
  }
3705
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
3706 3707 3708
});
```

3709
### isCommunicationDeviceActive<sup>9+</sup>
3710

3711
isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
3712

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

3715
**System capability**: SystemCapability.Multimedia.Audio.Communication
3716 3717 3718

**Parameters**

3719 3720 3721
| Name    | Type                                                 | Mandatory| Description              |
| ---------- | ---------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.|
3722 3723 3724

**Return value**

3725 3726 3727
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
3728 3729 3730 3731

**Example**

```js
3732 3733
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
3734 3735 3736
});
```

3737
### selectOutputDevice<sup>9+</sup>
3738

3739
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3740

3741
Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
3742

3743 3744 3745
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
3746 3747 3748

**Parameters**

3749 3750 3751 3752
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
3753 3754 3755

**Example**
```js
3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3769

3770 3771 3772 3773 3774 3775 3776 3777
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices result callback: SUCCESS'); }
  });
}
3778 3779
```

3780
### selectOutputDevice<sup>9+</sup>
3781

3782
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3783

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

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

3788
**System capability**: SystemCapability.Multimedia.Audio.Device
3789 3790 3791

**Parameters**

3792 3793 3794
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3795 3796 3797

**Return value**

3798 3799 3800
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3801 3802 3803 3804

**Example**

```js
3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3818

3819 3820 3821 3822 3823 3824 3825
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  });
}
3826 3827
```

3828
### selectOutputDeviceByFilter<sup>9+</sup>
3829

3830
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3831

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

3834 3835 3836
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
3837 3838 3839

**Parameters**

3840 3841 3842 3843 3844
| 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.|
3845 3846 3847

**Example**
```js
3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
  
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3869

3870 3871 3872 3873 3874 3875 3876 3877
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'); }
  });
}
3878 3879
```

3880
### selectOutputDeviceByFilter<sup>9+</sup>
3881

3882
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3883

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

3886 3887 3888
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
3889 3890 3891

**Parameters**

3892 3893 3894 3895
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3896 3897 3898

**Return value**

3899 3900 3901
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3902 3903 3904 3905

**Example**

```js
3906 3907 3908 3909 3910 3911 3912
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3913

3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3927

3928 3929 3930 3931 3932 3933 3934 3935
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}`);
  })
}
```
3936

3937
## AudioRendererChangeInfoArray<sup>9+</sup>
3938

3939
Defines an **AudioRenderChangeInfo** array, which is read-only.
3940 3941 3942

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

3943
## AudioRendererChangeInfo<sup>9+</sup>
3944

3945 3946 3947 3948 3949 3950 3951 3952 3953 3954
Describes the audio renderer change event.

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

| 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.                      |
3955 3956 3957 3958

**Example**

```js
G
Gloria 已提交
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
import audio from '@ohos.multimedia.audio';

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

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}`);
    }
3990 3991 3992 3993 3994
  }
});
```


3995
## AudioCapturerChangeInfoArray<sup>9+</sup>
3996

3997
Defines an **AudioCapturerChangeInfo** array, which is read-only.
3998

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

4001
## AudioCapturerChangeInfo<sup>9+</sup>
4002

4003
Describes the audio capturer change event.
4004

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

4007 4008 4009 4010 4011 4012
| 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.                      |
4013 4014 4015 4016

**Example**

```js
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040
import audio from '@ohos.multimedia.audio';

const audioManager = audio.getAudioManager();
let audioStreamManager = audioManager.getStreamManager();

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}`);
4041
    }
4042 4043 4044
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4045 4046 4047 4048 4049
    }
  }
});
```

4050
## AudioDeviceDescriptors
4051

4052
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
4053

4054
## AudioDeviceDescriptor
4055

4056
Describes an audio device.
4057

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

4060 4061 4062 4063
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
G
Gloria 已提交
4064
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID, which is unique.                                  |
4065 4066 4067 4068 4069 4070 4071 4072
| 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. |
4073 4074 4075 4076

**Example**

```js
4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093
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');
4094 4095 4096 4097
  }
});
```

4098
## AudioRendererFilter<sup>9+</sup>
4099

4100
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4101

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

4104 4105 4106 4107 4108
| 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 |
4109

4110
**Example**
4111

4112 4113 4114 4115 4116 4117 4118 4119 4120
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4121

4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132
## AudioRenderer<sup>8+</sup>

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. |
4133 4134 4135 4136

**Example**

```js
4137
let state = audioRenderer.state;
4138 4139
```

4140
### getRendererInfo<sup>8+</sup>
4141

4142
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4143

4144
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4145 4146 4147 4148 4149

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

**Parameters**

4150 4151 4152
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
4153 4154 4155 4156

**Example**

```js
4157 4158 4159 4160 4161
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}`);
4162 4163 4164
});
```

4165
### getRendererInfo<sup>8+</sup>
4166

4167
getRendererInfo(): Promise<AudioRendererInfo\>
4168

4169
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4170 4171 4172

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

4173
**Return value**
4174

4175 4176 4177
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
4178 4179 4180 4181

**Example**

```js
4182 4183 4184 4185 4186 4187 4188 4189
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}`);
});
4190 4191
```

4192
### getStreamInfo<sup>8+</sup>
4193

4194
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4195

4196
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4197 4198 4199 4200 4201

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

**Parameters**

4202 4203 4204
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
4205 4206 4207 4208

**Example**

```js
4209 4210 4211 4212 4213 4214
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}`);
4215 4216 4217
});
```

4218
### getStreamInfo<sup>8+</sup>
4219

4220
getStreamInfo(): Promise<AudioStreamInfo\>
4221

4222
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
4223

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

4226 4227 4228 4229 4230
**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
4231 4232 4233 4234

**Example**

```js
4235 4236 4237 4238 4239 4240 4241 4242 4243
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}`);
});
4244
```
4245

4246
### getAudioStreamId<sup>9+</sup>
4247

4248
getAudioStreamId(callback: AsyncCallback<number\>): void
4249

4250
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4251

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

4254 4255
**Parameters**

4256 4257 4258
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
4259

4260 4261
**Example**

G
Gloria 已提交
4262
```js
4263 4264
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4265
});
4266 4267
```

4268
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4269

4270
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4271

4272
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4273

4274
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4275 4276

**Return value**
V
Vaidegi B 已提交
4277

4278 4279 4280
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
4281

W
wusongqing 已提交
4282
**Example**
V
Vaidegi B 已提交
4283

G
Gloria 已提交
4284
```js
4285 4286
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4287
}).catch((err) => {
4288
  console.error(`ERROR: ${err}`);
4289 4290
});
```
V
Vaidegi B 已提交
4291

4292
### start<sup>8+</sup>
4293

4294
start(callback: AsyncCallback<void\>): void
4295

4296
Starts the renderer. This API uses an asynchronous callback to return the result.
4297

4298
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4299 4300 4301

**Parameters**

4302 4303 4304
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4305 4306 4307 4308

**Example**

```js
4309
audioRenderer.start((err) => {
4310
  if (err) {
4311
    console.error('Renderer start failed.');
4312
  } else {
4313
    console.info('Renderer start success.');
4314
  }
4315
});
V
Vaidegi B 已提交
4316 4317
```

4318
### start<sup>8+</sup>
G
Gloria 已提交
4319

4320
start(): Promise<void\>
G
Gloria 已提交
4321

4322
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
4323

4324
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4325 4326 4327

**Return value**

4328 4329 4330
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
4331 4332 4333 4334

**Example**

```js
4335 4336
audioRenderer.start().then(() => {
  console.info('Renderer started');
4337
}).catch((err) => {
4338
  console.error(`ERROR: ${err}`);
4339 4340 4341
});
```

4342
### pause<sup>8+</sup>
4343

4344
pause(callback: AsyncCallback\<void>): void
4345

4346
Pauses rendering. This API uses an asynchronous callback to return the result.
4347

4348
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4349 4350 4351

**Parameters**

4352 4353 4354
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4355 4356 4357 4358

**Example**

```js
4359 4360 4361 4362 4363 4364
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4365 4366 4367
});
```

4368
### pause<sup>8+</sup>
4369

4370
pause(): Promise\<void>
4371

4372
Pauses rendering. This API uses a promise to return the result.
4373

4374
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4375 4376 4377

**Return value**

4378 4379 4380
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
4381 4382 4383 4384

**Example**

```js
4385 4386
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4387 4388 4389 4390 4391
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
```

4392
### drain<sup>8+</sup>
4393

4394
drain(callback: AsyncCallback\<void>): void
4395

4396
Drains the playback buffer. This API uses an asynchronous callback to return the result.
4397

4398
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4399 4400 4401 4402

**Parameters**

| Name     | Type                 | Mandatory | Description                         |
4403 4404
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4405 4406 4407 4408

**Example**

```js
4409
audioRenderer.drain((err) => {
4410
  if (err) {
4411
    console.error('Renderer drain failed');
4412
  } else {
4413
    console.info('Renderer drained.');
4414 4415
  }
});
G
Gloria 已提交
4416 4417
```

4418
### drain<sup>8+</sup>
V
Vaidegi B 已提交
4419

4420
drain(): Promise\<void>
V
Vaidegi B 已提交
4421

4422
Drains the playback buffer. This API uses a promise to return the result.
4423

4424
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4425 4426 4427 4428

**Return value**

| Type           | Description                        |
4429 4430
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4431

W
wusongqing 已提交
4432
**Example**
V
Vaidegi B 已提交
4433

G
Gloria 已提交
4434
```js
4435 4436
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
4437
}).catch((err) => {
4438
  console.error(`ERROR: ${err}`);
4439
});
V
Vaidegi B 已提交
4440 4441
```

4442
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4443

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

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

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

W
wusongqing 已提交
4450
**Parameters**
V
Vaidegi B 已提交
4451

4452
| Name     | Type                 | Mandatory | Description                         |
4453 4454
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4455

W
wusongqing 已提交
4456
**Example**
V
Vaidegi B 已提交
4457

G
Gloria 已提交
4458
```js
4459
audioRenderer.stop((err) => {
4460
  if (err) {
4461
    console.error('Renderer stop failed');
4462
  } else {
4463
    console.info('Renderer stopped.');
4464
  }
4465
});
V
Vaidegi B 已提交
4466 4467
```

4468
### stop<sup>8+</sup>
4469

4470
stop(): Promise\<void>
V
Vaidegi B 已提交
4471

4472
Stops rendering. This API uses a promise to return the result.
4473

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

W
wusongqing 已提交
4476
**Return value**
V
Vaidegi B 已提交
4477

4478
| Type           | Description                        |
4479 4480
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4481

W
wusongqing 已提交
4482
**Example**
V
Vaidegi B 已提交
4483

G
Gloria 已提交
4484
```js
4485 4486
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4487
}).catch((err) => {
4488
  console.error(`ERROR: ${err}`);
4489 4490
});
```
V
Vaidegi B 已提交
4491

4492
### release<sup>8+</sup>
V
Vaidegi B 已提交
4493

4494
release(callback: AsyncCallback\<void>): void
4495

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

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

W
wusongqing 已提交
4500
**Parameters**
V
Vaidegi B 已提交
4501

4502
| Name     | Type                 | Mandatory | Description                         |
4503 4504
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4505

W
wusongqing 已提交
4506
**Example**
V
Vaidegi B 已提交
4507

G
Gloria 已提交
4508
```js
4509
audioRenderer.release((err) => {
4510
  if (err) {
4511
    console.error('Renderer release failed');
4512
  } else {
4513
    console.info('Renderer released.');
4514
  }
4515
});
V
Vaidegi B 已提交
4516 4517
```

4518
### release<sup>8+</sup>
V
Vaidegi B 已提交
4519

4520
release(): Promise\<void>
V
Vaidegi B 已提交
4521

4522
Releases the renderer. This API uses a promise to return the result.
4523

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

W
wusongqing 已提交
4526
**Return value**
V
Vaidegi B 已提交
4527

4528
| Type           | Description                        |
4529 4530
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4531

W
wusongqing 已提交
4532
**Example**
V
Vaidegi B 已提交
4533

G
Gloria 已提交
4534
```js
4535 4536
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4537
}).catch((err) => {
4538
  console.error(`ERROR: ${err}`);
4539
});
V
Vaidegi B 已提交
4540 4541
```

4542
### write<sup>8+</sup>
V
Vaidegi B 已提交
4543

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

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

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

W
wusongqing 已提交
4550
**Parameters**
V
Vaidegi B 已提交
4551

4552 4553 4554 4555
| 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. |
V
Vaidegi B 已提交
4556

W
wusongqing 已提交
4557
**Example**
V
Vaidegi B 已提交
4558

G
Gloria 已提交
4559
```js
4560
let bufferSize;
4561 4562
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4563 4564
  bufferSize = data;
  }).catch((err) => {
4565
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4566
  });
4567 4568 4569 4570 4571 4572 4573
console.info(`Buffer size: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
G
Gloria 已提交
4574 4575
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4576
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4577
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4578 4579
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4580 4581
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4582 4583 4584
    }
    let readsize = await fs.read(file.fd, buf, options)
    let writeSize = await new Promise((resolve,reject)=>{
G
Gloria 已提交
4585
      audioRenderer.write(buf,(err,writeSize)=>{
G
Gloria 已提交
4586 4587 4588 4589 4590 4591 4592 4593 4594
        if(err){
          reject(err)
        }else{
          resolve(writeSize)
        }
      })
    })	  
}

V
Vaidegi B 已提交
4595 4596
```

4597
### write<sup>8+</sup>
V
Vaidegi B 已提交
4598

4599
write(buffer: ArrayBuffer): Promise\<number>
4600

4601
Writes the buffer. This API uses a promise to return the result.
4602

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

W
wusongqing 已提交
4605
**Return value**
V
Vaidegi B 已提交
4606

4607 4608 4609
| 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. |
V
Vaidegi B 已提交
4610

W
wusongqing 已提交
4611
**Example**
V
Vaidegi B 已提交
4612

G
Gloria 已提交
4613
```js
4614
let bufferSize;
4615 4616
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4617 4618
  bufferSize = data;
  }).catch((err) => {
4619
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4620
  });
4621 4622 4623 4624 4625 4626 4627
console.info(`BufferSize: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
G
Gloria 已提交
4628 4629
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4630
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4631
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4632 4633
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4634 4635
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4636 4637 4638
    }
    let readsize = await fs.read(file.fd, buf, options)
    try{
G
Gloria 已提交
4639
       let writeSize = await audioRenderer.write(buf);
G
Gloria 已提交
4640 4641 4642 4643
    } catch(err) {
       console.error(`audioRenderer.write err: ${err}`);
    }   
}
V
Vaidegi B 已提交
4644 4645
```

4646
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4647

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

4650
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 已提交
4651

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

W
wusongqing 已提交
4654
**Parameters**
V
Vaidegi B 已提交
4655

4656 4657 4658
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
V
Vaidegi B 已提交
4659

W
wusongqing 已提交
4660
**Example**
V
Vaidegi B 已提交
4661

G
Gloria 已提交
4662
```js
4663
audioRenderer.getAudioTime((err, timestamp) => {
4664
  console.info(`Current timestamp: ${timestamp}`);
4665
});
V
Vaidegi B 已提交
4666 4667
```

4668
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4669

4670
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4671

4672
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4673

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

W
wusongqing 已提交
4676
**Return value**
V
Vaidegi B 已提交
4677

4678
| Type             | Description                           |
4679 4680
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4681

W
wusongqing 已提交
4682
**Example**
V
Vaidegi B 已提交
4683

G
Gloria 已提交
4684
```js
4685 4686
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4687
}).catch((err) => {
4688
  console.error(`ERROR: ${err}`);
4689
});
V
Vaidegi B 已提交
4690 4691
```

4692
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4693

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

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

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

W
wusongqing 已提交
4700
**Parameters**
V
Vaidegi B 已提交
4701

4702
| Name     | Type                   | Mandatory | Description                              |
4703 4704
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4705

W
wusongqing 已提交
4706
**Example**
V
Vaidegi B 已提交
4707

G
Gloria 已提交
4708
```js
4709 4710 4711
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4712
  }
4713
});
V
Vaidegi B 已提交
4714 4715
```

4716
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4717

4718
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4719

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

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

W
wusongqing 已提交
4724
**Return value**
V
Vaidegi B 已提交
4725

4726
| Type             | Description                             |
4727 4728
| ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4729

W
wusongqing 已提交
4730
**Example**
V
Vaidegi B 已提交
4731

G
Gloria 已提交
4732
```js
4733
let bufferSize;
4734 4735
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4736
  bufferSize = data;
4737
}).catch((err) => {
4738
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4739
});
V
Vaidegi B 已提交
4740 4741
```

4742
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4743

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

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

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

W
wusongqing 已提交
4750
**Parameters**
V
Vaidegi B 已提交
4751

4752 4753 4754 4755
| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4756

W
wusongqing 已提交
4757
**Example**
V
Vaidegi B 已提交
4758

G
Gloria 已提交
4759
```js
4760 4761 4762 4763 4764
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.');
4765
  }
4766
});
V
Vaidegi B 已提交
4767 4768
```

4769
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4770

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

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

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

W
wusongqing 已提交
4777
**Parameters**
V
Vaidegi B 已提交
4778

4779 4780 4781 4782 4783 4784 4785 4786 4787
| Name | Type                                     | Mandatory | Description        |
| ---- | ---------------------------------------- | --------- | ------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |

**Return value**

| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4788

W
wusongqing 已提交
4789
**Example**
V
Vaidegi B 已提交
4790

G
Gloria 已提交
4791
```js
4792 4793 4794 4795
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4796
});
V
Vaidegi B 已提交
4797 4798
```

4799
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4800

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

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

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

4807
**Parameters**
V
Vaidegi B 已提交
4808

4809 4810 4811
| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
4812

W
wusongqing 已提交
4813
**Example**
V
Vaidegi B 已提交
4814

G
Gloria 已提交
4815
```js
4816 4817 4818
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
V
Vaidegi B 已提交
4819 4820
```

4821
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4822

4823
getRenderRate(): Promise\<AudioRendererRate>
V
Vaidegi B 已提交
4824

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

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

4829
**Return value**
V
Vaidegi B 已提交
4830

4831 4832 4833
| Type                                              | Description                                   |
| ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
V
Vaidegi B 已提交
4834

W
wusongqing 已提交
4835
**Example**
V
Vaidegi B 已提交
4836

G
Gloria 已提交
4837
```js
4838 4839 4840 4841
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4842
});
V
Vaidegi B 已提交
4843
```
4844
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
4845

4846
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4847

4848
Sets the audio interruption mode for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4849

4850
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4851

4852
**Parameters**
V
Vaidegi B 已提交
4853

4854 4855 4856
| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
V
Vaidegi B 已提交
4857

4858
**Return value**
4859

4860 4861 4862
| Type                | Description                                                  |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |
V
Vaidegi B 已提交
4863

4864
**Example**
V
Vaidegi B 已提交
4865

4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880
```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
V
Vaidegi B 已提交
4881

W
wusongqing 已提交
4882
**Parameters**
V
Vaidegi B 已提交
4883

4884 4885 4886 4887
| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4888

W
wusongqing 已提交
4889
**Example**
V
Vaidegi B 已提交
4890

G
Gloria 已提交
4891
```js
4892 4893 4894 4895
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
4896
  }
4897
  console.info('setInterruptMode Success!');
4898
});
V
Vaidegi B 已提交
4899 4900
```

4901
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4902

4903
setVolume(volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
4904

4905
Sets the volume for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4906

4907
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4908 4909 4910

**Parameters**

4911 4912 4913
| Name   | Type   | Mandatory | Description                                                  |
| ------ | ------ | --------- | ------------------------------------------------------------ |
| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
4914

W
wusongqing 已提交
4915
**Return value**
V
Vaidegi B 已提交
4916

4917 4918 4919
| Type                | Description                                                  |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |
V
Vaidegi B 已提交
4920

W
wusongqing 已提交
4921
**Example**
V
Vaidegi B 已提交
4922

G
Gloria 已提交
4923
```js
4924 4925 4926 4927
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
4928
});
V
Vaidegi B 已提交
4929
```
4930
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4931

4932
setVolume(volume: number, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
4933

4934
Sets the volume for the application. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4935

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

W
wusongqing 已提交
4938
**Parameters**
V
Vaidegi B 已提交
4939

4940 4941 4942 4943
| Name     | Type                 | Mandatory | Description                                                  |
| -------- | -------------------- | --------- | ------------------------------------------------------------ |
| volume   | number               | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result.                          |
V
Vaidegi B 已提交
4944

W
wusongqing 已提交
4945
**Example**
V
Vaidegi B 已提交
4946

G
Gloria 已提交
4947
```js
4948 4949 4950
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
4951
  }
4952
  console.info('setVolume Success!');
4953
});
V
Vaidegi B 已提交
4954 4955
```

4956
### on('audioInterrupt')<sup>9+</sup>
V
Vaidegi B 已提交
4957

4958
on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
4959

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

4962
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.
V
Vaidegi B 已提交
4963

4964
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4965

4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978
**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                  |
| ------- | ------------------------------ |
G
Gloria 已提交
4979
| 6800101 | if input parameter value error              |
V
Vaidegi B 已提交
4980

W
wusongqing 已提交
4981
**Example**
V
Vaidegi B 已提交
4982

G
Gloria 已提交
4983
```js
4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032
let isPlay;
let started;
onAudioInterrupt();

async function onAudioInterrupt(){
  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;
      }
    } 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;
      }
   }
  });
}
V
Vaidegi B 已提交
5033 5034
```

5035
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
5036

5037
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5038

5039
Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is invoked.
V
Vaidegi B 已提交
5040

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

W
wusongqing 已提交
5043
**Parameters**
5044

5045 5046 5047 5048 5049
| 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 已提交
5050

W
wusongqing 已提交
5051
**Example**
V
Vaidegi B 已提交
5052

G
Gloria 已提交
5053
```js
5054 5055 5056
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5057
  }
5058
});
V
Vaidegi B 已提交
5059 5060 5061
```


5062
### off('markReach') <sup>8+</sup>
5063

5064
off(type: 'markReach'): void
V
Vaidegi B 已提交
5065

5066
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5067

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

5070 5071 5072 5073 5074
**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
5075

W
wusongqing 已提交
5076
**Example**
V
Vaidegi B 已提交
5077

G
Gloria 已提交
5078
```js
5079
audioRenderer.off('markReach');
V
Vaidegi B 已提交
5080 5081
```

5082
### on('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5083

5084
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5085

5086
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.
V
Vaidegi B 已提交
5087

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

W
wusongqing 已提交
5090
**Parameters**
5091

5092 5093 5094 5095 5096
| 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 已提交
5097

W
wusongqing 已提交
5098
**Example**
V
Vaidegi B 已提交
5099

G
Gloria 已提交
5100
```js
5101 5102 5103
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5104
  }
5105
});
V
Vaidegi B 已提交
5106 5107
```

5108
### off('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5109

5110
off(type: 'periodReach'): void
5111

5112
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5113

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

5116
**Parameters**
V
Vaidegi B 已提交
5117

5118 5119 5120
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
5121

W
wusongqing 已提交
5122
**Example**
V
Vaidegi B 已提交
5123

G
Gloria 已提交
5124
```js
5125
audioRenderer.off('periodReach')
V
Vaidegi B 已提交
5126
```
5127

G
Gloria 已提交
5128
### on('stateChange') <sup>8+</sup>
W
wusongqing 已提交
5129

5130
on(type: 'stateChange', callback: Callback<AudioState\>): void
W
wusongqing 已提交
5131

5132
Subscribes to state change events.
W
wusongqing 已提交
5133

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

5136
**Parameters**
W
wusongqing 已提交
5137

5138 5139 5140 5141
| Name     | Type                                  | Mandatory | Description                                                  |
| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the state change.                    |
W
wusongqing 已提交
5142

5143
**Example**
W
wusongqing 已提交
5144

5145 5146 5147 5148 5149 5150 5151 5152 5153 5154
```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');
  }
});
```
5155

5156
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5157

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

5160
### Attributes
5161

5162
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5163

5164 5165 5166
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
V
Vaidegi B 已提交
5167

5168
**Example**
V
Vaidegi B 已提交
5169

5170 5171 5172
```js
let state = audioCapturer.state;
```
V
Vaidegi B 已提交
5173

5174
### getCapturerInfo<sup>8+</sup>
5175

5176
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5177

5178
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5179

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

W
wusongqing 已提交
5182
**Parameters**
5183

5184 5185 5186
| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
5187

W
wusongqing 已提交
5188
**Example**
5189

G
Gloria 已提交
5190
```js
5191
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5192
  if (err) {
5193 5194 5195 5196 5197
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5198
  }
5199 5200 5201
});
```

5202

5203
### getCapturerInfo<sup>8+</sup>
5204

5205
getCapturerInfo(): Promise<AudioCapturerInfo\>
5206

5207
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
5208

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

5211
**Return value**
5212

5213 5214 5215
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
5216

W
wusongqing 已提交
5217
**Example**
5218

G
Gloria 已提交
5219
```js
5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230
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}`);
5231
});
5232 5233
```

5234
### getStreamInfo<sup>8+</sup>
5235

5236
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5237

5238
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5239

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

W
wusongqing 已提交
5242
**Parameters**
5243

5244 5245 5246
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5247

W
wusongqing 已提交
5248
**Example**
5249

G
Gloria 已提交
5250
```js
5251
audioCapturer.getStreamInfo((err, streamInfo) => {
5252
  if (err) {
5253 5254 5255 5256 5257 5258 5259
    console.error('Failed to get stream info');
  } else {
    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}`);
5260
  }
5261 5262 5263
});
```

5264
### getStreamInfo<sup>8+</sup>
5265

5266
getStreamInfo(): Promise<AudioStreamInfo\>
5267

5268
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
5269

5270
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5271 5272 5273

**Return value**

5274 5275 5276
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5277

W
wusongqing 已提交
5278
**Example**
5279

G
Gloria 已提交
5280
```js
5281 5282 5283 5284 5285 5286 5287 5288
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}`);
5289
});
5290
```
V
Vaidegi B 已提交
5291

5292
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5293

5294
getAudioStreamId(callback: AsyncCallback<number\>): void
V
Vaidegi B 已提交
5295

5296
Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5297

5298
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5299

W
wusongqing 已提交
5300
**Parameters**
5301

5302 5303 5304
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5305

W
wusongqing 已提交
5306
**Example**
5307

G
Gloria 已提交
5308
```js
5309 5310
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5311
});
5312
```
V
Vaidegi B 已提交
5313

5314
### getAudioStreamId<sup>9+</sup>
5315

5316 5317 5318
getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
5319

5320
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5321 5322 5323

**Return value**

5324 5325 5326
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
5327

W
wusongqing 已提交
5328
**Example**
V
Vaidegi B 已提交
5329

G
Gloria 已提交
5330
```js
5331 5332 5333 5334
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5335
});
V
Vaidegi B 已提交
5336 5337
```

5338
### start<sup>8+</sup>
V
Vaidegi B 已提交
5339

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

5342
Starts capturing. This API uses an asynchronous callback to return the result.
5343

5344
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5345

W
wusongqing 已提交
5346
**Parameters**
V
Vaidegi B 已提交
5347

5348 5349 5350
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5351

W
wusongqing 已提交
5352
**Example**
V
Vaidegi B 已提交
5353

G
Gloria 已提交
5354
```js
5355
audioCapturer.start((err) => {
5356
  if (err) {
5357 5358 5359
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5360
  }
5361
});
V
Vaidegi B 已提交
5362 5363 5364
```


5365
### start<sup>8+</sup>
V
Vaidegi B 已提交
5366

5367
start(): Promise<void\>
5368

5369
Starts capturing. This API uses a promise to return the result.
5370

5371
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5372

W
wusongqing 已提交
5373
**Return value**
V
Vaidegi B 已提交
5374

5375 5376 5377
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5378

W
wusongqing 已提交
5379
**Example**
V
Vaidegi B 已提交
5380

G
Gloria 已提交
5381
```js
5382 5383 5384 5385 5386 5387 5388 5389 5390 5391
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}`);
5392
});
5393
```
V
Vaidegi B 已提交
5394

5395
### stop<sup>8+</sup>
5396

5397
stop(callback: AsyncCallback<void\>): void
5398

5399
Stops capturing. This API uses an asynchronous callback to return the result.
5400

5401
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5402

W
wusongqing 已提交
5403
**Parameters**
V
Vaidegi B 已提交
5404

5405 5406 5407
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5408

W
wusongqing 已提交
5409
**Example**
V
Vaidegi B 已提交
5410

G
Gloria 已提交
5411
```js
5412
audioCapturer.stop((err) => {
5413
  if (err) {
5414 5415 5416
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5417
  }
5418
});
V
Vaidegi B 已提交
5419 5420
```

5421

5422
### stop<sup>8+</sup>
5423

5424
stop(): Promise<void\>
5425

5426
Stops capturing. This API uses a promise to return the result.
5427

5428
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5429

W
wusongqing 已提交
5430
**Return value**
V
Vaidegi B 已提交
5431

5432 5433 5434
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5435

W
wusongqing 已提交
5436
**Example**
V
Vaidegi B 已提交
5437

G
Gloria 已提交
5438
```js
5439 5440 5441 5442 5443 5444 5445 5446
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:');
  }
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
5447
});
V
Vaidegi B 已提交
5448 5449
```

5450
### release<sup>8+</sup>
V
Vaidegi B 已提交
5451

5452
release(callback: AsyncCallback<void\>): void
5453

5454
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5455

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

W
wusongqing 已提交
5458
**Parameters**
5459

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

W
wusongqing 已提交
5464
**Example**
5465

G
Gloria 已提交
5466
```js
5467
audioCapturer.release((err) => {
5468
  if (err) {
5469 5470 5471
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5472
  }
5473
});
5474 5475 5476
```


5477
### release<sup>8+</sup>
5478

5479
release(): Promise<void\>
5480

5481
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5482

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

W
wusongqing 已提交
5485
**Return value**
5486

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

W
wusongqing 已提交
5491
**Example**
5492

G
Gloria 已提交
5493
```js
5494 5495 5496 5497 5498 5499 5500 5501
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}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
5502 5503 5504
});
```

5505
### read<sup>8+</sup>
5506

5507
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
5508

5509
Reads the buffer. This API uses an asynchronous callback to return the result.
5510

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

W
wusongqing 已提交
5513
**Parameters**
5514

5515 5516 5517 5518 5519
| 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.  |
5520

W
wusongqing 已提交
5521
**Example**
5522

G
Gloria 已提交
5523
```js
5524 5525 5526 5527 5528 5529 5530 5531 5532 5533
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');
5534
  }
5535
});
5536 5537
```

5538
### read<sup>8+</sup>
5539

5540
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5541

5542
Reads the buffer. This API uses a promise to return the result.
5543

5544
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5545 5546 5547

**Parameters**

5548 5549 5550 5551
| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
5552

W
wusongqing 已提交
5553
**Return value**
5554

5555 5556 5557
| 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. |
5558

W
wusongqing 已提交
5559
**Example**
5560

G
Gloria 已提交
5561
```js
5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573
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');
}).catch((err) => {
  console.info(`ERROR : ${err}`);
5574
});
5575
```
5576

5577
### getAudioTime<sup>8+</sup>
5578

5579
getAudioTime(callback: AsyncCallback<number\>): void
5580

5581 5582 5583
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
5585
**Parameters**
5586

5587 5588 5589
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
5590

W
wusongqing 已提交
5591
**Example**
5592

G
Gloria 已提交
5593
```js
5594 5595
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5596
});
5597 5598
```

5599
### getAudioTime<sup>8+</sup>
5600

5601
getAudioTime(): Promise<number\>
5602

5603
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
5604

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

W
wusongqing 已提交
5607
**Return value**
5608

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

W
wusongqing 已提交
5613
**Example**
5614

G
Gloria 已提交
5615
```js
5616 5617 5618 5619
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5620 5621 5622
});
```

5623
### getBufferSize<sup>8+</sup>
5624

5625
getBufferSize(callback: AsyncCallback<number\>): void
5626

5627
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
5628

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

W
wusongqing 已提交
5631
**Parameters**
5632

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

W
wusongqing 已提交
5637
**Example**
5638

G
Gloria 已提交
5639
```js
5640 5641 5642 5643 5644 5645 5646 5647
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}`);
    });
5648
  }
J
jiao_yanlin 已提交
5649
});
5650 5651
```

5652
### getBufferSize<sup>8+</sup>
5653

5654
getBufferSize(): Promise<number\>
5655

5656
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
5657

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

W
wusongqing 已提交
5660
**Return value**
5661

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

W
wusongqing 已提交
5666
**Example**
5667

G
Gloria 已提交
5668
```js
5669 5670 5671 5672 5673 5674
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5675 5676 5677
});
```

5678
### on('markReach')<sup>8+</sup>
5679

5680
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
5681

5682
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
5683

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

W
wusongqing 已提交
5686
**Parameters**
5687

5688 5689 5690 5691 5692
| 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.                |
5693

W
wusongqing 已提交
5694
**Example**
5695

G
Gloria 已提交
5696
```js
5697 5698 5699
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5700
  }
5701
});
5702 5703
```

5704
### off('markReach')<sup>8+</sup>
5705

5706
off(type: 'markReach'): void
5707

5708
Unsubscribes from mark reached events.
5709

5710
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5711 5712 5713

**Parameters**

5714 5715 5716
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
5717

W
wusongqing 已提交
5718
**Example**
5719

G
Gloria 已提交
5720
```js
5721
audioCapturer.off('markReach');
5722 5723
```

5724
### on('periodReach')<sup>8+</sup>
5725

5726
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
5727

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

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

W
wusongqing 已提交
5732
**Parameters**
5733

5734 5735 5736 5737 5738
| 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.                |
5739

W
wusongqing 已提交
5740
**Example**
5741

G
Gloria 已提交
5742
```js
5743 5744 5745
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5746
  }
5747 5748 5749
});
```

5750
### off('periodReach')<sup>8+</sup>
5751

5752
off(type: 'periodReach'): void
5753

5754
Unsubscribes from period reached events.
5755

5756
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5757 5758 5759

**Parameters**

5760 5761 5762
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
5763

W
wusongqing 已提交
5764
**Example**
5765

G
Gloria 已提交
5766
```js
5767
audioCapturer.off('periodReach')
5768 5769
```

G
Gloria 已提交
5770
### on('stateChange') <sup>8+</sup>
5771

5772
on(type: 'stateChange', callback: Callback<AudioState\>): void
5773

5774
Subscribes to state change events.
5775

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

W
wusongqing 已提交
5778
**Parameters**
5779

5780 5781 5782 5783
| Name     | Type                                  | Mandatory | Description                                                  |
| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- |
| type     | string                                | Yes       | Event type. The value **stateChange** means the state change event. |
| callback | Callback\<[AudioState](#audiostate8)> | Yes       | Callback used to return the state change.                    |
5784

W
wusongqing 已提交
5785
**Example**
5786

G
Gloria 已提交
5787
```js
5788 5789 5790 5791 5792 5793
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');
5794
  }
5795 5796 5797
});
```

5798
## ToneType<sup>9+</sup>
5799

5800
Enumerates the tone types of the player.
5801

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

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

5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834
| Name                                             | 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.          |
5835

5836
## TonePlayer<sup>9+</sup>
5837

5838
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
5839

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

5842
### load<sup>9+</sup>
5843

5844
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
5845

5846
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
5847

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

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

W
wusongqing 已提交
5852
**Parameters**
5853

5854 5855 5856 5857
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
5858

W
wusongqing 已提交
5859
**Example**
5860

G
Gloria 已提交
5861
```js
5862
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
5863
  if (err) {
5864
    console.error(`callback call load failed error: ${err.message}`);
5865
    return;
5866 5867
  } else {
    console.info('callback call load success');
5868 5869
  }
});
5870 5871
```

5872
### load<sup>9+</sup>
5873

5874
load(type: ToneType): Promise&lt;void&gt;
5875

5876
Loads the DTMF tone configuration. This API uses a promise to return the result.
5877

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

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

W
wusongqing 已提交
5882
**Parameters**
5883

5884 5885 5886
| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
5887 5888 5889

**Return value**

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

W
wusongqing 已提交
5894
**Example**
5895

G
Gloria 已提交
5896
```js
5897 5898 5899 5900
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
5901
});
5902
```
5903

5904
### start<sup>9+</sup>
5905

5906
start(callback: AsyncCallback&lt;void&gt;): void
5907

5908
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
5909

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

5912
**System capability**: SystemCapability.Multimedia.Audio.Tone
5913 5914 5915

**Parameters**

5916 5917 5918
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5919 5920 5921 5922

**Example**

```js
5923
tonePlayer.start((err) => {
5924
  if (err) {
5925
    console.error(`callback call start failed error: ${err.message}`);
5926
    return;
5927 5928
  } else {
    console.info('callback call start success');
5929 5930 5931 5932
  }
});
```

5933
### start<sup>9+</sup>
5934

5935
start(): Promise&lt;void&gt;
5936

5937
Starts DTMF tone playing. This API uses a promise to return the result.
5938

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

5941
**System capability**: SystemCapability.Multimedia.Audio.Tone
5942 5943 5944

**Return value**

5945 5946 5947
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5948 5949 5950 5951

**Example**

```js
5952 5953 5954 5955
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
5956 5957 5958
});
```

5959
### stop<sup>9+</sup>
5960

5961
stop(callback: AsyncCallback&lt;void&gt;): void
5962

5963
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
5964 5965 5966

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

5967
**System capability**: SystemCapability.Multimedia.Audio.Tone
5968 5969 5970

**Parameters**

5971 5972 5973
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5974 5975 5976 5977

**Example**

```js
5978 5979 5980 5981 5982 5983 5984
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
5985 5986 5987
});
```

5988
### stop<sup>9+</sup>
5989

5990
stop(): Promise&lt;void&gt;
5991

5992
Stops the tone that is being played. This API uses a promise to return the result.
5993

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

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

5998
**Return value**
5999

6000 6001 6002
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6003 6004 6005 6006

**Example**

```js
6007 6008 6009 6010
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
6011 6012 6013
});
```

6014
### release<sup>9+</sup>
6015

6016
release(callback: AsyncCallback&lt;void&gt;): void
6017

6018
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
6019

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

6022
**System capability**: SystemCapability.Multimedia.Audio.Tone
6023 6024 6025

**Parameters**

6026 6027 6028
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6029 6030 6031 6032

**Example**

```js
6033 6034 6035 6036 6037 6038 6039
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6040 6041 6042
});
```

6043
### release<sup>9+</sup>
6044

6045
release(): Promise&lt;void&gt;
6046

6047
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
6048

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

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

6053
**Return value**
6054

6055 6056 6057
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6058 6059 6060 6061

**Example**

```js
6062 6063 6064 6065
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6066 6067 6068
});
```

6069
## ActiveDeviceType<sup>(deprecated)</sup>
6070

6071
Enumerates the active device types.
6072

6073 6074 6075
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6076

6077 6078 6079 6080 6081 6082 6083 6084 6085 6086
**System capability**: SystemCapability.Multimedia.Audio.Device

| Name          | Value | Description                                                  |
| ------------- | ----- | ------------------------------------------------------------ |
| SPEAKER       | 2     | Speaker.                                                     |
| BLUETOOTH_SCO | 7     | Bluetooth device using Synchronous Connection Oriented (SCO) links. |

## InterruptActionType<sup>(deprecated)</sup>

Enumerates the returned event types for audio interruption events.
6087 6088 6089 6090 6091 6092

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

6094 6095 6096 6097
| Name           | Value | Description               |
| -------------- | ----- | ------------------------- |
| TYPE_ACTIVATED | 0     | Focus gain event.         |
| TYPE_INTERRUPT | 1     | Audio interruption event. |
6098

6099
## AudioInterrupt<sup>(deprecated)</sup>
6100

6101
Describes input parameters of audio interruption events.
6102

6103 6104 6105
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6106

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

6109 6110 6111 6112 6113
| 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. |
6114

6115
## InterruptAction<sup>(deprecated)</sup>
6116

6117
Describes the callback invoked for audio interruption or focus gain events.
6118

6119 6120 6121
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6122

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

6125 6126 6127 6128 6129 6130
| Name       | Type                                                  | Mandatory | Description                                                  |
| ---------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontypedeprecated) | 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. |