js-apis-audio.md 243.6 KB
Newer Older
1
# @ohos.multimedia.audio (Audio Management)
V
Vaidegi B 已提交
2

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

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

W
wusongqing 已提交
7 8 9
- [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
10
- [TonePlayer](#toneplayer9): tone player, used to manage and play Dual Tone Multi Frequency (DTMF) tones, such as dial tones and ringback tones.
11

12
> **NOTE**
13
>
14
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
15

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

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

G
Gloria 已提交
22 23
## Constants

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

**Example**

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

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

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

42
getAudioManager(): AudioManager
43

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

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

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

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

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

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

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

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

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

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

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

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

G
Gloria 已提交
76
```js
77
import featureAbility from '@ohos.ability.featureAbility';
G
Gloria 已提交
78
import fs from '@ohos.file.fs';
79
import audio from '@ohos.multimedia.audio';
80

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

**Example**
181

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

264 265 266 267 268 269 270 271
## audio.createTonePlayer<sup>9+</sup>

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

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

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

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

274 275 276 277 278 279 280 281 282 283 284 285
**Parameters**

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

**Example**

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

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

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

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

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

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

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

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

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
**Parameters**

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

**Return value**

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

**Example**

```js
import audio from '@ohos.multimedia.audio';
330 331
let tonePlayer;
async function createTonePlayerBefore(){
332
  let audioRendererInfo = {
333 334 335
    content : audio.ContentType.CONTENT_TYPE_SONIFICATION,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0
336
  }
337
  tonePlayer = await audio.createTonePlayer(audioRendererInfo);
338 339 340
}
```

341
## AudioVolumeType
W
wusongqing 已提交
342

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

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

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

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

Enumerates the result types of audio interruption requests.

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

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

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

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

Enumerates the audio interruption modes.

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

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

382
## DeviceFlag
W
wusongqing 已提交
383

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

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

388
| Name                           |  Value    | Description                                             |
G
Gloria 已提交
389
| ------------------------------- | ------ | ------------------------------------------------- |
390
| NONE_DEVICES_FLAG<sup>9+</sup>  | 0      | No device.<br>This is a system API.       |
G
Gloria 已提交
391 392 393
| OUTPUT_DEVICES_FLAG             | 1      | Output device.|
| INPUT_DEVICES_FLAG              | 2      | Input device.|
| ALL_DEVICES_FLAG                | 3      | All devices.|
394 395 396
| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4   | Distributed output device.<br>This is a system API. |
| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup>  | 8   | Distributed input device.<br>This is a system API. |
| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup>    | 12  | Distributed input and output device.<br>This is a system API. |
397 398

## DeviceRole
W
wusongqing 已提交
399

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

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

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

409
## DeviceType
W
wusongqing 已提交
410

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

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

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

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

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

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

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

## AudioRingMode
W
wusongqing 已提交
439

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

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

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

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

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

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

456
| Name                               |  Value   | Description                      |
457 458 459 460 461 462
| ---------------------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID              | -1     | Invalid format.                |
| SAMPLE_FORMAT_U8                   | 0      | Unsigned 8-bit integer.           |
| SAMPLE_FORMAT_S16LE                | 1      | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE                | 2      | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_S32LE                | 3      | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
G
Gloria 已提交
463
| SAMPLE_FORMAT_F32LE<sup>9+</sup>   | 4      | Signed 32-bit floating point number, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
464

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

Enumerates the audio error codes.

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

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

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

Enumerates the audio channels.

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

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

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

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

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

498
| Name             |  Value   | Description           |
W
wusongqing 已提交
499 500 501 502 503 504 505 506 507 508 509 510
| ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000  | 8000   | The sampling rate is 8000. |
| SAMPLE_RATE_11025 | 11025  | The sampling rate is 11025.|
| SAMPLE_RATE_12000 | 12000  | The sampling rate is 12000.|
| SAMPLE_RATE_16000 | 16000  | The sampling rate is 16000.|
| SAMPLE_RATE_22050 | 22050  | The sampling rate is 22050.|
| SAMPLE_RATE_24000 | 24000  | The sampling rate is 24000.|
| SAMPLE_RATE_32000 | 32000  | The sampling rate is 32000.|
| SAMPLE_RATE_44100 | 44100  | The sampling rate is 44100.|
| SAMPLE_RATE_48000 | 48000  | The sampling rate is 48000.|
| SAMPLE_RATE_64000 | 64000  | The sampling rate is 64000.|
| SAMPLE_RATE_96000 | 96000  | The sampling rate is 96000.|
511 512 513

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

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

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

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

523 524
## ContentType

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

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

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

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

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

544
| Name                                     |  Value   | Description      |
545 546 547 548 549
| ------------------------------------------| ------ | ---------- |
| STREAM_USAGE_UNKNOWN                      | 0      | Unknown usage.|
| STREAM_USAGE_MEDIA                        | 1      | Used for media.    |
| STREAM_USAGE_VOICE_COMMUNICATION          | 2      | Used for voice communication.|
| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3      | Used for voice assistant.|
G
Gloria 已提交
550
| STREAM_USAGE_ALARM<sup>10+</sup>          | 4      | Used for alarming.    |
551
| STREAM_USAGE_NOTIFICATION_RINGTONE        | 6      | Used for notification.|
G
Gloria 已提交
552 553
| STREAM_USAGE_ACCESSIBILITY<sup>10+</sup>  | 8     | Used for accessibility.  |
| STREAM_USAGE_SYSTEM<sup>10+</sup>         | 9     | System tone (such as screen lock or keypad tone).<br>This is a system API.|
V
Vaidegi B 已提交
554

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

557
Enumerates the audio interruption request types.
558

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

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

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

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

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

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

573
| Name          | Value    | Description            |
W
wusongqing 已提交
574 575 576 577 578 579 580 581
| -------------- | ------ | ---------------- |
| STATE_INVALID  | -1     | Invalid state.      |
| STATE_NEW      | 0      | Creating instance state.|
| STATE_PREPARED | 1      | Prepared.      |
| STATE_RUNNING  | 2      | Running.    |
| STATE_STOPPED  | 3      | Stopped.      |
| STATE_RELEASED | 4      | Released.      |
| STATE_PAUSED   | 5      | Paused.      |
V
Vaidegi B 已提交
582

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

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

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

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

595
## InterruptType
V
Vaidegi B 已提交
596

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

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

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

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

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

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

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

## InterruptHint
V
Vaidegi B 已提交
618

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

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

623
| Name                              |  Value    | Description                                        |
W
wusongqing 已提交
624 625 626 627 628 629 630
| ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup>   | 0      | None.                                    |
| INTERRUPT_HINT_RESUME              | 1      | Resume the playback.                              |
| INTERRUPT_HINT_PAUSE               | 2      | Paused/Pause the playback.                              |
| INTERRUPT_HINT_STOP                | 3      | Stopped/Stop the playback.                              |
| INTERRUPT_HINT_DUCK                | 4      | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5      | Unducked the playback.                              |
631 632

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

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

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

638 639 640 641 642 643
| Name        | Type                                              | Mandatory| Description              |
| ------------ | ------------------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | Yes  | Audio sampling rate.|
| channels     | [AudioChannel](#audiochannel8)                    | Yes  | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | Yes  | Audio sample format.    |
| encodingType | [AudioEncodingType](#audioencodingtype8)          | Yes  | Audio encoding type.    |
644 645

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

Describes audio renderer information.

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

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

657 658 659 660 661 662 663 664 665 666 667 668 669
## InterruptResult<sup>9+</sup>

Describes the audio interruption result.

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

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

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

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

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

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

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

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

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

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

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

G
Gloria 已提交
693
## VolumeEvent<sup>9+</sup>
V
Vaidegi B 已提交
694

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

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

699
| Name      | Type                               | Mandatory  | Description                                                    |
W
wusongqing 已提交
700
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
G
Gloria 已提交
701 702 703 704 705
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                              |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.    |
| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                       |
| volumeGroupId | number                           | Yes  | Volume group ID. It can be used as an input parameter of **getGroupManager**.<br>This is a system API. |
| networkId  | string                              | Yes  | Network ID.<br>This is a system API.                            |
G
Gloria 已提交
706

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

G
Gloria 已提交
717 718 719 720
## ConnectType<sup>9+</sup>

Enumerates the types of connected devices.

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

723
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
724

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

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

W
wusongqing 已提交
754
## DeviceChangeAction
755

W
wusongqing 已提交
756
Describes the device connection status and device information.
757

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

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

W
wusongqing 已提交
765
## DeviceChangeType
766

W
wusongqing 已提交
767
Enumerates the device connection statuses.
V
Vaidegi B 已提交
768

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

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

W
wusongqing 已提交
776
## AudioCapturerOptions<sup>8+</sup>
777

W
wusongqing 已提交
778
Describes audio capturer configurations.
779

W
wusongqing 已提交
780
**System capability**: SystemCapability.Multimedia.Audio.Capturer
781

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

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

W
wusongqing 已提交
789
Describes audio capturer information.
790

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

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

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

W
wusongqing 已提交
800
Enumerates the audio source types.
801

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

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

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

W
wusongqing 已提交
813
Enumerates the audio scenes.
814

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

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

824
## AudioManager
W
wusongqing 已提交
825

W
wusongqing 已提交
826
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 已提交
827

828 829 830
### setAudioParameter

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

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

834
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 已提交
835

836 837 838
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

**System capability**: SystemCapability.Multimedia.Audio.Core
G
Gloria 已提交
839 840 841

**Parameters**

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

**Example**
849

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

860
### setAudioParameter
G
Gloria 已提交
861

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

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

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

**Return value**

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

**Example**
886

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

893
### getAudioParameter
894

895
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
896

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

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

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

W
wusongqing 已提交
903
**Parameters**
904

905 906 907 908
| 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.|
909

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

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

922
### getAudioParameter
923

924
getAudioParameter(key: string): Promise&lt;string&gt;
925

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

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

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

W
wusongqing 已提交
932
**Parameters**
933

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

W
wusongqing 已提交
938
**Return value**
939

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

W
wusongqing 已提交
944
**Example**
W
wusongqing 已提交
945

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

952
### setAudioScene<sup>8+</sup>
W
wusongqing 已提交
953

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

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

958 959 960
**System API**: This is a system API.

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

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

964 965 966 967
| 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.|
968

W
wusongqing 已提交
969
**Example**
W
wusongqing 已提交
970

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

981
### setAudioScene<sup>8+</sup>
V
Vaidegi B 已提交
982

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

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

987 988 989
**System API**: This is a system API.

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

W
wusongqing 已提交
991
**Parameters**
W
wusongqing 已提交
992

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

W
wusongqing 已提交
997
**Return value**
998

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

W
wusongqing 已提交
1003
**Example**
W
wusongqing 已提交
1004

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

1013
### getAudioScene<sup>8+</sup>
1014

1015
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1016

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

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

W
wusongqing 已提交
1021
**Parameters**
W
wusongqing 已提交
1022

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

**Example**
W
wusongqing 已提交
1028

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

1039
### getAudioScene<sup>8+</sup>
W
wusongqing 已提交
1040

1041
getAudioScene\(\): Promise<AudioScene\>
W
wusongqing 已提交
1042

1043
Obtains the audio scene. This API uses a promise to return the result.
1044

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

W
wusongqing 已提交
1047
**Return value**
W
wusongqing 已提交
1048

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

W
wusongqing 已提交
1053
**Example**
1054

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

1063
### getVolumeManager<sup>9+</sup>
1064

1065
getVolumeManager(): AudioVolumeManager
1066

1067
Obtains an **AudioVolumeManager** instance.
1068

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

W
wusongqing 已提交
1071
**Example**
W
wusongqing 已提交
1072

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

1077
### getStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1078

1079
getStreamManager(): AudioStreamManager
W
wusongqing 已提交
1080

1081
Obtains an **AudioStreamManager** instance.
W
wusongqing 已提交
1082

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

1085
**Example**
W
wusongqing 已提交
1086

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

1091
### getRoutingManager<sup>9+</sup>
1092

1093 1094 1095 1096 1097
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

W
wusongqing 已提交
1099
**Example**
W
wusongqing 已提交
1100

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

1105
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1106

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

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

1111 1112
> **NOTE**
>
G
Gloria 已提交
1113
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1114

G
Gloria 已提交
1115 1116
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1121
**Parameters**
W
wusongqing 已提交
1122

1123 1124 1125 1126 1127
| 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.                                  |
1128

W
wusongqing 已提交
1129
**Example**
W
wusongqing 已提交
1130

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

1141
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1142

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

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

1147 1148
> **NOTE**
>
G
Gloria 已提交
1149
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1150

G
Gloria 已提交
1151 1152
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1157
**Parameters**
W
wusongqing 已提交
1158

1159 1160 1161 1162
| 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**.|
1163

W
wusongqing 已提交
1164
**Return value**
1165

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

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

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

1178
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1179

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

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

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

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

W
wusongqing 已提交
1190
**Parameters**
W
wusongqing 已提交
1191

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

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

1209
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1210

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

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

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

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

1221 1222 1223 1224 1225
**Parameters**

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

W
wusongqing 已提交
1227
**Return value**
W
wusongqing 已提交
1228

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

W
wusongqing 已提交
1233
**Example**
W
wusongqing 已提交
1234

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

1241
### getMinVolume<sup>(deprecated)</sup>
1242

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

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

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

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

W
wusongqing 已提交
1253
**Parameters**
W
wusongqing 已提交
1254

1255 1256 1257 1258
| 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 已提交
1259

W
wusongqing 已提交
1260
**Example**
W
wusongqing 已提交
1261

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

1272
### getMinVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1273

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

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

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

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

W
wusongqing 已提交
1284
**Parameters**
W
wusongqing 已提交
1285

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

W
wusongqing 已提交
1290
**Return value**
1291

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

W
wusongqing 已提交
1296
**Example**
W
wusongqing 已提交
1297

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

1304
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1305

1306
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1307

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

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

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

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

1318 1319 1320 1321
| 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 已提交
1322

W
wusongqing 已提交
1323
**Example**
W
wusongqing 已提交
1324

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

1335
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1336

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

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

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

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

W
wusongqing 已提交
1347
**Parameters**
1348

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

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

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

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

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

1367
### mute<sup>(deprecated)</sup>
1368

1369
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1370

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

1373 1374
> **NOTE**
>
G
Gloria 已提交
1375
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1376 1377

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

W
wusongqing 已提交
1379
**Parameters**
W
wusongqing 已提交
1380

1381 1382 1383 1384 1385
| 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 已提交
1386

W
wusongqing 已提交
1387
**Example**
1388

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

1399
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1400

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

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

1405 1406
> **NOTE**
>
G
Gloria 已提交
1407
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1408 1409

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

W
wusongqing 已提交
1411
**Parameters**
W
wusongqing 已提交
1412

1413 1414 1415 1416
| 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 已提交
1417

W
wusongqing 已提交
1418
**Return value**
1419

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

W
wusongqing 已提交
1424
**Example**
W
wusongqing 已提交
1425

1426

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

1433
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1434

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

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

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

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

W
wusongqing 已提交
1445
**Parameters**
W
wusongqing 已提交
1446

1447 1448 1449 1450
| 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.|
1451

W
wusongqing 已提交
1452
**Example**
W
wusongqing 已提交
1453

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

1464
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1465

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

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

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

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

W
wusongqing 已提交
1476
**Parameters**
1477

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

W
wusongqing 已提交
1482
**Return value**
1483

1484 1485 1486
| 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.|
1487

W
wusongqing 已提交
1488
**Example**
1489

G
Gloria 已提交
1490
```js
1491
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
1492
  console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
1493
});
W
wusongqing 已提交
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 1556 1557 1558 1559
### 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 已提交
1560

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

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

1565 1566
> **NOTE**
>
G
Gloria 已提交
1567
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1568

1569 1570 1571 1572
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1575
**Parameters**
W
wusongqing 已提交
1576

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

W
wusongqing 已提交
1582
**Example**
W
wusongqing 已提交
1583

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

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

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

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

1600 1601
> **NOTE**
>
G
Gloria 已提交
1602 1603
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.

1604

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

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

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

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

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

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

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

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

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

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

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

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

1637 1638 1639 1640 1641
> **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
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651

**Parameters**

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

**Example**

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

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

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

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

1667 1668 1669 1670 1671
> **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
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681

**Return value**

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

**Example**

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

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

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

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

1693 1694 1695 1696 1697
> **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
1698 1699 1700

**Parameters**

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

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

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

1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
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.|
1740 1741 1742 1743

**Example**

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

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

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

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

1755 1756 1757 1758 1759
> **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 已提交
1760

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1808

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

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

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

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

1821 1822 1823 1824 1825
> **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 已提交
1826

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

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

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

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

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

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

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

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

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

**Parameters**

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

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

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

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

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

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

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

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

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

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

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

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

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

1899
**Example**
1900

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

1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
### 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 已提交
1936

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

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

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

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

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

1951 1952 1953
> **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 已提交
1954

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

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

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

1961 1962 1963
| 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 已提交
1964

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

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

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

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

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

1983 1984 1985 1986 1987 1988 1989
> **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
1990

1991
**Return value**
1992

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

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

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

G
Gloria 已提交
2005
### on('volumeChange')<sup>9+</sup>
2006

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

2009 2010
> **NOTE**
>
G
Gloria 已提交
2011
> You are advised to use [on('volumeChange')](#onvolumechange9) in **AudioVolumeManager**.
2012

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

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

2023 2024 2025
| 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.|
G
Gloria 已提交
2026
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the system volume change event.                                                  |
2027

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

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

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

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

2042
Subscribes to ringer mode change events.
2043

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

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

2050 2051 2052 2053 2054 2055 2056 2057
**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.                                                  |
2058 2059

**Example**
2060

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

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

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

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

2073 2074
> **NOTE**
>
G
Gloria 已提交
2075
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('deviceChange')](#ondevicechange9) in **AudioRoutingManager**.
2076

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

2079
**Parameters**
2080

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

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

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

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

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

2101
Unsubscribes from device change events.
2102

2103 2104
> **NOTE**
>
G
Gloria 已提交
2105
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('deviceChange')](#offdevicechange9) in **AudioRoutingManager**.
2106

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

2109
**Parameters**
2110

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

**Example**

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

2124
### on('interrupt')
2125

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

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

2130 2131 2132
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.

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

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

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

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

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

2162
### off('interrupt')
2163

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

2166
Unsubscribes from audio interruption events.
2167

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

W
wusongqing 已提交
2170
**Parameters**
2171

2172 2173 2174 2175 2176
| 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.                                      |
2177

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

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

2194
## AudioVolumeManager<sup>9+</sup>
2195

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

2198
### getVolumeGroupInfos<sup>9+</sup>
2199

2200 2201 2202 2203 2204 2205 2206
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
2207

W
wusongqing 已提交
2208
**Parameters**
2209

2210 2211 2212 2213
| 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.|
2214

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

2226
### getVolumeGroupInfos<sup>9+</sup>
2227

2228
getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2229

2230
Obtains the volume groups. This API uses a promise to return the result.
2231

2232 2233 2234
**System API**: This is a system API.

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

2236 2237
**Parameters**

2238 2239 2240
| Name    | Type              | Mandatory| Description                |
| ---------- | ------------------| ---- | -------------------- |
| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2241

W
wusongqing 已提交
2242
**Return value**
2243

2244 2245 2246
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
2247

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

G
Gloria 已提交
2250
```js
2251 2252 2253 2254 2255
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))
}
```
2256

2257
### getVolumeGroupManager<sup>9+</sup>
2258

2259
getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2260

2261
Obtains the audio group manager. This API uses an asynchronous callback to return the result.
2262

2263
**System capability**: SystemCapability.Multimedia.Audio.Volume
2264 2265 2266

**Parameters**

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

**Example**
2273

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

2284 2285
```

2286
### getVolumeGroupManager<sup>9+</sup>
2287

2288
getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2289

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

2292
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2293 2294 2295

**Parameters**

2296 2297 2298
| Name    | Type                                     | Mandatory| Description             |
| ---------- | ---------------------------------------- | ---- | ---------------- |
| groupId    | number                                   | Yes  | Volume group ID.    |
2299 2300 2301

**Return value**

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

**Example**
G
Gloria 已提交
2307 2308

```js
2309 2310 2311 2312 2313 2314 2315 2316
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.');
}

2317 2318
```

2319
### on('volumeChange')<sup>9+</sup>
2320

2321
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2322

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

2325
**System capability**: SystemCapability.Multimedia.Audio.Volume
2326 2327 2328

**Parameters**

2329 2330 2331
| 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.|
G
Gloria 已提交
2332
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the system volume change event.                                                  |
G
Gloria 已提交
2333

2334
**Error codes**
2335

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

2338 2339
| ID| Error Message|
| ------- | --------------------------------------------|
2340
| 6800101 | if input parameter value error              |
2341 2342

**Example**
G
Gloria 已提交
2343 2344

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

2352
## AudioVolumeGroupManager<sup>9+</sup>
2353

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

2356
### setVolume<sup>9+</sup>
2357

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

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

2362
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2363

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

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

2368
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2369 2370 2371

**Parameters**

2372 2373 2374 2375 2376
| 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 已提交
2377 2378

**Example**
2379

2380 2381 2382 2383 2384 2385 2386 2387
```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 已提交
2388 2389
```

2390
### setVolume<sup>9+</sup>
G
Gloria 已提交
2391

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

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

2396
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2397

2398 2399 2400 2401 2402
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 已提交
2403 2404 2405

**Parameters**

2406 2407 2408 2409
| 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 已提交
2410 2411 2412

**Return value**

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

**Example**

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

2425
### getVolume<sup>9+</sup>
G
Gloria 已提交
2426

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

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

2431
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2432 2433 2434

**Parameters**

2435 2436 2437 2438
| 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 已提交
2439 2440 2441 2442

**Example**

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

2452
### getVolume<sup>9+</sup>
G
Gloria 已提交
2453

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

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

2458
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2459 2460 2461

**Parameters**

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

**Return value**

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

**Example**

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

2480
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2481

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

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

2486
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2487 2488 2489

**Parameters**

2490 2491 2492 2493
| 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 已提交
2494 2495 2496 2497

**Example**

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

2507
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2508

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

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

2513
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2514 2515 2516

**Parameters**

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

**Return value**

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

**Example**

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

2535
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2536

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

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

2541
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2542 2543 2544

**Parameters**

2545 2546 2547 2548
| 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 已提交
2549 2550

**Example**
2551

G
Gloria 已提交
2552
```js
2553 2554 2555 2556 2557 2558 2559
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 已提交
2560 2561
```

2562
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2563

2564
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2565

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

2568
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2569 2570 2571

**Parameters**

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

**Return value**

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

**Example**

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

2590
### mute<sup>9+</sup>
2591

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

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

2596
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2597

2598 2599 2600 2601 2602
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 已提交
2603 2604 2605

**Parameters**

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

**Example**

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

2624
### mute<sup>9+</sup>
G
Gloria 已提交
2625

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

2628
Mutes or unmutes a stream. This API uses a promise to return the result.
2629

2630
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2631

2632 2633 2634 2635 2636
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 已提交
2637 2638 2639

**Parameters**

2640 2641 2642 2643
| 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 已提交
2644 2645 2646

**Return value**

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

**Example**

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

2659
### isMute<sup>9+</sup>
G
Gloria 已提交
2660

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

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

2665
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2666

2667
**Parameters**
G
Gloria 已提交
2668

2669 2670 2671 2672
| 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 已提交
2673 2674 2675 2676

**Example**

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

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

2714
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2715

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

2718
Sets the ringer mode. This API uses an asynchronous callback to return the result.
2719

2720
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2721

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

2724
**System API**: This is a system API.
G
Gloria 已提交
2725

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

2728 2729 2730 2731 2732 2733
**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 已提交
2734 2735 2736 2737

**Example**

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

2747
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2748

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

2751
Sets the ringer mode. This API uses a promise to return the result.
2752

2753
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2754

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

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

**Example**

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

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

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

2807 2808 2809 2810 2811
### getRingerMode<sup>9+</sup>

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

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

2813
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2814

2815
**Return value**
2816

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

2821
**Example**
G
Gloria 已提交
2822

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

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

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

2833
Subscribes to ringer mode change events.
2834

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

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

**Example**

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

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

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

2865
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
2866

2867
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2868 2869 2870

**Parameters**

2871 2872 2873 2874
| 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 已提交
2875 2876 2877 2878

**Example**

```js
2879 2880 2881 2882 2883 2884
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 已提交
2885 2886 2887
});
```

2888
### setMicrophoneMute<sup>9+</sup>
2889

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

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

2894 2895 2896 2897 2898 2899 2900 2901 2902
**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 已提交
2903 2904 2905

**Return value**

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

**Example**

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

2918
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2919

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

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

2924
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2925 2926 2927

**Parameters**

2928 2929 2930
| 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 已提交
2931 2932 2933 2934

**Example**

```js
2935 2936 2937 2938 2939 2940
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 已提交
2941 2942 2943
});
```

2944
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2945

2946
isMicrophoneMute(): Promise&lt;boolean&gt;
G
Gloria 已提交
2947

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

2950
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2951 2952 2953

**Return value**

2954 2955 2956
| 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 已提交
2957 2958 2959 2960

**Example**

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

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

2968 2969 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
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 已提交
2997 2998
```

2999
## AudioStreamManager<sup>9+</sup>
G
Gloria 已提交
3000

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

3003 3004 3005 3006 3007
### 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 已提交
3008 3009 3010 3011 3012

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

**Parameters**

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

**Example**

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

3050
### getCurrentAudioRendererInfoArray<sup>9+</sup>
G
Gloria 已提交
3051

3052
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
G
Gloria 已提交
3053

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

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

**Return value**

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

**Example**

```js
3067 3068 3069 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
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}`);
  });
}
3095
```
G
Gloria 已提交
3096

3097
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3098

3099
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3100

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

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

**Parameters**

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

**Example**

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

3142
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
G
Gloria 已提交
3143

3144
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
G
Gloria 已提交
3145

3146
Obtains the information about the current audio capturer. This API uses a promise to return the result.
G
Gloria 已提交
3147 3148 3149

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

3150
**Return value**
G
Gloria 已提交
3151

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

**Example**

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

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

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

3191
Subscribes to audio renderer change events.
G
Gloria 已提交
3192

3193
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3194 3195 3196

**Parameters**

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

**Example**

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

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

3239
off(type: "audioRendererChange"): void
G
Gloria 已提交
3240

3241
Unsubscribes from audio renderer change events.
G
Gloria 已提交
3242

3243
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3244

3245
**Parameters**
G
Gloria 已提交
3246

3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257
| 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 已提交
3258 3259 3260 3261

**Example**

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

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

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

3270
Subscribes to audio capturer change events.
G
Gloria 已提交
3271

3272
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3273 3274 3275

**Parameters**

3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287
| 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              |
3288 3289

**Example**
G
Gloria 已提交
3290 3291

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

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

3317
off(type: "audioCapturerChange"): void;
G
Gloria 已提交
3318

3319
Unsubscribes from audio capturer change events.
G
Gloria 已提交
3320

3321
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
3322

3323
**Parameters**
G
Gloria 已提交
3324

3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335
| 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 已提交
3336 3337 3338 3339

**Example**

```js
3340 3341
audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########');
3342

3343 3344
```

3345
### isActive<sup>9+</sup>
3346

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

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

3351
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3352 3353 3354

**Parameters**

3355 3356 3357 3358
| 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.|
3359 3360

**Example**
G
Gloria 已提交
3361 3362

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

3372
### isActive<sup>9+</sup>
3373

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

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

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

3380 3381 3382 3383 3384 3385
**Parameters**

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

3386
**Return value**
G
Gloria 已提交
3387

3388 3389 3390
| 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.|
3391 3392

**Example**
G
Gloria 已提交
3393 3394

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

3400
## AudioRoutingManager<sup>9+</sup>
3401

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

3404
### getDevices<sup>9+</sup>
3405

3406 3407 3408 3409 3410
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
3411 3412 3413

**Parameters**

3414 3415 3416 3417
| 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.|
3418 3419 3420

**Example**

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

3431
### getDevices<sup>9+</sup>
3432

3433
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
3434

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

3437 3438 3439 3440 3441 3442 3443
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

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

**Return value**

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

**Example**

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

G
Gloria 已提交
3459
### on('deviceChange')<sup>9+</sup>
3460

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

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

3465
**System capability**: SystemCapability.Multimedia.Audio.Device
3466 3467 3468

**Parameters**

3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481
| 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              |
3482 3483

**Example**
3484

3485
```js
3486 3487 3488 3489 3490
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);
3491 3492
});
```
3493

G
Gloria 已提交
3494
### off('deviceChange')<sup>9+</sup>
3495

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

3498
Unsubscribes from device change events.
3499

3500
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3501

3502
**Parameters**
G
Gloria 已提交
3503

3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515
| 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              |
3516 3517 3518

**Example**

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

3525
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3526

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

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

3531 3532 3533
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3534 3535 3536

**Parameters**

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

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

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

3568
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3569

3570
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3571

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

3574 3575 3576 3577 3578 3579 3580 3581 3582
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.              |
3583 3584 3585

**Return value**

3586 3587 3588
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3589 3590 3591

**Example**

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

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

3616
### setCommunicationDevice<sup>9+</sup>
3617

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

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

3622
**System capability**: SystemCapability.Multimedia.Audio.Communication
3623

3624
**Parameters**
3625

3626 3627 3628 3629 3630
| 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.|
3631 3632 3633

**Example**

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

3644
### setCommunicationDevice<sup>9+</sup>
3645

3646
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
3647

3648
Sets a communication device to the active state. This API uses a promise to return the result.
3649

3650 3651 3652 3653 3654 3655 3656 3657
**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.    |
3658 3659 3660

**Return value**

3661 3662 3663
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
3664 3665 3666 3667

**Example**

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

3673
### isCommunicationDeviceActive<sup>9+</sup>
3674

3675
isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
3676

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

3679
**System capability**: SystemCapability.Multimedia.Audio.Communication
3680 3681 3682

**Parameters**

3683 3684 3685 3686
| 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.|
3687 3688 3689 3690

**Example**

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

3700
### isCommunicationDeviceActive<sup>9+</sup>
3701

3702
isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
3703

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

3706
**System capability**: SystemCapability.Multimedia.Audio.Communication
3707 3708 3709

**Parameters**

3710 3711 3712
| Name    | Type                                                 | Mandatory| Description              |
| ---------- | ---------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.|
3713 3714 3715

**Return value**

3716 3717 3718
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
3719 3720 3721 3722

**Example**

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

3728
### selectOutputDevice<sup>9+</sup>
3729

3730
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3731

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

3734 3735 3736
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
3737 3738 3739

**Parameters**

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

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

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

3771
### selectOutputDevice<sup>9+</sup>
3772

3773
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3774

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

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

3779
**System capability**: SystemCapability.Multimedia.Audio.Device
3780 3781 3782

**Parameters**

3783 3784 3785
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3786 3787 3788

**Return value**

3789 3790 3791
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3792 3793 3794 3795

**Example**

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

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

3819
### selectOutputDeviceByFilter<sup>9+</sup>
3820

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

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

3825 3826 3827
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
3828 3829 3830

**Parameters**

3831 3832 3833 3834 3835
| 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.|
3836 3837 3838

**Example**
```js
3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859
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,
}];
3860

3861 3862 3863 3864 3865 3866 3867 3868
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'); }
  });
}
3869 3870
```

3871
### selectOutputDeviceByFilter<sup>9+</sup>
3872

3873
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3874

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

3877 3878 3879
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
3880 3881 3882

**Parameters**

3883 3884 3885 3886
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3887 3888 3889

**Return value**

3890 3891 3892
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3893 3894 3895 3896

**Example**

```js
3897 3898 3899 3900 3901 3902 3903
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3904

3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917
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,
}];
3918

3919 3920 3921 3922 3923 3924 3925 3926
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}`);
  })
}
```
3927

G
Gloria 已提交
3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947
### getPreferOutputDeviceForRendererInfo<sup>10+</sup>

getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void

Obtains the output device with the highest priority based on the audio renderer information. This API uses an asynchronous callback to return the result.

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

**Parameters**

| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| rendererInfo                | [AudioRendererInfo](#audiorendererinfo8)                     | Yes  | Audio renderer information.            |
| callback                    | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;  | Yes  | Callback used to return the information about the output device with the highest priority.|

**Example**
```js
let rendererInfo = {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
3948
    rendererFlags : 0 }
G
Gloria 已提交
3949 3950 3951 3952

async function getPreferOutputDevice() {
  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err, desc) => {
    if (err) {
3953
      console.error(`Result ERROR: ${err}`);
G
Gloria 已提交
3954
    } else {
3955
      console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
3956 3957 3958 3959 3960
    }
  });
}
```

3961
### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
G
Gloria 已提交
3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979
getPreferOutputDeviceForRendererInfo(rendererInfo: AudioRendererInfo): Promise&lt;AudioDeviceDescriptors&gt;

Obtains the output device with the highest priority based on the audio renderer information. This API uses a promise to return the result.

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

**Parameters**

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

**Return value**

| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt;   | Promise used to return the information about the output device with the highest priority.|

3980 3981 3982 3983 3984 3985 3986 3987
**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 已提交
3988 3989 3990 3991 3992 3993
**Example**

```js
let rendererInfo = {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
3994
    rendererFlags : 0 }
G
Gloria 已提交
3995 3996 3997

async function getPreferOutputDevice() {
  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc) => {
3998
    console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
3999
  }).catch((err) => {
4000
    console.error(`Result ERROR: ${err}`);
G
Gloria 已提交
4001 4002 4003 4004 4005 4006 4007 4008 4009 4010
  })
}
```

### on('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>

on(type: 'preferOutputDeviceChangeForRendererInfo', rendererInfo: AudioRendererInfo, callback: Callback<AudioDeviceDescriptors\>): void

Subscribes to the change of the output device with the highest priority. This API uses an asynchronous callback to return the result.

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

G
Gloria 已提交
4013 4014 4015 4016 4017 4018 4019 4020
**Parameters**

| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Event type. The value **'preferOutputDeviceChangeForRendererInfo'** means the event triggered when the output device with the highest priority changes.|
| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8)        | Yes  | Audio renderer information.             |
| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | Yes  | Callback used to return the information about the output device with the highest priority.                        |

4021 4022 4023 4024 4025 4026 4027 4028
**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 已提交
4029 4030 4031 4032 4033 4034
**Example**

```js
let rendererInfo = {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
4035
    rendererFlags : 0 }
G
Gloria 已提交
4036 4037

audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc) => {
4038
  console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056
});
```

### off('preferOutputDeviceChangeForRendererInfo')<sup>10+</sup>

off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDeviceDescriptors\>): void

Unsubscribes from the change of the output device with the highest priority.

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

**Parameters**

| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Event type. The value **'preferOutputDeviceChangeForRendererInfo'** means the event triggered when the output device with the highest priority changes.|
| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | No  | Callback used for unsubscription.                        |

4057 4058 4059 4060 4061 4062 4063 4064
**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 已提交
4065 4066 4067 4068 4069 4070 4071 4072
**Example**

```js
audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', () => {
  console.info('Should be no callback.');
});
```

4073
## AudioRendererChangeInfoArray<sup>9+</sup>
4074

4075
Defines an **AudioRenderChangeInfo** array, which is read-only.
4076 4077 4078

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

4079
## AudioRendererChangeInfo<sup>9+</sup>
4080

4081 4082 4083 4084
Describes the audio renderer change event.

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

G
Gloria 已提交
4085 4086 4087 4088 4089 4090 4091
| 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.                      |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
4092 4093 4094 4095

**Example**

```js
4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125
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}`);
    }
4126 4127 4128 4129 4130
  }
});
```


4131
## AudioCapturerChangeInfoArray<sup>9+</sup>
4132

4133
Defines an **AudioCapturerChangeInfo** array, which is read-only.
4134

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

4137
## AudioCapturerChangeInfo<sup>9+</sup>
4138

4139
Describes the audio capturer change event.
4140

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

G
Gloria 已提交
4143 4144 4145 4146 4147 4148 4149
| 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.                      |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
4150 4151 4152 4153

**Example**

```js
4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177
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}`);
4178
    }
4179 4180 4181
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4182 4183 4184 4185 4186
    }
  }
});
```

4187
## AudioDeviceDescriptors
4188

4189
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
4190

4191
## AudioDeviceDescriptor
4192

4193
Describes an audio device.
4194

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

4197 4198 4199 4200
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
G
Gloria 已提交
4201
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID, which is unique.                                  |
4202 4203 4204 4205 4206 4207 4208 4209
| 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. |
4210 4211 4212 4213

**Example**

```js
4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230
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');
4231 4232 4233 4234
  }
});
```

4235
## AudioRendererFilter<sup>9+</sup>
4236

4237
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4238

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

4241 4242
| Name         | Type                                     | Mandatory | Description                                                  |
| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
G
Gloria 已提交
4243
| uid          | number                                   | No        | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core |
4244 4245
| 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 |
4246

4247
**Example**
4248

4249 4250 4251 4252 4253 4254 4255 4256 4257
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4258

4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269
## 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. |
4270 4271 4272 4273

**Example**

```js
4274
let state = audioRenderer.state;
4275 4276
```

4277
### getRendererInfo<sup>8+</sup>
4278

4279
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4280

4281
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4282 4283 4284 4285 4286

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

**Parameters**

4287 4288 4289
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
4290 4291 4292 4293

**Example**

```js
4294 4295 4296 4297 4298
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}`);
4299 4300 4301
});
```

4302
### getRendererInfo<sup>8+</sup>
4303

4304
getRendererInfo(): Promise<AudioRendererInfo\>
4305

4306
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4307 4308 4309

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

4310
**Return value**
4311

4312 4313 4314
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
4315 4316 4317 4318

**Example**

```js
4319 4320 4321 4322 4323 4324 4325 4326
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}`);
});
4327 4328
```

4329
### getStreamInfo<sup>8+</sup>
4330

4331
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4332

4333
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4334 4335 4336 4337 4338

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

**Parameters**

4339 4340 4341
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
4342 4343 4344 4345

**Example**

```js
4346 4347 4348 4349 4350 4351
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}`);
4352 4353 4354
});
```

4355
### getStreamInfo<sup>8+</sup>
4356

4357
getStreamInfo(): Promise<AudioStreamInfo\>
4358

4359
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
4360

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

4363 4364 4365 4366 4367
**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
4368 4369 4370 4371

**Example**

```js
4372 4373 4374 4375 4376 4377 4378 4379 4380
audioRenderer.getStreamInfo().then((streamInfo) => {
  console.info('Renderer GetStreamInfo:');
  console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
  console.info(`Renderer channel: ${streamInfo.channels}`);
  console.info(`Renderer format: ${streamInfo.sampleFormat}`);
  console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
G
Gloria 已提交
4381

4382
```
4383

4384
### getAudioStreamId<sup>9+</sup>
4385

4386
getAudioStreamId(callback: AsyncCallback<number\>): void
4387

4388
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4389

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

4392 4393
**Parameters**

4394 4395 4396
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
4397

4398 4399
**Example**

G
Gloria 已提交
4400
```js
4401 4402
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4403
});
G
Gloria 已提交
4404

4405 4406
```

4407
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4408

4409
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4410

4411
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4412

4413
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4414 4415

**Return value**
V
Vaidegi B 已提交
4416

4417 4418 4419
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
4420

W
wusongqing 已提交
4421
**Example**
V
Vaidegi B 已提交
4422

G
Gloria 已提交
4423
```js
4424 4425
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4426
}).catch((err) => {
4427
  console.error(`ERROR: ${err}`);
4428
});
G
Gloria 已提交
4429

4430
```
V
Vaidegi B 已提交
4431

4432
### start<sup>8+</sup>
4433

4434
start(callback: AsyncCallback<void\>): void
4435

4436
Starts the renderer. This API uses an asynchronous callback to return the result.
4437

4438
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4439 4440 4441

**Parameters**

4442 4443 4444
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4445 4446 4447 4448

**Example**

```js
4449
audioRenderer.start((err) => {
4450
  if (err) {
4451
    console.error('Renderer start failed.');
4452
  } else {
4453
    console.info('Renderer start success.');
4454
  }
4455
});
G
Gloria 已提交
4456

V
Vaidegi B 已提交
4457 4458
```

4459
### start<sup>8+</sup>
G
Gloria 已提交
4460

4461
start(): Promise<void\>
G
Gloria 已提交
4462

4463
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
4464

4465
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4466 4467 4468

**Return value**

4469 4470 4471
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
4472 4473 4474 4475

**Example**

```js
4476 4477
audioRenderer.start().then(() => {
  console.info('Renderer started');
4478
}).catch((err) => {
4479
  console.error(`ERROR: ${err}`);
4480
});
G
Gloria 已提交
4481

4482 4483
```

4484
### pause<sup>8+</sup>
4485

4486
pause(callback: AsyncCallback\<void>): void
4487

4488
Pauses rendering. This API uses an asynchronous callback to return the result.
4489

4490
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4491 4492 4493

**Parameters**

4494 4495 4496
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4497 4498 4499 4500

**Example**

```js
4501 4502 4503 4504 4505 4506
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4507
});
G
Gloria 已提交
4508

4509 4510
```

4511
### pause<sup>8+</sup>
4512

4513
pause(): Promise\<void>
4514

4515
Pauses rendering. This API uses a promise to return the result.
4516

4517
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4518 4519 4520

**Return value**

4521 4522 4523
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
4524 4525 4526 4527

**Example**

```js
4528 4529
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4530 4531 4532
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
G
Gloria 已提交
4533

4534 4535
```

4536
### drain<sup>8+</sup>
4537

4538
drain(callback: AsyncCallback\<void>): void
4539

4540
Drains the playback buffer. This API uses an asynchronous callback to return the result.
4541

4542
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4543 4544 4545 4546

**Parameters**

| Name     | Type                 | Mandatory | Description                         |
4547 4548
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4549 4550 4551 4552

**Example**

```js
4553
audioRenderer.drain((err) => {
4554
  if (err) {
4555
    console.error('Renderer drain failed');
4556
  } else {
4557
    console.info('Renderer drained.');
4558 4559
  }
});
G
Gloria 已提交
4560

G
Gloria 已提交
4561 4562
```

4563
### drain<sup>8+</sup>
V
Vaidegi B 已提交
4564

4565
drain(): Promise\<void>
V
Vaidegi B 已提交
4566

4567
Drains the playback buffer. This API uses a promise to return the result.
4568

4569
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4570 4571 4572 4573

**Return value**

| Type           | Description                        |
4574 4575
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4576

W
wusongqing 已提交
4577
**Example**
V
Vaidegi B 已提交
4578

G
Gloria 已提交
4579
```js
4580 4581
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
4582
}).catch((err) => {
4583
  console.error(`ERROR: ${err}`);
4584
});
G
Gloria 已提交
4585

V
Vaidegi B 已提交
4586 4587
```

4588
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4589

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

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

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

W
wusongqing 已提交
4596
**Parameters**
V
Vaidegi B 已提交
4597

4598
| Name     | Type                 | Mandatory | Description                         |
4599 4600
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4601

W
wusongqing 已提交
4602
**Example**
V
Vaidegi B 已提交
4603

G
Gloria 已提交
4604
```js
4605
audioRenderer.stop((err) => {
4606
  if (err) {
4607
    console.error('Renderer stop failed');
4608
  } else {
4609
    console.info('Renderer stopped.');
4610
  }
4611
});
G
Gloria 已提交
4612

V
Vaidegi B 已提交
4613 4614
```

4615
### stop<sup>8+</sup>
4616

4617
stop(): Promise\<void>
V
Vaidegi B 已提交
4618

4619
Stops rendering. This API uses a promise to return the result.
4620

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

W
wusongqing 已提交
4623
**Return value**
V
Vaidegi B 已提交
4624

4625
| Type           | Description                        |
4626 4627
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4628

W
wusongqing 已提交
4629
**Example**
V
Vaidegi B 已提交
4630

G
Gloria 已提交
4631
```js
4632 4633
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4634
}).catch((err) => {
4635
  console.error(`ERROR: ${err}`);
4636
});
G
Gloria 已提交
4637

4638
```
V
Vaidegi B 已提交
4639

4640
### release<sup>8+</sup>
V
Vaidegi B 已提交
4641

4642
release(callback: AsyncCallback\<void>): void
4643

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

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

W
wusongqing 已提交
4648
**Parameters**
V
Vaidegi B 已提交
4649

4650
| Name     | Type                 | Mandatory | Description                         |
4651 4652
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4653

W
wusongqing 已提交
4654
**Example**
V
Vaidegi B 已提交
4655

G
Gloria 已提交
4656
```js
4657
audioRenderer.release((err) => {
4658
  if (err) {
4659
    console.error('Renderer release failed');
4660
  } else {
4661
    console.info('Renderer released.');
4662
  }
4663
});
G
Gloria 已提交
4664

V
Vaidegi B 已提交
4665 4666
```

4667
### release<sup>8+</sup>
V
Vaidegi B 已提交
4668

4669
release(): Promise\<void>
V
Vaidegi B 已提交
4670

4671
Releases the renderer. This API uses a promise to return the result.
4672

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

W
wusongqing 已提交
4675
**Return value**
V
Vaidegi B 已提交
4676

4677
| Type           | Description                        |
4678 4679
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4680

W
wusongqing 已提交
4681
**Example**
V
Vaidegi B 已提交
4682

G
Gloria 已提交
4683
```js
4684 4685
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4686
}).catch((err) => {
4687
  console.error(`ERROR: ${err}`);
4688
});
G
Gloria 已提交
4689

V
Vaidegi B 已提交
4690 4691
```

4692
### write<sup>8+</sup>
V
Vaidegi B 已提交
4693

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

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

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

W
wusongqing 已提交
4700
**Parameters**
V
Vaidegi B 已提交
4701

4702 4703 4704 4705
| 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 已提交
4706

W
wusongqing 已提交
4707
**Example**
V
Vaidegi B 已提交
4708

G
Gloria 已提交
4709
```js
4710
let bufferSize;
4711 4712
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4713 4714
  bufferSize = data;
  }).catch((err) => {
4715
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4716
  });
4717 4718 4719 4720 4721 4722 4723
console.info(`Buffer size: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
G
Gloria 已提交
4724 4725
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4726
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4727
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4728 4729
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4730 4731
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4732 4733 4734
    }
    let readsize = await fs.read(file.fd, buf, options)
    let writeSize = await new Promise((resolve,reject)=>{
G
Gloria 已提交
4735
      audioRenderer.write(buf,(err,writeSize)=>{
G
Gloria 已提交
4736 4737 4738 4739 4740 4741 4742 4743 4744
        if(err){
          reject(err)
        }else{
          resolve(writeSize)
        }
      })
    })	  
}

G
Gloria 已提交
4745

V
Vaidegi B 已提交
4746 4747
```

4748
### write<sup>8+</sup>
V
Vaidegi B 已提交
4749

4750
write(buffer: ArrayBuffer): Promise\<number>
4751

4752
Writes the buffer. This API uses a promise to return the result.
4753

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

W
wusongqing 已提交
4756
**Return value**
V
Vaidegi B 已提交
4757

4758 4759 4760
| 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 已提交
4761

W
wusongqing 已提交
4762
**Example**
V
Vaidegi B 已提交
4763

G
Gloria 已提交
4764
```js
4765
let bufferSize;
4766 4767
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4768 4769
  bufferSize = data;
  }).catch((err) => {
4770
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4771
  });
4772 4773 4774 4775 4776 4777 4778
console.info(`BufferSize: ${bufferSize}`);
let context = featureAbility.getContext();
let path;
async function getCacheDir(){
  path = await context.getCacheDir();
}
let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
G
Gloria 已提交
4779 4780
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4781
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4782
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4783 4784
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4785 4786
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4787 4788 4789
    }
    let readsize = await fs.read(file.fd, buf, options)
    try{
G
Gloria 已提交
4790
       let writeSize = await audioRenderer.write(buf);
G
Gloria 已提交
4791 4792 4793 4794
    } catch(err) {
       console.error(`audioRenderer.write err: ${err}`);
    }   
}
G
Gloria 已提交
4795

V
Vaidegi B 已提交
4796 4797
```

4798
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4799

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

4802
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 已提交
4803

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

W
wusongqing 已提交
4806
**Parameters**
V
Vaidegi B 已提交
4807

4808 4809 4810
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
V
Vaidegi B 已提交
4811

W
wusongqing 已提交
4812
**Example**
V
Vaidegi B 已提交
4813

G
Gloria 已提交
4814
```js
4815
audioRenderer.getAudioTime((err, timestamp) => {
4816
  console.info(`Current timestamp: ${timestamp}`);
4817
});
G
Gloria 已提交
4818

V
Vaidegi B 已提交
4819 4820
```

4821
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4822

4823
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4824

4825
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4826

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

W
wusongqing 已提交
4829
**Return value**
V
Vaidegi B 已提交
4830

4831
| Type             | Description                           |
4832 4833
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4834

W
wusongqing 已提交
4835
**Example**
V
Vaidegi B 已提交
4836

G
Gloria 已提交
4837
```js
4838 4839
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4840
}).catch((err) => {
4841
  console.error(`ERROR: ${err}`);
4842
});
G
Gloria 已提交
4843

V
Vaidegi B 已提交
4844 4845
```

4846
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4847

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

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

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

W
wusongqing 已提交
4854
**Parameters**
V
Vaidegi B 已提交
4855

4856
| Name     | Type                   | Mandatory | Description                              |
4857 4858
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4859

W
wusongqing 已提交
4860
**Example**
V
Vaidegi B 已提交
4861

G
Gloria 已提交
4862
```js
4863 4864 4865
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4866
  }
4867
});
G
Gloria 已提交
4868

V
Vaidegi B 已提交
4869 4870
```

4871
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4872

4873
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4874

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

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

W
wusongqing 已提交
4879
**Return value**
V
Vaidegi B 已提交
4880

4881
| Type             | Description                             |
4882 4883
| ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4884

W
wusongqing 已提交
4885
**Example**
V
Vaidegi B 已提交
4886

G
Gloria 已提交
4887
```js
4888
let bufferSize;
4889 4890
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4891
  bufferSize = data;
4892
}).catch((err) => {
4893
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4894
});
G
Gloria 已提交
4895

V
Vaidegi B 已提交
4896 4897
```

4898
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4899

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

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

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

W
wusongqing 已提交
4906
**Parameters**
V
Vaidegi B 已提交
4907

4908 4909 4910 4911
| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4912

W
wusongqing 已提交
4913
**Example**
V
Vaidegi B 已提交
4914

G
Gloria 已提交
4915
```js
4916 4917 4918 4919 4920
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.');
4921
  }
4922
});
G
Gloria 已提交
4923

V
Vaidegi B 已提交
4924 4925
```

4926
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4927

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

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

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

W
wusongqing 已提交
4934
**Parameters**
V
Vaidegi B 已提交
4935

4936 4937 4938 4939 4940 4941 4942 4943 4944
| 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 已提交
4945

W
wusongqing 已提交
4946
**Example**
V
Vaidegi B 已提交
4947

G
Gloria 已提交
4948
```js
4949 4950 4951 4952
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4953
});
G
Gloria 已提交
4954

V
Vaidegi B 已提交
4955 4956
```

4957
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4958

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

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

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

4965
**Parameters**
V
Vaidegi B 已提交
4966

4967 4968 4969
| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
4970

W
wusongqing 已提交
4971
**Example**
V
Vaidegi B 已提交
4972

G
Gloria 已提交
4973
```js
4974 4975 4976
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
G
Gloria 已提交
4977

V
Vaidegi B 已提交
4978 4979
```

4980
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4981

4982
getRenderRate(): Promise\<AudioRendererRate>
V
Vaidegi B 已提交
4983

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

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

4988
**Return value**
V
Vaidegi B 已提交
4989

4990 4991 4992
| Type                                              | Description                                   |
| ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
V
Vaidegi B 已提交
4993

W
wusongqing 已提交
4994
**Example**
V
Vaidegi B 已提交
4995

G
Gloria 已提交
4996
```js
4997 4998 4999 5000
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5001
});
G
Gloria 已提交
5002

V
Vaidegi B 已提交
5003
```
G
Gloria 已提交
5004

5005
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
5006

5007
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
5008

5009
Sets the audio interruption mode for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
5010

5011
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
5012

5013
**Parameters**
V
Vaidegi B 已提交
5014

5015 5016 5017
| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
V
Vaidegi B 已提交
5018

5019
**Return value**
5020

5021 5022 5023
| 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 已提交
5024

5025
**Example**
V
Vaidegi B 已提交
5026

5027 5028 5029 5030 5031 5032 5033
```js
let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{
  console.info('setInterruptMode Success!');
}).catch((err) => {
  console.error(`setInterruptMode Fail: ${err}`);
});
G
Gloria 已提交
5034

5035
```
G
Gloria 已提交
5036

5037 5038 5039 5040 5041 5042 5043
### 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 已提交
5044

W
wusongqing 已提交
5045
**Parameters**
V
Vaidegi B 已提交
5046

5047 5048 5049 5050
| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5051

W
wusongqing 已提交
5052
**Example**
V
Vaidegi B 已提交
5053

G
Gloria 已提交
5054
```js
5055 5056 5057 5058
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
5059
  }
5060
  console.info('setInterruptMode Success!');
5061
});
G
Gloria 已提交
5062

V
Vaidegi B 已提交
5063 5064
```

5065
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
5066

5067
setVolume(volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
5068

5069
Sets the volume for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
5070

5071
**System capability**: SystemCapability.Multimedia.Audio.Renderer
5072 5073 5074

**Parameters**

5075 5076 5077
| Name   | Type   | Mandatory | Description                                                  |
| ------ | ------ | --------- | ------------------------------------------------------------ |
| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
5078

W
wusongqing 已提交
5079
**Return value**
V
Vaidegi B 已提交
5080

5081 5082 5083
| 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 已提交
5084

W
wusongqing 已提交
5085
**Example**
V
Vaidegi B 已提交
5086

G
Gloria 已提交
5087
```js
5088 5089 5090 5091
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
5092
});
G
Gloria 已提交
5093

V
Vaidegi B 已提交
5094
```
G
Gloria 已提交
5095

5096
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
5097

5098
setVolume(volume: number, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
5099

5100
Sets the volume for the application. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5101

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

W
wusongqing 已提交
5104
**Parameters**
V
Vaidegi B 已提交
5105

5106 5107 5108 5109
| 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 已提交
5110

W
wusongqing 已提交
5111
**Example**
V
Vaidegi B 已提交
5112

G
Gloria 已提交
5113
```js
5114 5115 5116
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
5117
  }
5118
  console.info('setVolume Success!');
5119
});
G
Gloria 已提交
5120

V
Vaidegi B 已提交
5121 5122
```

5123
### on('audioInterrupt')<sup>9+</sup>
V
Vaidegi B 已提交
5124

5125
on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
5126

5127
Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
5128

5129
Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioRenderer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
V
Vaidegi B 已提交
5130

5131
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
5132

5133 5134
**Parameters**

5135 5136 5137 5138
| Name     | Type                                           | Mandatory | Description                                                  |
| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                         | Yes       | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio rendering is interrupted. |
| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event.        |
5139 5140 5141 5142 5143 5144 5145

**Error codes**

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

| ID      | Error Message                  |
| ------- | ------------------------------ |
G
Gloria 已提交
5146
| 6800101 | if input parameter value error |
V
Vaidegi B 已提交
5147

W
wusongqing 已提交
5148
**Example**
V
Vaidegi B 已提交
5149

G
Gloria 已提交
5150
```js
5151 5152
let isPlaying; // An identifier specifying whether rendering is in progress.
let isDucked; // An identifier specifying whether the audio volume is reduced.
5153 5154 5155 5156 5157
onAudioInterrupt();

async function onAudioInterrupt(){
  audioRenderer.on('audioInterrupt', async(interruptEvent) => {
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
5158
      // The system forcibly interrupts audio rendering. The application must update the status and displayed content accordingly.
5159 5160
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
5161 5162 5163
          // The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
          console.info('Force paused. Update playing status and stop writing');
          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
5164 5165
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181
          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume rendering.
          console.info('Force stopped. Update playing status and stop writing');
          isPlaying = false; // A simplified processing indicating several operations for switching the application to the paused state.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
          // The audio stream is rendered at a reduced volume.
          console.info('Force ducked. Update volume status');
          isDucked = true; // A simplified processing indicating several operations for updating the volume status.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
          // The audio stream is rendered at the normal volume.
          console.info('Force ducked. Update volume status');
          isDucked = false; // A simplified processing indicating several operations for updating the volume status.
          break;
        default:
          console.info('Invalid interruptEvent');
5182 5183 5184
          break;
      }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
5185
      // The application can choose to take action or ignore.
5186 5187
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
5188
          // It is recommended that the application continue rendering. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume rendering now.)
5189
          console.info('Resume force paused renderer or ignore');
5190
          // To continue rendering, the application must perform the required operations.
5191 5192
          break;
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
5193
          // It is recommended that the application pause rendering.
5194
          console.info('Choose to pause or ignore');
5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212
          // To pause rendering, the application must perform the required operations.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
          // It is recommended that the application stop rendering.
          console.info('Choose to stop or ignore');
          // To stop rendering, the application must perform the required operations.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_DUCK:
          // It is recommended that the application reduce the volume for rendering.
          console.info('Choose to duck or ignore');
          // To decrease the volume for rendering, the application must perform the required operations.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_UNDUCK:
          // It is recommended that the application resume rendering at the normal volume.
          console.info('Choose to unduck or ignore');
          // To resume rendering at the normal volume, the application must perform the required operations.
          break;
        default:
5213 5214 5215 5216 5217
          break;
      }
   }
  });
}
G
Gloria 已提交
5218

V
Vaidegi B 已提交
5219 5220
```

5221
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
5222

5223
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5224

5225
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 已提交
5226

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

W
wusongqing 已提交
5229
**Parameters**
5230

5231 5232 5233 5234 5235
| 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 已提交
5236

W
wusongqing 已提交
5237
**Example**
V
Vaidegi B 已提交
5238

G
Gloria 已提交
5239
```js
5240 5241 5242
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5243
  }
5244
});
G
Gloria 已提交
5245

V
Vaidegi B 已提交
5246 5247 5248
```


5249
### off('markReach') <sup>8+</sup>
5250

5251
off(type: 'markReach'): void
V
Vaidegi B 已提交
5252

5253
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5254

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

5257 5258 5259 5260 5261
**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
5262

W
wusongqing 已提交
5263
**Example**
V
Vaidegi B 已提交
5264

G
Gloria 已提交
5265
```js
5266
audioRenderer.off('markReach');
G
Gloria 已提交
5267

V
Vaidegi B 已提交
5268 5269
```

5270
### on('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5271

5272
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5273

5274
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 已提交
5275

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

W
wusongqing 已提交
5278
**Parameters**
5279

5280 5281 5282 5283 5284
| 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 已提交
5285

W
wusongqing 已提交
5286
**Example**
V
Vaidegi B 已提交
5287

G
Gloria 已提交
5288
```js
5289 5290 5291
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5292
  }
5293
});
G
Gloria 已提交
5294

V
Vaidegi B 已提交
5295 5296
```

5297
### off('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5298

5299
off(type: 'periodReach'): void
5300

5301
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5302

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

5305
**Parameters**
V
Vaidegi B 已提交
5306

5307 5308 5309
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
5310

W
wusongqing 已提交
5311
**Example**
V
Vaidegi B 已提交
5312

G
Gloria 已提交
5313
```js
5314
audioRenderer.off('periodReach')
G
Gloria 已提交
5315

V
Vaidegi B 已提交
5316
```
5317

G
Gloria 已提交
5318
### on('stateChange')<sup>8+</sup>
W
wusongqing 已提交
5319

5320
on(type: 'stateChange', callback: Callback<AudioState\>): void
W
wusongqing 已提交
5321

5322
Subscribes to state change events.
W
wusongqing 已提交
5323

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

5326
**Parameters**
W
wusongqing 已提交
5327

5328 5329 5330 5331
| 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 已提交
5332

5333
**Example**
W
wusongqing 已提交
5334

5335 5336 5337 5338 5339 5340 5341 5342 5343
```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');
  }
});
G
Gloria 已提交
5344

5345
```
5346

5347
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5348

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

5351
### Attributes
5352

5353
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5354

5355 5356 5357
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
V
Vaidegi B 已提交
5358

5359
**Example**
V
Vaidegi B 已提交
5360

5361 5362
```js
let state = audioCapturer.state;
G
Gloria 已提交
5363

5364
```
V
Vaidegi B 已提交
5365

5366
### getCapturerInfo<sup>8+</sup>
5367

5368
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5369

5370
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5371

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

W
wusongqing 已提交
5374
**Parameters**
5375

5376 5377 5378
| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
5379

W
wusongqing 已提交
5380
**Example**
5381

G
Gloria 已提交
5382
```js
5383
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5384
  if (err) {
5385 5386 5387 5388 5389
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5390
  }
5391
});
G
Gloria 已提交
5392

5393 5394
```

5395

5396
### getCapturerInfo<sup>8+</sup>
5397

5398
getCapturerInfo(): Promise<AudioCapturerInfo\>
5399

5400
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
5401

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

5404
**Return value**
5405

5406 5407 5408
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
5409

W
wusongqing 已提交
5410
**Example**
5411

G
Gloria 已提交
5412
```js
5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423
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}`);
5424
});
G
Gloria 已提交
5425

5426 5427
```

5428
### getStreamInfo<sup>8+</sup>
5429

5430
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5431

5432
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5433

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

W
wusongqing 已提交
5436
**Parameters**
5437

5438 5439 5440
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5441

W
wusongqing 已提交
5442
**Example**
5443

G
Gloria 已提交
5444
```js
5445
audioCapturer.getStreamInfo((err, streamInfo) => {
5446
  if (err) {
5447 5448 5449 5450 5451 5452 5453
    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}`);
5454
  }
5455
});
G
Gloria 已提交
5456

5457 5458
```

5459
### getStreamInfo<sup>8+</sup>
5460

5461
getStreamInfo(): Promise<AudioStreamInfo\>
5462

5463
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
5464

5465
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5466 5467 5468

**Return value**

5469 5470 5471
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5472

W
wusongqing 已提交
5473
**Example**
5474

G
Gloria 已提交
5475
```js
5476 5477 5478 5479 5480 5481 5482 5483
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}`);
5484
});
G
Gloria 已提交
5485

5486
```
V
Vaidegi B 已提交
5487

5488
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5489

5490
getAudioStreamId(callback: AsyncCallback<number\>): void
V
Vaidegi B 已提交
5491

5492
Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5493

5494
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5495

W
wusongqing 已提交
5496
**Parameters**
5497

5498 5499 5500
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5501

W
wusongqing 已提交
5502
**Example**
5503

G
Gloria 已提交
5504
```js
5505 5506
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5507
});
G
Gloria 已提交
5508

5509
```
V
Vaidegi B 已提交
5510

5511
### getAudioStreamId<sup>9+</sup>
5512

5513 5514 5515
getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
5516

5517
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5518 5519 5520

**Return value**

5521 5522 5523
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
5524

W
wusongqing 已提交
5525
**Example**
V
Vaidegi B 已提交
5526

G
Gloria 已提交
5527
```js
5528 5529 5530 5531
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5532
});
G
Gloria 已提交
5533

V
Vaidegi B 已提交
5534 5535
```

5536
### start<sup>8+</sup>
V
Vaidegi B 已提交
5537

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

5540
Starts capturing. This API uses an asynchronous callback to return the result.
5541

5542
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5543

W
wusongqing 已提交
5544
**Parameters**
V
Vaidegi B 已提交
5545

5546 5547 5548
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5549

W
wusongqing 已提交
5550
**Example**
V
Vaidegi B 已提交
5551

G
Gloria 已提交
5552
```js
5553
audioCapturer.start((err) => {
5554
  if (err) {
5555 5556 5557
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5558
  }
5559
});
G
Gloria 已提交
5560

V
Vaidegi B 已提交
5561 5562 5563
```


5564
### start<sup>8+</sup>
V
Vaidegi B 已提交
5565

5566
start(): Promise<void\>
5567

5568
Starts capturing. This API uses a promise to return the result.
5569

5570
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5571

W
wusongqing 已提交
5572
**Return value**
V
Vaidegi B 已提交
5573

5574 5575 5576
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5577

W
wusongqing 已提交
5578
**Example**
V
Vaidegi B 已提交
5579

G
Gloria 已提交
5580
```js
5581 5582 5583 5584 5585 5586 5587 5588 5589 5590
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}`);
5591
});
G
Gloria 已提交
5592

5593
```
V
Vaidegi B 已提交
5594

5595
### stop<sup>8+</sup>
5596

5597
stop(callback: AsyncCallback<void\>): void
5598

5599
Stops capturing. This API uses an asynchronous callback to return the result.
5600

5601
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5602

W
wusongqing 已提交
5603
**Parameters**
V
Vaidegi B 已提交
5604

5605 5606 5607
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5608

W
wusongqing 已提交
5609
**Example**
V
Vaidegi B 已提交
5610

G
Gloria 已提交
5611
```js
5612
audioCapturer.stop((err) => {
5613
  if (err) {
5614 5615 5616
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5617
  }
5618
});
G
Gloria 已提交
5619

V
Vaidegi B 已提交
5620 5621
```

5622

5623
### stop<sup>8+</sup>
5624

5625
stop(): Promise<void\>
5626

5627
Stops capturing. This API uses a promise to return the result.
5628

5629
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5630

W
wusongqing 已提交
5631
**Return value**
V
Vaidegi B 已提交
5632

5633 5634 5635
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5636

W
wusongqing 已提交
5637
**Example**
V
Vaidegi B 已提交
5638

G
Gloria 已提交
5639
```js
5640 5641 5642 5643 5644 5645 5646 5647
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}`);
5648
});
G
Gloria 已提交
5649

V
Vaidegi B 已提交
5650 5651
```

5652
### release<sup>8+</sup>
V
Vaidegi B 已提交
5653

5654
release(callback: AsyncCallback<void\>): void
5655

5656
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5657

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

W
wusongqing 已提交
5660
**Parameters**
5661

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

W
wusongqing 已提交
5666
**Example**
5667

G
Gloria 已提交
5668
```js
5669
audioCapturer.release((err) => {
5670
  if (err) {
5671 5672 5673
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5674
  }
5675
});
G
Gloria 已提交
5676

5677 5678 5679
```


5680
### release<sup>8+</sup>
5681

5682
release(): Promise<void\>
5683

5684
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5685

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

W
wusongqing 已提交
5688
**Return value**
5689

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

W
wusongqing 已提交
5694
**Example**
5695

G
Gloria 已提交
5696
```js
5697 5698 5699 5700 5701 5702 5703 5704
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}`);
5705
});
G
Gloria 已提交
5706

5707 5708
```

5709
### read<sup>8+</sup>
5710

5711
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
5712

5713
Reads the buffer. This API uses an asynchronous callback to return the result.
5714

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

W
wusongqing 已提交
5717
**Parameters**
5718

5719 5720 5721 5722 5723
| 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.  |
5724

W
wusongqing 已提交
5725
**Example**
5726

G
Gloria 已提交
5727
```js
5728 5729 5730 5731 5732 5733 5734 5735 5736 5737
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');
5738
  }
5739
});
G
Gloria 已提交
5740

5741 5742
```

5743
### read<sup>8+</sup>
5744

5745
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5746

5747
Reads the buffer. This API uses a promise to return the result.
5748

5749
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5750 5751 5752

**Parameters**

5753 5754 5755 5756
| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
5757

W
wusongqing 已提交
5758
**Return value**
5759

5760 5761 5762
| 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. |
5763

W
wusongqing 已提交
5764
**Example**
5765

G
Gloria 已提交
5766
```js
5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778
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}`);
5779
});
G
Gloria 已提交
5780

5781
```
5782

5783
### getAudioTime<sup>8+</sup>
5784

5785
getAudioTime(callback: AsyncCallback<number\>): void
5786

5787 5788 5789
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
5790

W
wusongqing 已提交
5791
**Parameters**
5792

5793 5794 5795
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
5796

W
wusongqing 已提交
5797
**Example**
5798

G
Gloria 已提交
5799
```js
5800 5801
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5802
});
G
Gloria 已提交
5803

5804 5805
```

5806
### getAudioTime<sup>8+</sup>
5807

5808
getAudioTime(): Promise<number\>
5809

5810
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
5811

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

W
wusongqing 已提交
5814
**Return value**
5815

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

W
wusongqing 已提交
5820
**Example**
5821

G
Gloria 已提交
5822
```js
5823 5824 5825 5826
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5827
});
G
Gloria 已提交
5828

5829 5830
```

5831
### getBufferSize<sup>8+</sup>
5832

5833
getBufferSize(callback: AsyncCallback<number\>): void
5834

5835
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
5836

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

W
wusongqing 已提交
5839
**Parameters**
5840

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

W
wusongqing 已提交
5845
**Example**
5846

G
Gloria 已提交
5847
```js
5848 5849 5850 5851 5852 5853 5854 5855
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}`);
    });
5856
  }
J
jiao_yanlin 已提交
5857
});
G
Gloria 已提交
5858

5859 5860
```

5861
### getBufferSize<sup>8+</sup>
5862

5863
getBufferSize(): Promise<number\>
5864

5865
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
5866

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

W
wusongqing 已提交
5869
**Return value**
5870

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

W
wusongqing 已提交
5875
**Example**
5876

G
Gloria 已提交
5877
```js
5878 5879 5880 5881 5882 5883
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5884
});
G
Gloria 已提交
5885

5886 5887
```

5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965
### on('audioInterrupt')<sup>10+</sup>

on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void

Subscribes to audio interruption events. This API uses a callback to get interrupt events.

Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioCapturer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.

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

**Parameters**

| Name     | Type                                           | Mandatory | Description                                                  |
| -------- | ---------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                         | Yes       | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio capturing is interrupted. |
| callback | Callback\<[InterruptEvent](#interruptevent9)\> | Yes       | Callback used to return the audio interruption event.        |

**Error codes**

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

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

**Example**

```js
let isCapturing; // An identifier specifying whether capturing is in progress.
onAudioInterrupt();

async function onAudioInterrupt(){
  audioCapturer.on('audioInterrupt', async(interruptEvent) => {
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
      // The system forcibly interrupts audio capturing. The application must update the status and displayed content accordingly.
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
          // The audio stream has been paused and temporarily loses the focus. It will receive the interruptEvent corresponding to resume when it is able to regain the focus.
          console.info('Force paused. Update capturing status and stop reading');
          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
          // The audio stream has been stopped and permanently loses the focus. The user must manually trigger the operation to resume capturing.
          console.info('Force stopped. Update capturing status and stop reading');
          isCapturing = false; // A simplified processing indicating several operations for switching the application to the paused state.
          break;
        default:
          console.info('Invalid interruptEvent');
          break;
      }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
      // The application can choose to take action or ignore.
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
          // It is recommended that the application continue capturing. (The audio stream has been forcibly paused and temporarily lost the focus. It can resume capturing now.)
          console.info('Resume force paused renderer or ignore');
          // To continue capturing, the application must perform the required operations.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
          // It is recommended that the application pause capturing.
          console.info('Choose to pause or ignore');
          // To pause capturing, the application must perform the required operations.
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
          // It is recommended that the application stop capturing.
          console.info('Choose to stop or ignore');
          // To stop capturing, the application must perform the required operations.
          break;
        default:
          break;
      }
   }
  });
}

```


5966
### on('markReach')<sup>8+</sup>
5967

5968
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
5969

5970
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
5971

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

W
wusongqing 已提交
5974
**Parameters**
5975

5976 5977 5978 5979 5980
| 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.                |
5981

W
wusongqing 已提交
5982
**Example**
5983

G
Gloria 已提交
5984
```js
5985 5986 5987
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5988
  }
5989
});
G
Gloria 已提交
5990

5991 5992
```

5993
### off('markReach')<sup>8+</sup>
5994

5995
off(type: 'markReach'): void
5996

5997
Unsubscribes from mark reached events.
5998

5999
**System capability**: SystemCapability.Multimedia.Audio.Capturer
6000 6001 6002

**Parameters**

6003 6004 6005
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
6006

W
wusongqing 已提交
6007
**Example**
6008

G
Gloria 已提交
6009
```js
6010
audioCapturer.off('markReach');
G
Gloria 已提交
6011

6012 6013
```

6014
### on('periodReach')<sup>8+</sup>
6015

6016
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
6017

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

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

W
wusongqing 已提交
6022
**Parameters**
6023

6024 6025 6026 6027 6028
| 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.                |
6029

W
wusongqing 已提交
6030
**Example**
6031

G
Gloria 已提交
6032
```js
6033 6034 6035
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
6036
  }
6037
});
G
Gloria 已提交
6038

6039 6040
```

6041
### off('periodReach')<sup>8+</sup>
6042

6043
off(type: 'periodReach'): void
6044

6045
Unsubscribes from period reached events.
6046

6047
**System capability**: SystemCapability.Multimedia.Audio.Capturer
6048 6049 6050

**Parameters**

6051 6052 6053
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
6054

W
wusongqing 已提交
6055
**Example**
6056

G
Gloria 已提交
6057
```js
6058
audioCapturer.off('periodReach')
G
Gloria 已提交
6059

6060 6061
```

G
Gloria 已提交
6062
### on('stateChange')<sup>8+</sup>
6063

6064
on(type: 'stateChange', callback: Callback<AudioState\>): void
6065

6066
Subscribes to state change events.
6067

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

W
wusongqing 已提交
6070
**Parameters**
6071

6072 6073 6074 6075
| 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.                    |
6076

W
wusongqing 已提交
6077
**Example**
6078

G
Gloria 已提交
6079
```js
6080 6081 6082 6083 6084 6085
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');
6086
  }
6087
});
G
Gloria 已提交
6088

6089 6090
```

6091
## ToneType<sup>9+</sup>
6092

6093
Enumerates the tone types of the player.
6094

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

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

6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127
| 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.          |
6128

6129
## TonePlayer<sup>9+</sup>
6130

6131
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
6132

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

6135
### load<sup>9+</sup>
6136

6137
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
6138

6139
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
6140

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

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

W
wusongqing 已提交
6145
**Parameters**
6146

6147 6148 6149 6150
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
6151

W
wusongqing 已提交
6152
**Example**
6153

G
Gloria 已提交
6154
```js
6155
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
6156
  if (err) {
6157
    console.error(`callback call load failed error: ${err.message}`);
6158
    return;
6159 6160
  } else {
    console.info('callback call load success');
6161 6162
  }
});
G
Gloria 已提交
6163

6164 6165
```

6166
### load<sup>9+</sup>
6167

6168
load(type: ToneType): Promise&lt;void&gt;
6169

6170
Loads the DTMF tone configuration. This API uses a promise to return the result.
6171

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

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

W
wusongqing 已提交
6176
**Parameters**
6177

6178 6179 6180
| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
6181 6182 6183

**Return value**

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

W
wusongqing 已提交
6188
**Example**
6189

G
Gloria 已提交
6190
```js
6191 6192 6193 6194
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
6195
});
G
Gloria 已提交
6196

6197
```
6198

6199
### start<sup>9+</sup>
6200

6201
start(callback: AsyncCallback&lt;void&gt;): void
6202

6203
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
6204

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

6207
**System capability**: SystemCapability.Multimedia.Audio.Tone
6208 6209 6210

**Parameters**

6211 6212 6213
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6214 6215 6216 6217

**Example**

```js
6218
tonePlayer.start((err) => {
6219
  if (err) {
6220
    console.error(`callback call start failed error: ${err.message}`);
6221
    return;
6222 6223
  } else {
    console.info('callback call start success');
6224 6225
  }
});
G
Gloria 已提交
6226

6227 6228
```

6229
### start<sup>9+</sup>
6230

6231
start(): Promise&lt;void&gt;
6232

6233
Starts DTMF tone playing. This API uses a promise to return the result.
6234

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

6237
**System capability**: SystemCapability.Multimedia.Audio.Tone
6238 6239 6240

**Return value**

6241 6242 6243
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6244 6245 6246 6247

**Example**

```js
6248 6249 6250 6251
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
6252
});
G
Gloria 已提交
6253

6254 6255
```

6256
### stop<sup>9+</sup>
6257

6258
stop(callback: AsyncCallback&lt;void&gt;): void
6259

6260
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
6261 6262 6263

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

6264
**System capability**: SystemCapability.Multimedia.Audio.Tone
6265 6266 6267

**Parameters**

6268 6269 6270
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6271 6272 6273 6274

**Example**

```js
6275 6276 6277 6278 6279 6280 6281
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
6282
});
G
Gloria 已提交
6283

6284 6285
```

6286
### stop<sup>9+</sup>
6287

6288
stop(): Promise&lt;void&gt;
6289

6290
Stops the tone that is being played. This API uses a promise to return the result.
6291

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

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

6296
**Return value**
6297

6298 6299 6300
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6301 6302 6303 6304

**Example**

```js
6305 6306 6307 6308
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
6309
});
G
Gloria 已提交
6310

6311 6312
```

6313
### release<sup>9+</sup>
6314

6315
release(callback: AsyncCallback&lt;void&gt;): void
6316

6317
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
6318

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

6321
**System capability**: SystemCapability.Multimedia.Audio.Tone
6322 6323 6324

**Parameters**

6325 6326 6327
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6328 6329 6330 6331

**Example**

```js
6332 6333 6334 6335 6336 6337 6338
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6339
});
G
Gloria 已提交
6340

6341 6342
```

6343
### release<sup>9+</sup>
6344

6345
release(): Promise&lt;void&gt;
6346

6347
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
6348

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

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

6353
**Return value**
6354

6355 6356 6357
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6358 6359 6360 6361

**Example**

```js
6362 6363 6364 6365
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6366
});
G
Gloria 已提交
6367

6368 6369
```

6370
## ActiveDeviceType<sup>(deprecated)</sup>
6371

6372
Enumerates the active device types.
6373

6374 6375 6376
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6377

6378 6379 6380 6381 6382 6383 6384 6385 6386 6387
**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.
6388 6389 6390 6391 6392 6393

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

6395 6396 6397 6398
| Name           | Value | Description               |
| -------------- | ----- | ------------------------- |
| TYPE_ACTIVATED | 0     | Focus gain event.         |
| TYPE_INTERRUPT | 1     | Audio interruption event. |
6399

6400
## AudioInterrupt<sup>(deprecated)</sup>
6401

6402
Describes input parameters of audio interruption events.
6403

6404 6405 6406
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6407

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

6410 6411 6412 6413 6414
| 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. |
6415

6416
## InterruptAction<sup>(deprecated)</sup>
6417

6418
Describes the callback invoked for audio interruption or focus gain events.
6419

6420 6421
> **NOTE**
>
6422
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [InterruptEvent](#interruptevent9).
6423

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

6426 6427 6428 6429 6430 6431
| 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. |