js-apis-audio.md 229.3 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              |
| --------------------------------------- | ----------| ---- | ---- | ------------------ |
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 78
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
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 133
import featureAbility from '@ohos.ability.featureAbility';
import fileio from '@ohos.fileio';
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 352
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
| RINGTONE                     | 2      | Audio stream for ringtones.    |
| MEDIA                        | 3      | Audio stream for media purpose.    |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
353 354 355 356 357 358 359 360 361 362
| 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.

363
| Name                        | Value     | Description      |
364 365 366
| ---------------------------- | ------ | ---------- |
| 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 已提交
367

W
wusongqing 已提交
368 369 370 371
## InterruptMode<sup>9+</sup>

Enumerates the audio interruption modes.

372
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
W
wusongqing 已提交
373

374
| Name                        | Value     | Description      |
W
wusongqing 已提交
375
| ---------------------------- | ------ | ---------- |
376 377
| SHARE_MODE                   | 0      | Shared mode.|
| INDEPENDENT_MODE             | 1      | Independent mode.|
W
wusongqing 已提交
378

379
## DeviceFlag
W
wusongqing 已提交
380

W
wusongqing 已提交
381
Enumerates the audio device flags.
W
wusongqing 已提交
382

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

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

## DeviceRole
W
wusongqing 已提交
396

W
wusongqing 已提交
397 398 399
Enumerates the audio device roles.

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

401
| Name         |  Value   | Description          |
W
wusongqing 已提交
402 403 404
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
405

406
## DeviceType
W
wusongqing 已提交
407

W
wusongqing 已提交
408
Enumerates the audio device types.
W
wusongqing 已提交
409

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

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

425
## CommunicationDeviceType<sup>9+</sup>
V
Vaidegi B 已提交
426

427
Enumerates the device types used for communication.
W
wusongqing 已提交
428

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

431
| Name         | Value    | Description         |
432 433
| ------------- | ------ | -------------|
| SPEAKER       | 2      | Speaker.     |
W
wusongqing 已提交
434 435

## AudioRingMode
W
wusongqing 已提交
436

W
wusongqing 已提交
437
Enumerates the ringer modes.
W
wusongqing 已提交
438

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

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

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

449
Enumerates the audio sample formats.
V
Vaidegi B 已提交
450

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

453
| Name                               |  Value   | Description                      |
454 455 456 457 458 459 460
| ---------------------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID              | -1     | Invalid format.                |
| SAMPLE_FORMAT_U8                   | 0      | Unsigned 8-bit integer.           |
| SAMPLE_FORMAT_S16LE                | 1      | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE                | 2      | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_S32LE                | 3      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
461

462 463 464 465 466 467
## AudioErrors<sup>9+</sup>

Enumerates the audio error codes.

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

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

478
## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
479 480 481

Enumerates the audio channels.

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

484
| Name     |  Value      | Description    |
W
wusongqing 已提交
485 486 487
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
488 489

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

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

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

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

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

V
Vaidegi B 已提交
511 512
Enumerates the audio encoding types.

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

515
| Name                 |  Value   | Description     |
W
wusongqing 已提交
516 517 518
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
519

520 521
## ContentType

W
wusongqing 已提交
522
Enumerates the audio content types.
523

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

526
| Name                              |  Value   | Description      |
W
wusongqing 已提交
527 528 529 530 531 532 533
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
| CONTENT_TYPE_SONIFICATION          | 4      | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
V
Vaidegi B 已提交
534

535 536
## StreamUsage

W
wusongqing 已提交
537
Enumerates the audio stream usage.
V
Vaidegi B 已提交
538

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

541
| Name                                     |  Value   | Description      |
542 543 544 545 546 547
| ------------------------------------------| ------ | ---------- |
| STREAM_USAGE_UNKNOWN                      | 0      | Unknown usage.|
| STREAM_USAGE_MEDIA                        | 1      | Used for media.    |
| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | Used for voice communication.|
| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | Used for voice assistant.|
| STREAM_USAGE_NOTIFICATION_RINGTONE        | 6      | Used for notification.|
V
Vaidegi B 已提交
548

549
## InterruptRequestType<sup>9+</sup>
550

551
Enumerates the audio interruption request types.
552

G
Gloria 已提交
553 554
**System API**: This is a system API.

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

557
| Name                              |  Value    | Description                      |
558 559
| ---------------------------------- | ------ | ------------------------- |
| INTERRUPT_REQUEST_TYPE_DEFAULT     | 0      |  Default type, which can be used to interrupt audio requests. |
560

561 562
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
563 564
Enumerates the audio states.

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

567
| Name          | Value    | Description            |
W
wusongqing 已提交
568 569 570 571 572 573 574 575
| -------------- | ------ | ---------------- |
| 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 已提交
576

577 578
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
579 580
Enumerates the audio renderer rates.

W
wusongqing 已提交
581
**System capability**: SystemCapability.Multimedia.Audio.Renderer
582

583
| Name              | Value    | Description      |
W
wusongqing 已提交
584 585 586 587
| ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0      | Normal rate.|
| RENDER_RATE_DOUBLE | 1      | Double rate.   |
| RENDER_RATE_HALF   | 2      | Half rate. |
V
Vaidegi B 已提交
588

589
## InterruptType
V
Vaidegi B 已提交
590

W
wusongqing 已提交
591
Enumerates the audio interruption types.
V
Vaidegi B 已提交
592

W
wusongqing 已提交
593
**System capability**: SystemCapability.Multimedia.Audio.Renderer
594

595
| Name                |  Value    | Description                  |
W
wusongqing 已提交
596 597 598
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
599 600

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

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

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

606
| Name           |  Value   | Description                                |
W
wusongqing 已提交
607 608 609
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
610 611

## InterruptHint
V
Vaidegi B 已提交
612

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

W
wusongqing 已提交
615
**System capability**: SystemCapability.Multimedia.Audio.Renderer
616

617
| Name                              |  Value    | Description                                        |
W
wusongqing 已提交
618 619 620 621 622 623 624
| ---------------------------------- | ------ | -------------------------------------------- |
| 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.                              |
625 626

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

628
Describes audio stream information.
V
Vaidegi B 已提交
629

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

632 633 634 635 636 637
| 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.    |
638 639

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
640 641 642

Describes audio renderer information.

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

645
| Name         | Type                       | Mandatory | Description            |
W
wusongqing 已提交
646 647 648 649
| ------------- | --------------------------- | ---- | ---------------- |
| content       | [ContentType](#contenttype) | Yes  | Audio content type.      |
| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
| rendererFlags | number                      | Yes  | Audio renderer flags.|
V
Vaidegi B 已提交
650

651 652 653 654 655 656 657 658 659 660 661 662 663
## 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.|

664
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
665

W
wusongqing 已提交
666
Describes audio renderer configurations.
667

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

670
| Name        | Type                                    | Mandatory | Description            |
W
wusongqing 已提交
671 672 673
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
674

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

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

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

681
| Name     | Type                                      |Mandatory  | Description                                |
W
wusongqing 已提交
682 683 684 685
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
| 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 已提交
686

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

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

G
Gloria 已提交
691
**System API**: This is a system API.
692

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

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

703 704 705 706 707 708 709
## 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                                                    |
710
| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- |
711 712
| mute | boolean | Yes  | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.         |

G
Gloria 已提交
713 714 715 716
## ConnectType<sup>9+</sup>

Enumerates the types of connected devices.

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

719
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
720

721
| Name                           |  Value    | Description                  |
G
Gloria 已提交
722 723 724 725
| :------------------------------ | :----- | :--------------------- |
| CONNECT_TYPE_LOCAL              | 1      | Local device.        |
| CONNECT_TYPE_DISTRIBUTED        | 2      | Distributed device.           |

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

W
wusongqing 已提交
750
## DeviceChangeAction
751

W
wusongqing 已提交
752
Describes the device connection status and device information.
753

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

W
wusongqing 已提交
756 757
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
758
| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
W
wusongqing 已提交
759
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
V
Vaidegi B 已提交
760

W
wusongqing 已提交
761
## DeviceChangeType
762

W
wusongqing 已提交
763
Enumerates the device connection statuses.
V
Vaidegi B 已提交
764

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

767
| Name      |  Value    | Description          |
W
wusongqing 已提交
768 769 770
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
771

W
wusongqing 已提交
772
## AudioCapturerOptions<sup>8+</sup>
773

W
wusongqing 已提交
774
Describes audio capturer configurations.
775

W
wusongqing 已提交
776
**System capability**: SystemCapability.Multimedia.Audio.Capturer
777

W
wusongqing 已提交
778 779 780 781
| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|
782

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

W
wusongqing 已提交
785
Describes audio capturer information.
786

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

W
wusongqing 已提交
789 790 791 792
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
793 794

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

W
wusongqing 已提交
796
Enumerates the audio source types.
797

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

800
| Name                                        |  Value    | Description                  |
801 802 803 804 805
| :------------------------------------------- | :----- | :--------------------- |
| 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.|
806 807

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

W
wusongqing 已提交
809
Enumerates the audio scenes.
810

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

813
| Name                  |  Value    | Description                                         |
W
wusongqing 已提交
814 815
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
816 817
| 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 已提交
818
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
819

820
## AudioManager
W
wusongqing 已提交
821

W
wusongqing 已提交
822
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 已提交
823

824 825 826
### setAudioParameter

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

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

830
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 已提交
831

832 833 834
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

**System capability**: SystemCapability.Multimedia.Audio.Core
G
Gloria 已提交
835 836 837

**Parameters**

838 839 840 841 842
| 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 已提交
843 844

**Example**
845

G
Gloria 已提交
846
```js
847
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
G
Gloria 已提交
848
  if (err) {
849 850
    console.error(`Failed to set the audio parameter. ${err}`);
    return;
G
Gloria 已提交
851
  }
852
  console.info('Callback invoked to indicate a successful setting of the audio parameter.');
G
Gloria 已提交
853 854 855
});
```

856
### setAudioParameter
G
Gloria 已提交
857

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

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

862 863 864 865 866 867 868 869 870 871 872 873
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 已提交
874 875 876

**Return value**

877 878 879
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
880 881

**Example**
882

G
Gloria 已提交
883
```js
884 885 886
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
  console.info('Promise returned to indicate a successful setting of the audio parameter.');
});
G
Gloria 已提交
887 888
```

889
### getAudioParameter
890

891
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
892

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

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

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

W
wusongqing 已提交
899
**Parameters**
900

901 902 903 904
| 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.|
905

W
wusongqing 已提交
906
**Example**
W
wusongqing 已提交
907

G
Gloria 已提交
908
```js
909
audioManager.getAudioParameter('key_example', (err, value) => {
910
  if (err) {
911
    console.error(`Failed to obtain the value of the audio parameter. ${err}`);
912 913
    return;
  }
914
  console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
915
});
W
wusongqing 已提交
916
```
W
wusongqing 已提交
917

918
### getAudioParameter
919

920
getAudioParameter(key: string): Promise&lt;string&gt;
921

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

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

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

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

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

W
wusongqing 已提交
934
**Return value**
935

936 937 938
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
939

W
wusongqing 已提交
940
**Example**
W
wusongqing 已提交
941

G
Gloria 已提交
942
```js
943 944
audioManager.getAudioParameter('key_example').then((value) => {
  console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
945 946 947
});
```

948
### setAudioScene<sup>8+</sup>
W
wusongqing 已提交
949

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

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

954 955 956
**System API**: This is a system API.

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

W
wusongqing 已提交
958
**Parameters**
959

960 961 962 963
| 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.|
964

W
wusongqing 已提交
965
**Example**
W
wusongqing 已提交
966

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

977
### setAudioScene<sup>8+</sup>
V
Vaidegi B 已提交
978

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

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

983 984 985
**System API**: This is a system API.

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

W
wusongqing 已提交
987
**Parameters**
W
wusongqing 已提交
988

989 990 991
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
W
wusongqing 已提交
992

W
wusongqing 已提交
993
**Return value**
994

995 996 997
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
W
wusongqing 已提交
998

W
wusongqing 已提交
999
**Example**
W
wusongqing 已提交
1000

G
Gloria 已提交
1001
```js
1002 1003 1004 1005
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}`);
1006 1007 1008
});
```

1009
### getAudioScene<sup>8+</sup>
1010

1011
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1012

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

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

W
wusongqing 已提交
1017
**Parameters**
W
wusongqing 已提交
1018

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

**Example**
W
wusongqing 已提交
1024

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

1035
### getAudioScene<sup>8+</sup>
W
wusongqing 已提交
1036

1037
getAudioScene\(\): Promise<AudioScene\>
W
wusongqing 已提交
1038

1039
Obtains the audio scene. This API uses a promise to return the result.
1040

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

W
wusongqing 已提交
1043
**Return value**
W
wusongqing 已提交
1044

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

W
wusongqing 已提交
1049
**Example**
1050

G
Gloria 已提交
1051
```js
1052 1053 1054 1055
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}`);
1056 1057 1058
});
```

1059
### getVolumeManager<sup>9+</sup>
1060

1061
getVolumeManager(): AudioVolumeManager
1062

1063
Obtains an **AudioVolumeManager** instance.
1064

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

W
wusongqing 已提交
1067
**Example**
W
wusongqing 已提交
1068

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

1073
### getStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1074

1075
getStreamManager(): AudioStreamManager
W
wusongqing 已提交
1076

1077
Obtains an **AudioStreamManager** instance.
W
wusongqing 已提交
1078

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

1081
**Example**
W
wusongqing 已提交
1082

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

1087
### getRoutingManager<sup>9+</sup>
1088

1089 1090 1091 1092 1093
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

W
wusongqing 已提交
1095
**Example**
W
wusongqing 已提交
1096

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

1101
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1102

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

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

1107 1108 1109 1110
> **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 已提交
1111 1112
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1117
**Parameters**
W
wusongqing 已提交
1118

1119 1120 1121 1122 1123
| 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.                                  |
1124

W
wusongqing 已提交
1125
**Example**
W
wusongqing 已提交
1126

G
Gloria 已提交
1127
```js
1128
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
1129
  if (err) {
1130
    console.error(`Failed to set the volume. ${err}`);
1131 1132
    return;
  }
1133
  console.info('Callback invoked to indicate a successful volume setting.');
1134
});
W
wusongqing 已提交
1135 1136
```

1137
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1138

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

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

1143 1144 1145 1146
> **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 已提交
1147 1148
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

1155 1156 1157 1158
| 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**.|
1159

W
wusongqing 已提交
1160
**Return value**
1161

1162 1163
| Type               | Description                         |
| ------------------- | ----------------------------- |
W
wusongqing 已提交
1164
| Promise&lt;void&gt; | Promise used to return the result.|
1165

W
wusongqing 已提交
1166
**Example**
W
wusongqing 已提交
1167

G
Gloria 已提交
1168
```js
1169
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
1170
  console.info('Promise returned to indicate a successful volume setting.');
1171
});
W
wusongqing 已提交
1172 1173
```

1174
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1175

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

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

1180 1181 1182 1183
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1186
**Parameters**
W
wusongqing 已提交
1187

1188 1189 1190 1191 1192 1193
| 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 已提交
1194

G
Gloria 已提交
1195
```js
1196
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1197
  if (err) {
1198
    console.error(`Failed to obtain the volume. ${err}`);
1199 1200
    return;
  }
1201
  console.info('Callback invoked to indicate that the volume is obtained.');
1202
});
W
wusongqing 已提交
1203 1204
```

1205
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1206

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

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

1211 1212 1213 1214
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**.

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

1217 1218 1219 1220 1221
**Parameters**

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

W
wusongqing 已提交
1223
**Return value**
W
wusongqing 已提交
1224

1225 1226 1227
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
1228

W
wusongqing 已提交
1229
**Example**
W
wusongqing 已提交
1230

G
Gloria 已提交
1231
```js
1232 1233
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
1234
});
W
wusongqing 已提交
1235 1236
```

1237
### getMinVolume<sup>(deprecated)</sup>
1238

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

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

1243 1244 1245 1246
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1249
**Parameters**
W
wusongqing 已提交
1250

1251 1252 1253 1254
| 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 已提交
1255

W
wusongqing 已提交
1256
**Example**
W
wusongqing 已提交
1257

G
Gloria 已提交
1258
```js
1259
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1260
  if (err) {
1261
    console.error(`Failed to obtain the minimum volume. ${err}`);
1262 1263
    return;
  }
1264
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
1265
});
W
wusongqing 已提交
1266 1267
```

1268
### getMinVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1269

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

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

1274 1275 1276 1277
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**.

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

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

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

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

1288 1289 1290
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
1291

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

G
Gloria 已提交
1294
```js
1295 1296
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
1297
});
W
wusongqing 已提交
1298 1299
```

1300
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1301

1302
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1303

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

1306 1307 1308 1309
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1312
**Parameters**
W
wusongqing 已提交
1313

1314 1315 1316 1317
| 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 已提交
1318

W
wusongqing 已提交
1319
**Example**
W
wusongqing 已提交
1320

G
Gloria 已提交
1321
```js
1322
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
1323
  if (err) {
1324
    console.error(`Failed to obtain the maximum volume. ${err}`);
1325 1326
    return;
  }
1327
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
1328
});
W
wusongqing 已提交
1329 1330
```

1331
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1332

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

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

1337 1338 1339 1340
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1343
**Parameters**
1344

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

W
wusongqing 已提交
1349
**Return value**
W
wusongqing 已提交
1350

1351 1352 1353
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
1354

W
wusongqing 已提交
1355
**Example**
W
wusongqing 已提交
1356

G
Gloria 已提交
1357
```js
1358
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
1359
  console.info('Promised returned to indicate that the maximum volume is obtained.');
1360
});
W
wusongqing 已提交
1361 1362
```

1363
### mute<sup>(deprecated)</sup>
1364

1365
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1366

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

1369 1370 1371
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.
1372 1373

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

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

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

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

G
Gloria 已提交
1385
```js
1386
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
1387
  if (err) {
1388
    console.error(`Failed to mute the stream. ${err}`);
1389 1390
    return;
  }
1391
  console.info('Callback invoked to indicate that the stream is muted.');
1392
});
W
wusongqing 已提交
1393 1394
```

1395
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1396

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

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

1401 1402 1403
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**.
1404 1405

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

W
wusongqing 已提交
1407
**Parameters**
W
wusongqing 已提交
1408

1409 1410 1411 1412
| 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 已提交
1413

W
wusongqing 已提交
1414
**Return value**
1415

1416 1417 1418
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1419

W
wusongqing 已提交
1420
**Example**
W
wusongqing 已提交
1421

1422

G
Gloria 已提交
1423
```js
1424
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
1425
  console.info('Promise returned to indicate that the stream is muted.');
1426
});
W
wusongqing 已提交
1427 1428
```

1429
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1430

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

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

1435 1436 1437 1438
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1441
**Parameters**
W
wusongqing 已提交
1442

1443 1444 1445 1446
| 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.|
1447

W
wusongqing 已提交
1448
**Example**
W
wusongqing 已提交
1449

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

1460
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1461

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

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

1466 1467 1468 1469
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**.

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

W
wusongqing 已提交
1472
**Parameters**
1473

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

W
wusongqing 已提交
1478
**Return value**
1479

1480 1481 1482
| 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.|
1483

W
wusongqing 已提交
1484
**Example**
1485

G
Gloria 已提交
1486
```js
1487
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
1488
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1489
});
W
wusongqing 已提交
1490 1491
```

1492 1493 1494 1495 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
### 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 已提交
1556

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

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

1561 1562 1563 1564
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.

1565 1566 1567 1568
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

1573 1574 1575 1576
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1577

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

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

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

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

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

1596 1597 1598 1599
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**.

1600
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
W
wusongqing 已提交
1601

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

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

W
wusongqing 已提交
1606
**Parameters**
1607

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

W
wusongqing 已提交
1612
**Return value**
1613

1614 1615 1616
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1617

W
wusongqing 已提交
1618
**Example**
W
wusongqing 已提交
1619

G
Gloria 已提交
1620
```js
1621
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
1622 1623 1624 1625
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```

1626
### getRingerMode<sup>(deprecated)</sup>
1627 1628 1629 1630 1631

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

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

1632 1633 1634 1635 1636
> **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
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646

**Parameters**

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

**Example**

```js
1647
audioManager.getRingerMode((err, value) => {
1648 1649 1650 1651 1652 1653 1654 1655
  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}.`);
});
```

1656
### getRingerMode<sup>(deprecated)</sup>
1657 1658 1659 1660 1661

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

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

1662 1663 1664 1665 1666
> **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
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676

**Return value**

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

**Example**

```js
1677
audioManager.getRingerMode().then((value) => {
1678
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
1679
});
W
wusongqing 已提交
1680 1681
```

1682
### getDevices<sup>(deprecated)</sup>
1683

1684
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1685

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

1688 1689 1690 1691 1692
> **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
1693 1694 1695

**Parameters**

1696 1697 1698 1699
| 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.|
1700

1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
**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.');
});
```
1711

1712
### getDevices<sup>(deprecated)</sup>
1713

1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
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.|
1735 1736 1737 1738

**Example**

```js
1739 1740
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
1741 1742
});
```
V
Vaidegi B 已提交
1743

1744
### setDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1745

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

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

1750 1751 1752 1753 1754
> **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 已提交
1755

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

1758 1759 1760 1761 1762
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Audio device type.      |
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
W
wusongqing 已提交
1763

W
wusongqing 已提交
1764
**Example**
W
wusongqing 已提交
1765

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

1776
### setDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1777

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

1780
Sets a device to the active state. This API uses a promise to return the result.
1781

1782 1783 1784
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.
1785

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

W
wusongqing 已提交
1788
**Parameters**
1789

1790 1791 1792 1793
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Audio device type.|
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
1794

W
wusongqing 已提交
1795
**Return value**
W
wusongqing 已提交
1796

W
wusongqing 已提交
1797 1798 1799
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1800

W
wusongqing 已提交
1801
**Example**
W
wusongqing 已提交
1802

1803

G
Gloria 已提交
1804
```js
1805 1806
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
1807
});
W
wusongqing 已提交
1808 1809
```

1810
### isDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1811

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

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

1816 1817 1818 1819 1820
> **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 已提交
1821

W
wusongqing 已提交
1822
**Parameters**
W
wusongqing 已提交
1823

1824 1825 1826 1827
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Audio device type.      |
| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the active state of the device.|
W
wusongqing 已提交
1828

W
wusongqing 已提交
1829
**Example**
W
wusongqing 已提交
1830

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

1841
### isDeviceActive<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1842

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

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

1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857
> **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              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Audio device type.|
W
wusongqing 已提交
1858

W
wusongqing 已提交
1859
**Return value**
1860

1861 1862 1863
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
W
wusongqing 已提交
1864

W
wusongqing 已提交
1865
**Example**
W
wusongqing 已提交
1866

G
Gloria 已提交
1867
```js
1868 1869
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
1870
});
W
wusongqing 已提交
1871 1872
```

1873
### setMicrophoneMute<sup>(deprecated)</sup>
W
wusongqing 已提交
1874

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

1877
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
1878

1879 1880 1881
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**.
1882

1883 1884 1885
**Required permissions**: ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1887
**Parameters**
V
Vaidegi B 已提交
1888

1889 1890 1891 1892
| 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.                     |
1893

1894
**Example**
1895

1896 1897 1898 1899 1900 1901 1902 1903 1904
```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.');
});
```
1905

1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
### 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 已提交
1931

W
wusongqing 已提交
1932
**Example**
V
Vaidegi B 已提交
1933

G
Gloria 已提交
1934
```js
1935 1936
audioManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
1937
});
V
Vaidegi B 已提交
1938 1939
```

1940
### isMicrophoneMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1941

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

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

1946 1947 1948
> **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 已提交
1949

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

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

W
wusongqing 已提交
1954
**Parameters**
V
Vaidegi B 已提交
1955

1956 1957 1958
| 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 已提交
1959

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

G
Gloria 已提交
1962
```js
1963
audioManager.isMicrophoneMute((err, value) => {
1964
  if (err) {
1965 1966
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
    return;
1967
  }
1968
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
1969
});
V
Vaidegi B 已提交
1970 1971
```

1972
### isMicrophoneMute<sup>(deprecated)</sup>
1973

1974
isMicrophoneMute(): Promise&lt;boolean&gt;
1975

1976
Checks whether the microphone is muted. This API uses a promise to return the result.
1977

1978 1979 1980 1981 1982 1983 1984
> **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
1985

1986
**Return value**
1987

1988 1989 1990
| 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.|
1991

W
wusongqing 已提交
1992
**Example**
1993

G
Gloria 已提交
1994
```js
1995 1996 1997
audioManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
});
1998 1999
```

2000
### on('volumeChange')<sup>(deprecated)</sup>
2001

2002
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2003

2004 2005 2006
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioVolumeManager**.
2007

2008 2009 2010 2011 2012 2013 2014
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
2015

W
wusongqing 已提交
2016
**Parameters**
2017

2018 2019 2020 2021
| 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.                                                  |
2022

W
wusongqing 已提交
2023
**Example**
2024

G
Gloria 已提交
2025
```js
2026 2027 2028 2029
audioManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2030 2031 2032
});
```

2033
### on('ringerModeChange')<sup>(deprecated)</sup>
2034

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

2037
Subscribes to ringer mode change events.
2038

2039 2040 2041
> **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**.
2042

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

2045 2046 2047 2048 2049 2050 2051 2052
**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.                                                  |
2053 2054

**Example**
2055

G
Gloria 已提交
2056
```js
2057 2058 2059
audioManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
2060 2061
```

2062
### on('deviceChange')<sup>(deprecated)</sup>
2063

2064
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
2065

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

2068 2069 2070
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioRoutingManager**.
2071

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

2074
**Parameters**
2075

2076 2077 2078 2079
| 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.                        |
2080

W
wusongqing 已提交
2081
**Example**
2082

G
Gloria 已提交
2083
```js
2084 2085 2086 2087 2088
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} `);
2089 2090 2091
});
```

2092
### off('deviceChange')<sup>(deprecated)</sup>
2093

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

2096
Unsubscribes from device change events.
2097

2098 2099 2100
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off](#off9) in **AudioRoutingManager**.
2101

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

2104
**Parameters**
2105

2106 2107 2108 2109
| 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.                        |
2110 2111 2112 2113

**Example**

```js
2114 2115 2116
audioManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
});
2117 2118
```

2119
### on('interrupt')<sup>(deprecated)</sup>
2120

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

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

2125 2126 2127 2128 2129 2130 2131
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
2132

W
wusongqing 已提交
2133
**Parameters**
2134

2135 2136 2137 2138 2139
| 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.                                      |
2140

W
wusongqing 已提交
2141
**Example**
2142

G
Gloria 已提交
2143
```js
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156
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} `);
2157
  }
2158
});
2159 2160
```

2161
### off('interrupt')<sup>(deprecated)</sup>
2162

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

2165
Unsubscribes from audio interruption events.
2166

2167 2168 2169 2170 2171
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

W
wusongqing 已提交
2173
**Parameters**
2174

2175 2176 2177 2178 2179
| 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.                                      |
2180

W
wusongqing 已提交
2181
**Example**
2182

G
Gloria 已提交
2183
```js
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
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} `);
  }
});
2195 2196
```

2197
## AudioVolumeManager<sup>9+</sup>
2198

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

2201
### getVolumeGroupInfos<sup>9+</sup>
2202

2203 2204 2205 2206 2207 2208 2209
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
2210

W
wusongqing 已提交
2211
**Parameters**
2212

2213 2214 2215 2216
| 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.|
2217

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

2229
### getVolumeGroupInfos<sup>9+</sup>
2230

2231
getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2232

2233
Obtains the volume groups. This API uses a promise to return the result.
2234

2235 2236 2237
**System API**: This is a system API.

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

2239 2240
**Parameters**

2241 2242 2243
| Name    | Type              | Mandatory| Description                |
| ---------- | ------------------| ---- | -------------------- |
| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2244

W
wusongqing 已提交
2245
**Return value**
2246

2247 2248 2249
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
2250

W
wusongqing 已提交
2251
**Example**
2252

G
Gloria 已提交
2253
```js
2254 2255 2256 2257 2258
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))
}
```
2259

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

2262
getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2263

2264
Obtains the audio group manager. This API uses an asynchronous callback to return the result.
2265

2266
**System capability**: SystemCapability.Multimedia.Audio.Volume
2267 2268 2269

**Parameters**

G
Gloria 已提交
2270 2271
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2272 2273
| groupId    | number                                    | Yes  | Volume group ID.    |
| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | Yes  | Callback used to return the audio group manager.|
2274 2275

**Example**
2276

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

2287 2288
```

2289
### getVolumeGroupManager<sup>9+</sup>
2290

2291
getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2292

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

2295
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2296 2297 2298

**Parameters**

2299 2300 2301
| Name    | Type                                     | Mandatory| Description             |
| ---------- | ---------------------------------------- | ---- | ---------------- |
| groupId    | number                                   | Yes  | Volume group ID.    |
2302 2303 2304

**Return value**

2305 2306 2307
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the audio group manager.|
2308 2309

**Example**
G
Gloria 已提交
2310 2311

```js
2312 2313 2314 2315 2316 2317 2318 2319
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.');
}

2320 2321
```

2322
### on('volumeChange')<sup>9+</sup>
2323

2324
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2325

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

2328
**System capability**: SystemCapability.Multimedia.Audio.Volume
2329 2330 2331

**Parameters**

2332 2333 2334 2335
| 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 已提交
2336

2337
**Error codes**
2338

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

2341 2342
| ID| Error Message|
| ------- | --------------------------------------------|
2343
| 6800101 | if input parameter value error              |
2344 2345

**Example**
G
Gloria 已提交
2346 2347

```js
2348 2349 2350 2351
audioVolumeManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2352
});
2353
```
2354

2355
## AudioVolumeGroupManager<sup>9+</sup>
2356

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

2359
### setVolume<sup>9+</sup>
2360

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

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

2365
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2366

2367
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
G
Gloria 已提交
2368 2369 2370

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

2371
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2372 2373 2374

**Parameters**

2375 2376 2377 2378 2379
| 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 已提交
2380 2381

**Example**
2382

2383 2384 2385 2386 2387 2388 2389 2390
```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 已提交
2391 2392
```

2393
### setVolume<sup>9+</sup>
G
Gloria 已提交
2394

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

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

2399
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2400

2401 2402 2403 2404 2405
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 已提交
2406 2407 2408

**Parameters**

2409 2410 2411 2412
| 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 已提交
2413 2414 2415

**Return value**

2416 2417 2418
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2419 2420 2421 2422

**Example**

```js
2423 2424 2425
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.info('Promise returned to indicate a successful volume setting.');
});
G
Gloria 已提交
2426 2427
```

2428
### getVolume<sup>9+</sup>
G
Gloria 已提交
2429

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

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

2434
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2435 2436 2437

**Parameters**

2438 2439 2440 2441
| 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 已提交
2442 2443 2444 2445

**Example**

```js
2446
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
2447
  if (err) {
2448
    console.error(`Failed to obtain the volume. ${err}`);
2449
    return;
G
Gloria 已提交
2450
  }
2451
  console.info('Callback invoked to indicate that the volume is obtained.');
2452
});
G
Gloria 已提交
2453 2454
```

2455
### getVolume<sup>9+</sup>
G
Gloria 已提交
2456

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

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

2461
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2462 2463 2464

**Parameters**

2465 2466 2467
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2468 2469 2470

**Return value**

2471 2472 2473
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
G
Gloria 已提交
2474 2475 2476 2477

**Example**

```js
2478 2479
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2480
});
G
Gloria 已提交
2481 2482
```

2483
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2484

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

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

2489
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2490 2491 2492

**Parameters**

2493 2494 2495 2496
| 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 已提交
2497 2498 2499 2500

**Example**

```js
2501
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2502
  if (err) {
2503
    console.error(`Failed to obtain the minimum volume. ${err}`);
G
Gloria 已提交
2504 2505
    return;
  }
2506
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
G
Gloria 已提交
2507 2508 2509
});
```

2510
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2511

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

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

2516
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2517 2518 2519

**Parameters**

2520 2521 2522
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2523 2524 2525

**Return value**

2526 2527 2528
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
G
Gloria 已提交
2529 2530 2531 2532

**Example**

```js
2533 2534
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
G
Gloria 已提交
2535 2536 2537
});
```

2538
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2539

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

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

2544
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2545 2546 2547

**Parameters**

2548 2549 2550 2551
| 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 已提交
2552 2553

**Example**
2554

G
Gloria 已提交
2555
```js
2556 2557 2558 2559 2560 2561 2562
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 已提交
2563 2564
```

2565
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2566

2567
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2568

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

2571
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2572 2573 2574

**Parameters**

2575 2576 2577
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2578 2579 2580

**Return value**

2581 2582 2583
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
G
Gloria 已提交
2584 2585 2586 2587

**Example**

```js
2588 2589 2590
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.info('Promised returned to indicate that the maximum volume is obtained.');
});
2591
```
G
Gloria 已提交
2592

2593
### mute<sup>9+</sup>
2594

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

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

2599
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2600

2601 2602 2603 2604 2605
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 已提交
2606 2607 2608

**Parameters**

2609 2610 2611 2612 2613
| 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 已提交
2614 2615 2616

**Example**

2617 2618 2619 2620 2621 2622 2623 2624
```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.');
});
2625
```
G
Gloria 已提交
2626

2627
### mute<sup>9+</sup>
G
Gloria 已提交
2628

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

2631
Mutes or unmutes a stream. This API uses a promise to return the result.
2632

2633
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2634

2635 2636 2637 2638 2639
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 已提交
2640 2641 2642

**Parameters**

2643 2644 2645 2646
| 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 已提交
2647 2648 2649

**Return value**

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

**Example**

```js
2657 2658 2659
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.info('Promise returned to indicate that the stream is muted.');
});
G
Gloria 已提交
2660 2661
```

2662
### isMute<sup>9+</sup>
G
Gloria 已提交
2663

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

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

2668
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2669

2670
**Parameters**
G
Gloria 已提交
2671

2672 2673 2674 2675
| 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 已提交
2676 2677 2678 2679

**Example**

```js
2680
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2681
  if (err) {
2682 2683
    console.error(`Failed to obtain the mute status. ${err}`);
    return;
G
Gloria 已提交
2684
  }
2685
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
G
Gloria 已提交
2686
});
2687
```
G
Gloria 已提交
2688

2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713
### 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}.`);
2714 2715
});
```
G
Gloria 已提交
2716

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

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

2721
Sets the ringer mode. This API uses an asynchronous callback to return the result.
2722

2723
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2724

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

2727
**System API**: This is a system API.
G
Gloria 已提交
2728

2729
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2730

2731 2732 2733 2734 2735 2736
**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 已提交
2737 2738 2739 2740

**Example**

```js
2741
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
2742
  if (err) {
2743 2744
    console.error(`Failed to set the ringer mode.​ ${err}`);
    return;
2745
  }
2746
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
2747 2748
});
```
G
Gloria 已提交
2749

2750
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2751

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

2754
Sets the ringer mode. This API uses a promise to return the result.
2755

2756
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2757

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

2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
**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 已提交
2775 2776 2777 2778

**Example**

```js
2779 2780 2781 2782
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```
2783

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

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

2810 2811 2812 2813 2814
### getRingerMode<sup>9+</sup>

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

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

2816
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2817

2818
**Return value**
2819

2820 2821 2822
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
G
Gloria 已提交
2823

2824
**Example**
G
Gloria 已提交
2825

2826
```js
2827 2828 2829
audioVolumeGroupManager.getRingerMode().then((value) => {
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
});
2830
```
G
Gloria 已提交
2831

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

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

2836
Subscribes to ringer mode change events.
2837

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

2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
**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 已提交
2854 2855 2856 2857

**Example**

```js
2858 2859 2860
audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
G
Gloria 已提交
2861
```
2862
### setMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2863

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

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

2868
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
2869

2870
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2871 2872 2873

**Parameters**

2874 2875 2876 2877
| 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 已提交
2878 2879 2880 2881

**Example**

```js
2882 2883 2884 2885 2886 2887
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 已提交
2888 2889 2890
});
```

2891
### setMicrophoneMute<sup>9+</sup>
2892

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

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

2897 2898 2899 2900 2901 2902 2903 2904 2905
**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 已提交
2906 2907 2908

**Return value**

2909 2910 2911
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2912 2913 2914 2915

**Example**

```js
2916 2917
audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
G
Gloria 已提交
2918 2919 2920
});
```

2921
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2922

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

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

2927
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2928 2929 2930

**Parameters**

2931 2932 2933
| 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 已提交
2934 2935 2936 2937

**Example**

```js
2938 2939 2940 2941 2942 2943
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 已提交
2944 2945 2946
});
```

2947
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2948

2949
isMicrophoneMute(): Promise&lt;boolean&gt;
G
Gloria 已提交
2950

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

2953
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2954 2955 2956

**Return value**

2957 2958 2959
| 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 已提交
2960 2961 2962 2963

**Example**

```js
2964 2965
audioVolumeGroupManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2966
});
2967 2968 2969
```

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

2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999
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 已提交
3000 3001
```

3002
## AudioStreamManager<sup>9+</sup>
G
Gloria 已提交
3003

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

3006 3007 3008 3009 3010
### 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 已提交
3011 3012 3013 3014 3015

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

**Parameters**

3016 3017 3018
| Name    | Type                                | Mandatory    | Description                        |
| -------- | ----------------------------------- | -------- | --------------------------- |
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes    |  Callback used to return the audio renderer information.|
G
Gloria 已提交
3019 3020 3021 3022

**Example**

```js
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049
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 已提交
3050 3051 3052
});
```

3053
### getCurrentAudioRendererInfoArray<sup>9+</sup>
G
Gloria 已提交
3054

3055
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
G
Gloria 已提交
3056

3057
Obtains the information about the current audio renderer. This API uses a promise to return the result.
G
Gloria 已提交
3058 3059 3060 3061 3062

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

**Return value**

3063 3064 3065
| Type                                                                             | Description                                   |
| ---------------------------------------------------------------------------------| --------------------------------------- |
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise used to return the audio renderer information.     |
G
Gloria 已提交
3066 3067 3068 3069

**Example**

```js
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097
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}`);
  });
}
3098
```
G
Gloria 已提交
3099

3100
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3101

3102
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3103

3104
Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3105 3106 3107 3108 3109

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

**Parameters**

3110 3111 3112
| Name       | Type                                | Mandatory     | Description                                                     |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes   | Callback used to return the audio capturer information.|
G
Gloria 已提交
3113 3114 3115 3116

**Example**

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

3145
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
G
Gloria 已提交
3146

3147
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
G
Gloria 已提交
3148

3149
Obtains the information about the current audio capturer. This API uses a promise to return the result.
G
Gloria 已提交
3150 3151 3152

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

3153
**Return value**
G
Gloria 已提交
3154

3155 3156 3157
| Type                                                                        | Description                                |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise used to return the audio capturer information. |
G
Gloria 已提交
3158 3159 3160 3161

**Example**

```js
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187
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 已提交
3188 3189
```

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

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

3194
Subscribes to audio renderer change events.
G
Gloria 已提交
3195

3196
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3197 3198 3199

**Parameters**

3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
| 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 已提交
3212 3213 3214 3215

**Example**

```js
3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235
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 已提交
3236 3237 3238 3239
  }
});
```

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

3242
off(type: "audioRendererChange"): void
G
Gloria 已提交
3243

3244
Unsubscribes from audio renderer change events.
G
Gloria 已提交
3245

3246
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3247

3248
**Parameters**
G
Gloria 已提交
3249

3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260
| 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 已提交
3261 3262 3263 3264

**Example**

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

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

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

3273
Subscribes to audio capturer change events.
G
Gloria 已提交
3274

3275
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3276 3277 3278

**Parameters**

3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290
| 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              |
3291 3292

**Example**
G
Gloria 已提交
3293 3294

```js
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313
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 已提交
3314
  }
3315 3316
});
```
G
Gloria 已提交
3317

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

3320
off(type: "audioCapturerChange"): void;
G
Gloria 已提交
3321

3322
Unsubscribes from audio capturer change events.
G
Gloria 已提交
3323

3324
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
3325

3326
**Parameters**
G
Gloria 已提交
3327

3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338
| 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 已提交
3339 3340 3341 3342

**Example**

```js
3343 3344
audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########');
3345

3346 3347
```

3348
### isActive<sup>9+</sup>
3349

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

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

3354
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3355 3356 3357

**Parameters**

3358 3359 3360 3361
| 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.|
3362 3363

**Example**
G
Gloria 已提交
3364 3365

```js
3366
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
3367
  if (err) {
3368 3369
    console.error(`Failed to obtain the active status of the stream. ${err}`);
    return;
G
Gloria 已提交
3370
  }
3371
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
G
Gloria 已提交
3372
});
3373 3374
```

3375
### isActive<sup>9+</sup>
3376

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

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

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

3383 3384 3385 3386 3387 3388
**Parameters**

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

3389
**Return value**
G
Gloria 已提交
3390

3391 3392 3393
| 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.|
3394 3395

**Example**
G
Gloria 已提交
3396 3397

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

3403
## AudioRoutingManager<sup>9+</sup>
3404

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

3407
### getDevices<sup>9+</sup>
3408

3409 3410 3411 3412 3413
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
3414 3415 3416

**Parameters**

3417 3418 3419 3420
| 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.|
3421 3422 3423

**Example**

3424
```js
3425
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
3426
  if (err) {
3427 3428
    console.error(`Failed to obtain the device list. ${err}`);
    return;
3429
  }
3430
  console.info('Callback invoked to indicate that the device list is obtained.');
3431 3432
});
```
3433

3434
### getDevices<sup>9+</sup>
3435

3436
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
3437

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

3440 3441 3442 3443 3444 3445 3446
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

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

**Return value**

3450 3451 3452
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
3453 3454 3455 3456

**Example**

```js
3457 3458
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
3459
});
3460 3461
```

3462
### on<sup>9+</sup>
3463

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

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

3468
**System capability**: SystemCapability.Multimedia.Audio.Device
3469 3470 3471

**Parameters**

3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484
| 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              |
3485 3486

**Example**
3487

3488
```js
3489 3490 3491 3492 3493
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);
3494 3495
});
```
3496

3497
### off<sup>9+</sup>
3498

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

3501
Unsubscribes from device change events.
3502

3503
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3504

3505
**Parameters**
G
Gloria 已提交
3506

3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518
| 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              |
3519 3520 3521

**Example**

G
Gloria 已提交
3522
```js
3523 3524
audioRoutingManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
3525 3526
});
```
G
Gloria 已提交
3527

3528
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3529

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

3532
Selects an audio input device. Only one input device can be selected. This API uses an asynchronous callback to return the result.
3533

3534 3535 3536
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3537 3538 3539

**Parameters**

3540 3541 3542 3543
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
3544 3545 3546

**Example**
```js
3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559
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,
}];
3560

3561 3562 3563 3564 3565 3566 3567 3568
async function selectInputDevice(){
  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select input devices result callback: SUCCESS'); }
  });
}
3569 3570
```

3571
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3572

3573
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3574

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

3577 3578 3579 3580 3581 3582 3583 3584 3585
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.              |
3586 3587 3588

**Return value**

3589 3590 3591
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3592 3593 3594

**Example**

G
Gloria 已提交
3595
```js
3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608
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,
}];
3609

3610 3611 3612 3613 3614 3615 3616
async function getRoutingManager(){
    audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
      console.info('Select input devices result promise: SUCCESS');
    }).catch((err) => {
      console.error(`Result ERROR: ${err}`);
    });
}
3617 3618
```

3619
### setCommunicationDevice<sup>9+</sup>
3620

3621
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
3622

3623
Sets a communication device to the active state. This API uses an asynchronous callback to return the result.
3624

3625
**System capability**: SystemCapability.Multimedia.Audio.Communication
3626

3627
**Parameters**
3628

3629 3630 3631 3632 3633
| 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.|
3634 3635 3636

**Example**

G
Gloria 已提交
3637
```js
3638
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => {
3639
  if (err) {
3640 3641
    console.error(`Failed to set the active status of the device. ${err}`);
    return;
3642
  }
3643
  console.info('Callback invoked to indicate that the device is set to the active status.');
3644
});
3645 3646
```

3647
### setCommunicationDevice<sup>9+</sup>
3648

3649
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
3650

3651
Sets a communication device to the active state. This API uses a promise to return the result.
3652

3653 3654 3655 3656 3657 3658 3659 3660
**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.    |
3661 3662 3663

**Return value**

3664 3665 3666
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
3667 3668 3669 3670

**Example**

```js
3671 3672
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
3673 3674 3675
});
```

3676
### isCommunicationDeviceActive<sup>9+</sup>
3677

3678
isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
3679

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

3682
**System capability**: SystemCapability.Multimedia.Audio.Communication
3683 3684 3685

**Parameters**

3686 3687 3688 3689
| 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.|
3690 3691 3692 3693

**Example**

```js
3694
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => {
3695
  if (err) {
3696 3697
    console.error(`Failed to obtain the active status of the device. ${err}`);
    return;
3698
  }
3699
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
3700 3701 3702
});
```

3703
### isCommunicationDeviceActive<sup>9+</sup>
3704

3705
isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
3706

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

3709
**System capability**: SystemCapability.Multimedia.Audio.Communication
3710 3711 3712

**Parameters**

3713 3714 3715
| Name    | Type                                                 | Mandatory| Description              |
| ---------- | ---------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.|
3716 3717 3718

**Return value**

3719 3720 3721
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
3722 3723 3724 3725

**Example**

```js
3726 3727
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
3728 3729 3730
});
```

3731
### selectOutputDevice<sup>9+</sup>
3732

3733
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3734

3735
Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.
3736

3737 3738 3739
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
3740 3741 3742

**Parameters**

3743 3744 3745 3746
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
3747 3748 3749

**Example**
```js
3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762
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,
}];
3763

3764 3765 3766 3767 3768 3769 3770 3771
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices result callback: SUCCESS'); }
  });
}
3772 3773
```

3774
### selectOutputDevice<sup>9+</sup>
3775

3776
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3777

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

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

3782
**System capability**: SystemCapability.Multimedia.Audio.Device
3783 3784 3785

**Parameters**

3786 3787 3788
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3789 3790 3791

**Return value**

3792 3793 3794
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3795 3796 3797 3798

**Example**

```js
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811
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,
}];
3812

3813 3814 3815 3816 3817 3818 3819
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  });
}
3820 3821
```

3822
### selectOutputDeviceByFilter<sup>9+</sup>
3823

3824
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3825

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

3828 3829 3830
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
3831 3832 3833

**Parameters**

3834 3835 3836 3837 3838
| 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.|
3839 3840 3841

**Example**
```js
3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862
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,
}];
3863

3864 3865 3866 3867 3868 3869 3870 3871
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'); }
  });
}
3872 3873
```

3874
### selectOutputDeviceByFilter<sup>9+</sup>
3875

3876
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3877

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

3880 3881 3882
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
3883 3884 3885

**Parameters**

3886 3887 3888 3889
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3890 3891 3892

**Return value**

3893 3894 3895
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3896 3897 3898 3899

**Example**

```js
3900 3901 3902 3903 3904 3905 3906
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3907

3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920
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,
}];
3921

3922 3923 3924 3925 3926 3927 3928 3929
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}`);
  })
}
```
3930

3931
## AudioRendererChangeInfoArray<sup>9+</sup>
3932

3933
Defines an **AudioRenderChangeInfo** array, which is read-only.
3934 3935 3936

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

3937
## AudioRendererChangeInfo<sup>9+</sup>
3938

3939 3940 3941 3942 3943 3944 3945 3946 3947 3948
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.                      |
3949 3950 3951 3952

**Example**

```js
3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982
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}`);
    }
3983 3984 3985 3986 3987
  }
});
```


3988
## AudioCapturerChangeInfoArray<sup>9+</sup>
3989

3990
Defines an **AudioCapturerChangeInfo** array, which is read-only.
3991

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

3994
## AudioCapturerChangeInfo<sup>9+</sup>
3995

3996
Describes the audio capturer change event.
3997

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

4000 4001 4002 4003 4004 4005
| 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.                      |
4006 4007 4008 4009

**Example**

```js
4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033
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}`);
4034
    }
4035 4036 4037
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4038 4039 4040 4041 4042
    }
  }
});
```

4043
## AudioDeviceDescriptors
4044

4045
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
4046

4047
## AudioDeviceDescriptor
4048

4049
Describes an audio device.
4050

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

4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID.                                                   |
| name<sup>9+</sup>             | string                    | Yes      | No       | Device name.                                                 |
| address<sup>9+</sup>          | string                    | Yes      | No       | Device address.                                              |
| sampleRates<sup>9+</sup>      | Array&lt;number&gt;       | Yes      | No       | Supported sampling rates.                                    |
| channelCounts<sup>9+</sup>    | Array&lt;number&gt;       | Yes      | No       | Number of channels supported.                                |
| channelMasks<sup>9+</sup>     | Array&lt;number&gt;       | Yes      | No       | Supported channel masks.                                     |
| networkId<sup>9+</sup>        | string                    | Yes      | No       | ID of the device network.<br>This is a system API.           |
| interruptGroupId<sup>9+</sup> | number                    | Yes      | No       | ID of the interruption group to which the device belongs.<br>This is a system API. |
| volumeGroupId<sup>9+</sup>    | number                    | Yes      | No       | ID of the volume group to which the device belongs.<br>This is a system API. |
4066 4067 4068 4069

**Example**

```js
4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086
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');
4087 4088 4089 4090
  }
});
```

4091
## AudioRendererFilter<sup>9+</sup>
4092

4093
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4094

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

4097 4098 4099 4100 4101
| 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 |
4102

4103
**Example**
4104

4105 4106 4107 4108 4109 4110 4111 4112 4113
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4114

4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125
## 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. |
4126 4127 4128 4129

**Example**

```js
4130
let state = audioRenderer.state;
4131 4132
```

4133
### getRendererInfo<sup>8+</sup>
4134

4135
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4136

4137
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4138 4139 4140 4141 4142

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

**Parameters**

4143 4144 4145
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
4146 4147 4148 4149

**Example**

```js
4150 4151 4152 4153 4154
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}`);
4155 4156 4157
});
```

4158
### getRendererInfo<sup>8+</sup>
4159

4160
getRendererInfo(): Promise<AudioRendererInfo\>
4161

4162
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4163 4164 4165

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

4166
**Return value**
4167

4168 4169 4170
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
4171 4172 4173 4174

**Example**

```js
4175 4176 4177 4178 4179 4180 4181 4182
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}`);
});
4183 4184
```

4185
### getStreamInfo<sup>8+</sup>
4186

4187
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4188

4189
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4190 4191 4192 4193 4194

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

**Parameters**

4195 4196 4197
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
4198 4199 4200 4201

**Example**

```js
4202 4203 4204 4205 4206 4207
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}`);
4208 4209 4210
});
```

4211
### getStreamInfo<sup>8+</sup>
4212

4213
getStreamInfo(): Promise<AudioStreamInfo\>
4214

4215
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
4216

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

4219 4220 4221 4222 4223
**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
4224 4225 4226 4227

**Example**

```js
4228 4229 4230 4231 4232 4233 4234 4235 4236
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}`);
});
4237

4238
```
4239

4240
### getAudioStreamId<sup>9+</sup>
4241

4242
getAudioStreamId(callback: AsyncCallback<number\>): void
4243

4244
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4245

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

4248 4249
**Parameters**

4250 4251 4252
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
4253

4254 4255
**Example**

G
Gloria 已提交
4256
```js
4257 4258
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4259 4260
});

4261 4262
```

4263
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4264

4265
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4266

4267
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4268

4269
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4270 4271

**Return value**
V
Vaidegi B 已提交
4272

4273 4274 4275
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
4276

W
wusongqing 已提交
4277
**Example**
V
Vaidegi B 已提交
4278

G
Gloria 已提交
4279
```js
4280 4281
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4282
}).catch((err) => {
4283
  console.error(`ERROR: ${err}`);
4284
});
V
Vaidegi B 已提交
4285

4286
```
V
Vaidegi B 已提交
4287

4288
### start<sup>8+</sup>
4289

4290
start(callback: AsyncCallback<void\>): void
4291

4292
Starts the renderer. This API uses an asynchronous callback to return the result.
4293

4294
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4295 4296 4297

**Parameters**

4298 4299 4300
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4301 4302 4303 4304

**Example**

```js
4305
audioRenderer.start((err) => {
4306
  if (err) {
4307
    console.error('Renderer start failed.');
4308
  } else {
4309
    console.info('Renderer start success.');
4310
  }
4311
});
4312

V
Vaidegi B 已提交
4313 4314
```

4315
### start<sup>8+</sup>
G
Gloria 已提交
4316

4317
start(): Promise<void\>
G
Gloria 已提交
4318

4319
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
4320

4321
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4322 4323 4324

**Return value**

4325 4326 4327
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
4328 4329 4330 4331

**Example**

```js
4332 4333
audioRenderer.start().then(() => {
  console.info('Renderer started');
4334
}).catch((err) => {
4335
  console.error(`ERROR: ${err}`);
4336 4337 4338 4339
});

```

4340
### pause<sup>8+</sup>
4341

4342
pause(callback: AsyncCallback\<void>): void
4343

4344
Pauses rendering. This API uses an asynchronous callback to return the result.
4345

4346
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4347 4348 4349

**Parameters**

4350 4351 4352
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4353 4354 4355 4356

**Example**

```js
4357 4358 4359 4360 4361 4362
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4363 4364 4365 4366
});

```

4367
### pause<sup>8+</sup>
4368

4369
pause(): Promise\<void>
4370

4371
Pauses rendering. This API uses a promise to return the result.
4372

4373
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4374 4375 4376

**Return value**

4377 4378 4379
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
4380 4381 4382 4383

**Example**

```js
4384 4385
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4386 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 4416
  }
});

G
Gloria 已提交
4417 4418
```

4419
### drain<sup>8+</sup>
V
Vaidegi B 已提交
4420

4421
drain(): Promise\<void>
V
Vaidegi B 已提交
4422

4423
Drains the playback buffer. This API uses a promise to return the result.
4424

4425
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4426 4427 4428 4429

**Return value**

| Type           | Description                        |
4430 4431
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4432

W
wusongqing 已提交
4433
**Example**
V
Vaidegi B 已提交
4434

G
Gloria 已提交
4435
```js
4436 4437
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
4438
}).catch((err) => {
4439
  console.error(`ERROR: ${err}`);
4440 4441
});

V
Vaidegi B 已提交
4442 4443
```

4444
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4445

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

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

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

W
wusongqing 已提交
4452
**Parameters**
V
Vaidegi B 已提交
4453

4454
| Name     | Type                 | Mandatory | Description                         |
4455 4456
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4457

W
wusongqing 已提交
4458
**Example**
V
Vaidegi B 已提交
4459

G
Gloria 已提交
4460
```js
4461
audioRenderer.stop((err) => {
4462
  if (err) {
4463
    console.error('Renderer stop failed');
4464
  } else {
4465
    console.info('Renderer stopped.');
4466
  }
4467
});
4468

V
Vaidegi B 已提交
4469 4470
```

4471
### stop<sup>8+</sup>
4472

4473
stop(): Promise\<void>
V
Vaidegi B 已提交
4474

4475
Stops rendering. This API uses a promise to return the result.
4476

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

W
wusongqing 已提交
4479
**Return value**
V
Vaidegi B 已提交
4480

4481
| Type           | Description                        |
4482 4483
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4484

W
wusongqing 已提交
4485
**Example**
V
Vaidegi B 已提交
4486

G
Gloria 已提交
4487
```js
4488 4489
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4490
}).catch((err) => {
4491
  console.error(`ERROR: ${err}`);
4492
});
4493

4494
```
V
Vaidegi B 已提交
4495

4496
### release<sup>8+</sup>
V
Vaidegi B 已提交
4497

4498
release(callback: AsyncCallback\<void>): void
4499

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

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

W
wusongqing 已提交
4504
**Parameters**
V
Vaidegi B 已提交
4505

4506
| Name     | Type                 | Mandatory | Description                         |
4507 4508
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4509

W
wusongqing 已提交
4510
**Example**
V
Vaidegi B 已提交
4511

G
Gloria 已提交
4512
```js
4513
audioRenderer.release((err) => {
4514
  if (err) {
4515
    console.error('Renderer release failed');
4516
  } else {
4517
    console.info('Renderer released.');
4518
  }
4519
});
4520

V
Vaidegi B 已提交
4521 4522
```

4523
### release<sup>8+</sup>
V
Vaidegi B 已提交
4524

4525
release(): Promise\<void>
V
Vaidegi B 已提交
4526

4527
Releases the renderer. This API uses a promise to return the result.
4528

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

W
wusongqing 已提交
4531
**Return value**
V
Vaidegi B 已提交
4532

4533
| Type           | Description                        |
4534 4535
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4536

W
wusongqing 已提交
4537
**Example**
V
Vaidegi B 已提交
4538

G
Gloria 已提交
4539
```js
4540 4541
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4542
}).catch((err) => {
4543
  console.error(`ERROR: ${err}`);
4544
});
4545

V
Vaidegi B 已提交
4546 4547
```

4548
### write<sup>8+</sup>
V
Vaidegi B 已提交
4549

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

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

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

W
wusongqing 已提交
4556
**Parameters**
V
Vaidegi B 已提交
4557

4558 4559 4560 4561
| 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 已提交
4562

W
wusongqing 已提交
4563
**Example**
V
Vaidegi B 已提交
4564

G
Gloria 已提交
4565
```js
4566
let bufferSize;
4567 4568
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4569 4570
  bufferSize = data;
  }).catch((err) => {
4571
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4572
  });
4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587
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';
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf, (err, writtenbytes) => {
  if (writtenbytes < 0) {
    console.error('write failed.');
  } else {
    console.info(`Actual written bytes: ${writtenbytes}`);
4588
  }
4589
});
4590

V
Vaidegi B 已提交
4591 4592
```

4593
### write<sup>8+</sup>
V
Vaidegi B 已提交
4594

4595
write(buffer: ArrayBuffer): Promise\<number>
4596

4597
Writes the buffer. This API uses a promise to return the result.
4598

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

W
wusongqing 已提交
4601
**Return value**
V
Vaidegi B 已提交
4602

4603 4604 4605
| 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 已提交
4606

W
wusongqing 已提交
4607
**Example**
V
Vaidegi B 已提交
4608

G
Gloria 已提交
4609
```js
4610
let bufferSize;
4611 4612
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4613 4614
  bufferSize = data;
  }).catch((err) => {
4615
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4616
  });
4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632
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';
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf).then((writtenbytes) => {
  if (writtenbytes < 0) {
      console.error('write failed.');
  } else {
      console.info(`Actual written bytes: ${writtenbytes}`);
  }
4633
}).catch((err) => {
4634
    console.error(`ERROR: ${err}`);
4635
});
4636

V
Vaidegi B 已提交
4637 4638
```

4639
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4640

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

4643
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 已提交
4644

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

W
wusongqing 已提交
4647
**Parameters**
V
Vaidegi B 已提交
4648

4649 4650 4651
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
V
Vaidegi B 已提交
4652

W
wusongqing 已提交
4653
**Example**
V
Vaidegi B 已提交
4654

G
Gloria 已提交
4655
```js
4656
audioRenderer.getAudioTime((err, timestamp) => {
4657
  console.info(`Current timestamp: ${timestamp}`);
4658
});
4659

V
Vaidegi B 已提交
4660 4661
```

4662
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4663

4664
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4665

4666
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4667

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

W
wusongqing 已提交
4670
**Return value**
V
Vaidegi B 已提交
4671

4672
| Type             | Description                           |
4673 4674
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4675

W
wusongqing 已提交
4676
**Example**
V
Vaidegi B 已提交
4677

G
Gloria 已提交
4678
```js
4679 4680
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4681
}).catch((err) => {
4682
  console.error(`ERROR: ${err}`);
4683
});
4684

V
Vaidegi B 已提交
4685 4686
```

4687
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4688

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

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

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

W
wusongqing 已提交
4695
**Parameters**
V
Vaidegi B 已提交
4696

4697
| Name     | Type                   | Mandatory | Description                              |
4698 4699
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4700

W
wusongqing 已提交
4701
**Example**
V
Vaidegi B 已提交
4702

G
Gloria 已提交
4703
```js
4704 4705 4706
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4707
  }
4708
});
4709

V
Vaidegi B 已提交
4710 4711
```

4712
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4713

4714
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4715

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

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

W
wusongqing 已提交
4720
**Return value**
V
Vaidegi B 已提交
4721

4722
| Type             | Description                             |
4723 4724
| ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4725

W
wusongqing 已提交
4726
**Example**
V
Vaidegi B 已提交
4727

G
Gloria 已提交
4728
```js
4729
let bufferSize;
4730 4731
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4732
  bufferSize = data;
4733
}).catch((err) => {
4734
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4735
});
4736

V
Vaidegi B 已提交
4737 4738
```

4739
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4740

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

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

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

W
wusongqing 已提交
4747
**Parameters**
V
Vaidegi B 已提交
4748

4749 4750 4751 4752
| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4753

W
wusongqing 已提交
4754
**Example**
V
Vaidegi B 已提交
4755

G
Gloria 已提交
4756
```js
4757 4758 4759 4760 4761
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.');
4762
  }
4763
});
4764

V
Vaidegi B 已提交
4765 4766
```

4767
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4768

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

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

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

W
wusongqing 已提交
4775
**Parameters**
V
Vaidegi B 已提交
4776

4777 4778 4779 4780 4781 4782 4783 4784 4785
| 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 已提交
4786

W
wusongqing 已提交
4787
**Example**
V
Vaidegi B 已提交
4788

G
Gloria 已提交
4789
```js
4790 4791 4792 4793
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4794
});
4795

V
Vaidegi B 已提交
4796 4797
```

4798
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4799

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

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

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

4806
**Parameters**
V
Vaidegi B 已提交
4807

4808 4809 4810
| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
4811

W
wusongqing 已提交
4812
**Example**
V
Vaidegi B 已提交
4813

G
Gloria 已提交
4814
```js
4815 4816 4817
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
4818

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
});
4843

V
Vaidegi B 已提交
4844 4845
```

4846
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
4847

4848
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4849

4850
Sets the audio interruption mode for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4851

4852
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4853

4854
**Parameters**
V
Vaidegi B 已提交
4855

4856 4857 4858
| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
V
Vaidegi B 已提交
4859

4860
**Return value**
4861

4862 4863 4864
| 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 已提交
4865

4866
**Example**
V
Vaidegi B 已提交
4867

4868 4869 4870 4871 4872 4873 4874
```js
let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{
  console.info('setInterruptMode Success!');
}).catch((err) => {
  console.error(`setInterruptMode Fail: ${err}`);
});
V
Vaidegi B 已提交
4875

4876
```
V
Vaidegi B 已提交
4877

4878 4879 4880 4881 4882 4883 4884
### 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 已提交
4885

W
wusongqing 已提交
4886
**Parameters**
V
Vaidegi B 已提交
4887

4888 4889 4890 4891
| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4892

W
wusongqing 已提交
4893
**Example**
V
Vaidegi B 已提交
4894

G
Gloria 已提交
4895
```js
4896 4897 4898 4899
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
4900
  }
4901
  console.info('setInterruptMode Success!');
4902
});
4903

V
Vaidegi B 已提交
4904 4905
```

4906
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4907

4908
setVolume(volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
4909

4910
Sets the volume for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4911

4912
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4913 4914 4915

**Parameters**

4916 4917 4918
| Name   | Type   | Mandatory | Description                                                  |
| ------ | ------ | --------- | ------------------------------------------------------------ |
| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
4919

W
wusongqing 已提交
4920
**Return value**
V
Vaidegi B 已提交
4921

4922 4923 4924
| 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 已提交
4925

W
wusongqing 已提交
4926
**Example**
V
Vaidegi B 已提交
4927

G
Gloria 已提交
4928
```js
4929 4930 4931 4932
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
4933
});
4934

V
Vaidegi B 已提交
4935 4936
```

4937
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4938

4939
setVolume(volume: number, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
4940

4941
Sets the volume for the application. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4942

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

W
wusongqing 已提交
4945
**Parameters**
V
Vaidegi B 已提交
4946

4947 4948 4949 4950
| 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 已提交
4951

W
wusongqing 已提交
4952
**Example**
V
Vaidegi B 已提交
4953

G
Gloria 已提交
4954
```js
4955 4956 4957
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
4958
  }
4959
  console.info('setVolume Success!');
4960
});
4961

V
Vaidegi B 已提交
4962 4963
```

4964
### on('audioInterrupt')<sup>9+</sup>
V
Vaidegi B 已提交
4965

4966
on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
4967

4968
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
4969

4970
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 已提交
4971

4972
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4973

4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987
**Parameters**

| Name     | Type                                         | Mandatory | Description                                                  |
| -------- | -------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                       | Yes       | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio playback is interrupted. |
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes       | Callback used to return the audio interruption event.        |

**Error codes**

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

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

W
wusongqing 已提交
4989
**Example**
V
Vaidegi B 已提交
4990

G
Gloria 已提交
4991
```js
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 5033 5034 5035 5036 5037 5038 5039 5040
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;
      }
   }
  });
}
5041

V
Vaidegi B 已提交
5042 5043
```

5044
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
5045

5046
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5047

5048
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 已提交
5049

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

W
wusongqing 已提交
5052
**Parameters**
5053

5054 5055 5056 5057 5058
| 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 已提交
5059

W
wusongqing 已提交
5060
**Example**
V
Vaidegi B 已提交
5061

G
Gloria 已提交
5062
```js
5063 5064 5065
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5066
  }
5067
});
5068

V
Vaidegi B 已提交
5069 5070 5071
```


5072
### off('markReach') <sup>8+</sup>
5073

5074
off(type: 'markReach'): void
V
Vaidegi B 已提交
5075

5076
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5077

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

5080 5081 5082 5083 5084
**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
5085

W
wusongqing 已提交
5086
**Example**
V
Vaidegi B 已提交
5087

G
Gloria 已提交
5088
```js
5089
audioRenderer.off('markReach');
5090

V
Vaidegi B 已提交
5091 5092
```

5093
### on('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5094

5095
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5096

5097
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 已提交
5098

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

W
wusongqing 已提交
5101
**Parameters**
5102

5103 5104 5105 5106 5107
| 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 已提交
5108

W
wusongqing 已提交
5109
**Example**
V
Vaidegi B 已提交
5110

G
Gloria 已提交
5111
```js
5112 5113 5114
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5115
  }
5116
});
5117

V
Vaidegi B 已提交
5118 5119
```

5120
### off('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5121

5122
off(type: 'periodReach'): void
5123

5124
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5125

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

5128
**Parameters**
V
Vaidegi B 已提交
5129

5130 5131 5132
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
5133

W
wusongqing 已提交
5134
**Example**
V
Vaidegi B 已提交
5135

G
Gloria 已提交
5136
```js
5137
audioRenderer.off('periodReach')
5138

V
Vaidegi B 已提交
5139
```
5140

5141
### on('stateChange')<sup>8+</sup>
W
wusongqing 已提交
5142

5143
on(type: 'stateChange', callback: Callback<AudioState\>): void
W
wusongqing 已提交
5144

5145
Subscribes to state change events.
W
wusongqing 已提交
5146

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

5149
**Parameters**
W
wusongqing 已提交
5150

5151 5152 5153 5154
| 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 已提交
5155

5156
**Example**
W
wusongqing 已提交
5157

5158 5159 5160 5161 5162 5163 5164 5165 5166
```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');
  }
});
W
wusongqing 已提交
5167

5168
```
5169

5170
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5171

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

5174
### Attributes
5175

5176
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5177

5178 5179 5180
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
V
Vaidegi B 已提交
5181

5182
**Example**
V
Vaidegi B 已提交
5183

5184 5185
```js
let state = audioCapturer.state;
5186

5187
```
V
Vaidegi B 已提交
5188

5189
### getCapturerInfo<sup>8+</sup>
5190

5191
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5192

5193
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5194

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

W
wusongqing 已提交
5197
**Parameters**
5198

5199 5200 5201
| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
5202

W
wusongqing 已提交
5203
**Example**
5204

G
Gloria 已提交
5205
```js
5206
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5207
  if (err) {
5208 5209 5210 5211 5212
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5213
  }
5214
});
5215

5216 5217
```

5218

5219
### getCapturerInfo<sup>8+</sup>
5220

5221
getCapturerInfo(): Promise<AudioCapturerInfo\>
5222

5223
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
5224

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

5227
**Return value**
5228

5229 5230 5231
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
5232

W
wusongqing 已提交
5233
**Example**
5234

G
Gloria 已提交
5235
```js
5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246
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}`);
5247
});
5248

5249 5250
```

5251
### getStreamInfo<sup>8+</sup>
5252

5253
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5254

5255
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5256

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

W
wusongqing 已提交
5259
**Parameters**
5260

5261 5262 5263
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5264

W
wusongqing 已提交
5265
**Example**
5266

G
Gloria 已提交
5267
```js
5268
audioCapturer.getStreamInfo((err, streamInfo) => {
5269
  if (err) {
5270 5271 5272 5273 5274 5275 5276
    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}`);
5277
  }
5278
});
5279

5280 5281
```

5282
### getStreamInfo<sup>8+</sup>
5283

5284
getStreamInfo(): Promise<AudioStreamInfo\>
5285

5286
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
5287

5288
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5289 5290 5291

**Return value**

5292 5293 5294
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5295

W
wusongqing 已提交
5296
**Example**
5297

G
Gloria 已提交
5298
```js
5299 5300 5301 5302 5303 5304 5305 5306
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}`);
5307
});
5308

5309
```
V
Vaidegi B 已提交
5310

5311
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5312

5313
getAudioStreamId(callback: AsyncCallback<number\>): void
V
Vaidegi B 已提交
5314

5315
Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5316

5317
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5318

W
wusongqing 已提交
5319
**Parameters**
5320

5321 5322 5323
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5324

W
wusongqing 已提交
5325
**Example**
5326

G
Gloria 已提交
5327
```js
5328 5329
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5330
});
5331

5332
```
V
Vaidegi B 已提交
5333

5334
### getAudioStreamId<sup>9+</sup>
5335

5336 5337 5338
getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
5339

5340
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5341 5342 5343

**Return value**

5344 5345 5346
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
5347

W
wusongqing 已提交
5348
**Example**
V
Vaidegi B 已提交
5349

G
Gloria 已提交
5350
```js
5351 5352 5353 5354
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5355
});
5356

V
Vaidegi B 已提交
5357 5358
```

5359
### start<sup>8+</sup>
V
Vaidegi B 已提交
5360

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

5363
Starts capturing. This API uses an asynchronous callback to return the result.
5364

5365
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5366

W
wusongqing 已提交
5367
**Parameters**
V
Vaidegi B 已提交
5368

5369 5370 5371
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5372

W
wusongqing 已提交
5373
**Example**
V
Vaidegi B 已提交
5374

G
Gloria 已提交
5375
```js
5376
audioCapturer.start((err) => {
5377
  if (err) {
5378 5379 5380
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5381
  }
5382
});
5383

V
Vaidegi B 已提交
5384 5385 5386
```


5387
### start<sup>8+</sup>
V
Vaidegi B 已提交
5388

5389
start(): Promise<void\>
5390

5391
Starts capturing. This API uses a promise to return the result.
5392

5393
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5394

W
wusongqing 已提交
5395
**Return value**
V
Vaidegi B 已提交
5396

5397 5398 5399
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5400

W
wusongqing 已提交
5401
**Example**
V
Vaidegi B 已提交
5402

G
Gloria 已提交
5403
```js
5404 5405 5406 5407 5408 5409 5410 5411 5412 5413
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}`);
5414
});
5415

5416
```
V
Vaidegi B 已提交
5417

5418
### stop<sup>8+</sup>
5419

5420
stop(callback: AsyncCallback<void\>): void
5421

5422
Stops capturing. This API uses an asynchronous callback to return the result.
5423

5424
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5425

W
wusongqing 已提交
5426
**Parameters**
V
Vaidegi B 已提交
5427

5428 5429 5430
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5431

W
wusongqing 已提交
5432
**Example**
V
Vaidegi B 已提交
5433

G
Gloria 已提交
5434
```js
5435
audioCapturer.stop((err) => {
5436
  if (err) {
5437 5438 5439
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5440
  }
5441
});
5442

V
Vaidegi B 已提交
5443 5444
```

5445

5446
### stop<sup>8+</sup>
5447

5448
stop(): Promise<void\>
5449

5450
Stops capturing. This API uses a promise to return the result.
5451

5452
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5453

W
wusongqing 已提交
5454
**Return value**
V
Vaidegi B 已提交
5455

5456 5457 5458
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5459

W
wusongqing 已提交
5460
**Example**
V
Vaidegi B 已提交
5461

G
Gloria 已提交
5462
```js
5463 5464 5465 5466 5467 5468 5469 5470
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}`);
5471
});
5472

V
Vaidegi B 已提交
5473 5474
```

5475
### release<sup>8+</sup>
V
Vaidegi B 已提交
5476

5477
release(callback: AsyncCallback<void\>): void
5478

5479
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5480

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

W
wusongqing 已提交
5483
**Parameters**
5484

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

W
wusongqing 已提交
5489
**Example**
5490

G
Gloria 已提交
5491
```js
5492
audioCapturer.release((err) => {
5493
  if (err) {
5494 5495 5496
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5497
  }
5498
});
5499

5500 5501 5502
```


5503
### release<sup>8+</sup>
5504

5505
release(): Promise<void\>
5506

5507
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5508

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

W
wusongqing 已提交
5511
**Return value**
5512

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

W
wusongqing 已提交
5517
**Example**
5518

G
Gloria 已提交
5519
```js
5520 5521 5522 5523 5524 5525 5526 5527
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}`);
5528
});
5529

5530 5531
```

5532
### read<sup>8+</sup>
5533

5534
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
5535

5536
Reads the buffer. This API uses an asynchronous callback to return the result.
5537

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

W
wusongqing 已提交
5540
**Parameters**
5541

5542 5543 5544 5545 5546
| 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.  |
5547

W
wusongqing 已提交
5548
**Example**
5549

G
Gloria 已提交
5550
```js
5551 5552 5553 5554 5555 5556 5557 5558 5559 5560
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');
5561
  }
5562
});
5563

5564 5565
```

5566
### read<sup>8+</sup>
5567

5568
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5569

5570
Reads the buffer. This API uses a promise to return the result.
5571

5572
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5573 5574 5575

**Parameters**

5576 5577 5578 5579
| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
5580

W
wusongqing 已提交
5581
**Return value**
5582

5583 5584 5585
| 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. |
5586

W
wusongqing 已提交
5587
**Example**
5588

G
Gloria 已提交
5589
```js
5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601
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}`);
5602
});
5603

5604
```
5605

5606
### getAudioTime<sup>8+</sup>
5607

5608
getAudioTime(callback: AsyncCallback<number\>): void
5609

5610 5611 5612
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
5613

W
wusongqing 已提交
5614
**Parameters**
5615

5616 5617 5618
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
5619

W
wusongqing 已提交
5620
**Example**
5621

G
Gloria 已提交
5622
```js
5623 5624
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5625
});
5626

5627 5628
```

5629
### getAudioTime<sup>8+</sup>
5630

5631
getAudioTime(): Promise<number\>
5632

5633
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
5634

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

W
wusongqing 已提交
5637
**Return value**
5638

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

W
wusongqing 已提交
5643
**Example**
5644

G
Gloria 已提交
5645
```js
5646 5647 5648 5649
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5650
});
5651

5652 5653
```

5654
### getBufferSize<sup>8+</sup>
5655

5656
getBufferSize(callback: AsyncCallback<number\>): void
5657

5658
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
5659

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

W
wusongqing 已提交
5662
**Parameters**
5663

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

W
wusongqing 已提交
5668
**Example**
5669

G
Gloria 已提交
5670
```js
5671 5672 5673 5674 5675 5676 5677 5678
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}`);
    });
5679
  }
J
jiao_yanlin 已提交
5680
});
5681

5682 5683
```

5684
### getBufferSize<sup>8+</sup>
5685

5686
getBufferSize(): Promise<number\>
5687

5688
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
5689

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

W
wusongqing 已提交
5692
**Return value**
5693

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

W
wusongqing 已提交
5698
**Example**
5699

G
Gloria 已提交
5700
```js
5701 5702 5703 5704 5705 5706
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5707
});
5708

5709 5710
```

5711
### on('markReach')<sup>8+</sup>
5712

5713
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
5714

5715
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
5716

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

W
wusongqing 已提交
5719
**Parameters**
5720

5721 5722 5723 5724 5725
| 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.                |
5726

W
wusongqing 已提交
5727
**Example**
5728

G
Gloria 已提交
5729
```js
5730 5731 5732
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5733
  }
5734
});
5735

5736 5737
```

5738
### off('markReach')<sup>8+</sup>
5739

5740
off(type: 'markReach'): void
5741

5742
Unsubscribes from mark reached events.
5743

5744
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5745 5746 5747

**Parameters**

5748 5749 5750
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
5751

W
wusongqing 已提交
5752
**Example**
5753

G
Gloria 已提交
5754
```js
5755
audioCapturer.off('markReach');
5756

5757 5758
```

5759
### on('periodReach')<sup>8+</sup>
5760

5761
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
5762

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

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

W
wusongqing 已提交
5767
**Parameters**
5768

5769 5770 5771 5772 5773
| 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.                |
5774

W
wusongqing 已提交
5775
**Example**
5776

G
Gloria 已提交
5777
```js
5778 5779 5780
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5781
  }
5782
});
5783

5784 5785
```

5786
### off('periodReach')<sup>8+</sup>
5787

5788
off(type: 'periodReach'): void
5789

5790
Unsubscribes from period reached events.
5791

5792
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5793 5794 5795

**Parameters**

5796 5797 5798
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
5799

W
wusongqing 已提交
5800
**Example**
5801

G
Gloria 已提交
5802
```js
5803
audioCapturer.off('periodReach')
5804

5805 5806
```

5807
### on('stateChange')<sup>8+</sup>
5808

5809
on(type: 'stateChange', callback: Callback<AudioState\>): void
5810

5811
Subscribes to state change events.
5812

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

W
wusongqing 已提交
5815
**Parameters**
5816

5817 5818 5819 5820
| 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.                    |
5821

W
wusongqing 已提交
5822
**Example**
5823

G
Gloria 已提交
5824
```js
5825 5826 5827 5828 5829 5830
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');
5831
  }
5832
});
5833

5834 5835
```

5836
## ToneType<sup>9+</sup>
5837

5838
Enumerates the tone types of the player.
5839

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

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

5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872
| 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.          |
5873

5874
## TonePlayer<sup>9+</sup>
5875

5876
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
5877

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

5880
### load<sup>9+</sup>
5881

5882
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
5883

5884
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
5885

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

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

W
wusongqing 已提交
5890
**Parameters**
5891

5892 5893 5894 5895
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
5896

W
wusongqing 已提交
5897
**Example**
5898

G
Gloria 已提交
5899
```js
5900
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
5901
  if (err) {
5902
    console.error(`callback call load failed error: ${err.message}`);
5903
    return;
5904 5905
  } else {
    console.info('callback call load success');
5906 5907
  }
});
5908

5909 5910
```

5911
### load<sup>9+</sup>
5912

5913
load(type: ToneType): Promise&lt;void&gt;
5914

5915
Loads the DTMF tone configuration. This API uses a promise to return the result.
5916

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

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

W
wusongqing 已提交
5921
**Parameters**
5922

5923 5924 5925
| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
5926 5927 5928

**Return value**

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

W
wusongqing 已提交
5933
**Example**
5934

G
Gloria 已提交
5935
```js
5936 5937 5938 5939
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
5940
});
5941

5942
```
5943

5944
### start<sup>9+</sup>
5945

5946
start(callback: AsyncCallback&lt;void&gt;): void
5947

5948
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
5949

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

5952
**System capability**: SystemCapability.Multimedia.Audio.Tone
5953 5954 5955

**Parameters**

5956 5957 5958
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5959 5960 5961 5962

**Example**

```js
5963
tonePlayer.start((err) => {
5964
  if (err) {
5965
    console.error(`callback call start failed error: ${err.message}`);
5966
    return;
5967 5968
  } else {
    console.info('callback call start success');
5969 5970 5971 5972 5973
  }
});

```

5974
### start<sup>9+</sup>
5975

5976
start(): Promise&lt;void&gt;
5977

5978
Starts DTMF tone playing. This API uses a promise to return the result.
5979

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

5982
**System capability**: SystemCapability.Multimedia.Audio.Tone
5983 5984 5985

**Return value**

5986 5987 5988
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5989 5990 5991 5992

**Example**

```js
5993 5994 5995 5996
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
5997 5998 5999 6000
});

```

6001
### stop<sup>9+</sup>
6002

6003
stop(callback: AsyncCallback&lt;void&gt;): void
6004

6005
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
6006 6007 6008

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

6009
**System capability**: SystemCapability.Multimedia.Audio.Tone
6010 6011 6012

**Parameters**

6013 6014 6015
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6016 6017 6018 6019

**Example**

```js
6020 6021 6022 6023 6024 6025 6026
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
6027 6028 6029 6030
});

```

6031
### stop<sup>9+</sup>
6032

6033
stop(): Promise&lt;void&gt;
6034

6035
Stops the tone that is being played. This API uses a promise to return the result.
6036

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

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

6041
**Return value**
6042

6043 6044 6045
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6046 6047 6048 6049

**Example**

```js
6050 6051 6052 6053
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
6054 6055 6056 6057
});

```

6058
### release<sup>9+</sup>
6059

6060
release(callback: AsyncCallback&lt;void&gt;): void
6061

6062
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
6063

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

6066
**System capability**: SystemCapability.Multimedia.Audio.Tone
6067 6068 6069

**Parameters**

6070 6071 6072
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6073 6074 6075 6076

**Example**

```js
6077 6078 6079 6080 6081 6082 6083
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6084 6085 6086 6087
});

```

6088
### release<sup>9+</sup>
6089

6090
release(): Promise&lt;void&gt;
6091

6092
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
6093

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

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

6098
**Return value**
6099

6100 6101 6102
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6103 6104 6105 6106

**Example**

```js
6107 6108 6109 6110
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6111
});
6112

6113 6114
```

6115
## ActiveDeviceType<sup>(deprecated)</sup>
6116

6117
Enumerates the active device types.
6118

6119 6120 6121
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6122

6123 6124 6125 6126 6127 6128 6129 6130 6131 6132
**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.
6133 6134 6135 6136 6137 6138

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

6140 6141 6142 6143
| Name           | Value | Description               |
| -------------- | ----- | ------------------------- |
| TYPE_ACTIVATED | 0     | Focus gain event.         |
| TYPE_INTERRUPT | 1     | Audio interruption event. |
6144

6145
## AudioInterrupt<sup>(deprecated)</sup>
6146

6147
Describes input parameters of audio interruption events.
6148

6149 6150 6151
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6152

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

6155 6156 6157 6158 6159
| 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. |
6160

6161
## InterruptAction<sup>(deprecated)</sup>
6162

6163
Describes the callback invoked for audio interruption or focus gain events.
6164

6165 6166 6167
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6168

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

6171 6172 6173 6174 6175 6176
| 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. |