js-apis-audio.md 240.5 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
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,
G
Gloria 已提交
3556
    displayName : "",
3557
}];
3558

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

3569
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3570

3571
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3572

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

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

**Return value**

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

**Example**

G
Gloria 已提交
3593
```js
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,
G
Gloria 已提交
3606
    displayName : "",
3607
}];
3608

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

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

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

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

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

3626
**Parameters**
3627

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

**Example**

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

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

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

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

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

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

**Example**

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

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

**Parameters**

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

**Example**
```js
3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760
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,
G
Gloria 已提交
3761
    displayName : "",
3762
}];
3763

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

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

```js
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810
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,
G
Gloria 已提交
3811
    displayName : "",
3812
}];
3813

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

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

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

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

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

**Parameters**

3835 3836 3837 3838 3839
| 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.|
3840 3841 3842

**Example**
```js
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
  
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
G
Gloria 已提交
3863
    displayName : "",
3864
}];
3865

3866 3867 3868 3869 3870 3871 3872 3873
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'); }
  });
}
3874 3875
```

3876
### selectOutputDeviceByFilter<sup>9+</sup>
3877

3878
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3879

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

3882 3883 3884
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
3885 3886 3887

**Parameters**

3888 3889 3890 3891
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3892 3893 3894

**Return value**

3895 3896 3897
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3898 3899 3900 3901

**Example**

```js
3902 3903 3904 3905 3906 3907 3908
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3909

3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921
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,
G
Gloria 已提交
3922
    displayName : "",
3923
}];
3924

3925 3926 3927 3928 3929 3930 3931 3932
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}`);
  })
}
```
3933

G
Gloria 已提交
3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953
### 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,
3954
    rendererFlags : 0 }
G
Gloria 已提交
3955 3956 3957 3958

async function getPreferOutputDevice() {
  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (err, desc) => {
    if (err) {
3959
      console.error(`Result ERROR: ${err}`);
G
Gloria 已提交
3960
    } else {
3961
      console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
3962 3963 3964 3965 3966
    }
  });
}
```

3967
### getPreferOutputDeviceForRendererInfo<sup>10+</sup>
G
Gloria 已提交
3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985
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.|

3986 3987 3988 3989 3990 3991 3992 3993
**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 已提交
3994 3995 3996 3997 3998 3999
**Example**

```js
let rendererInfo = {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
4000
    rendererFlags : 0 }
G
Gloria 已提交
4001 4002 4003

async function getPreferOutputDevice() {
  audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc) => {
4004
    console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
4005
  }).catch((err) => {
4006
    console.error(`Result ERROR: ${err}`);
G
Gloria 已提交
4007 4008 4009 4010 4011 4012 4013 4014 4015 4016
  })
}
```

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

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

G
Gloria 已提交
4019 4020 4021 4022 4023 4024 4025 4026
**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.                        |

4027 4028 4029 4030 4031 4032 4033 4034
**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 已提交
4035 4036 4037 4038 4039 4040
**Example**

```js
let rendererInfo = {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
4041
    rendererFlags : 0 }
G
Gloria 已提交
4042 4043

audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc) => {
4044
  console.info(`device descriptor: ${desc}`);
G
Gloria 已提交
4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062
});
```

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

4063 4064 4065 4066 4067 4068 4069 4070
**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 已提交
4071 4072 4073 4074 4075 4076 4077 4078
**Example**

```js
audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', () => {
  console.info('Should be no callback.');
});
```

4079
## AudioRendererChangeInfoArray<sup>9+</sup>
4080

4081
Defines an **AudioRenderChangeInfo** array, which is read-only.
4082 4083 4084

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

4085
## AudioRendererChangeInfo<sup>9+</sup>
4086

4087 4088 4089 4090
Describes the audio renderer change event.

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

G
Gloria 已提交
4091 4092 4093 4094 4095 4096 4097
| 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.|
4098 4099 4100 4101

**Example**

```js
G
Gloria 已提交
4102

4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132
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}`);
    }
4133 4134 4135 4136 4137
  }
});
```


4138
## AudioCapturerChangeInfoArray<sup>9+</sup>
4139

4140
Defines an **AudioCapturerChangeInfo** array, which is read-only.
4141

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

4144
## AudioCapturerChangeInfo<sup>9+</sup>
4145

4146
Describes the audio capturer change event.
4147

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

G
Gloria 已提交
4150 4151 4152 4153 4154 4155 4156
| 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.|
4157 4158 4159 4160

**Example**

```js
4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184
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}`);
4185
    }
4186 4187 4188
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4189 4190 4191 4192 4193
    }
  }
});
```

4194
## AudioDeviceDescriptors
4195

4196
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
4197

4198
## AudioDeviceDescriptor
4199

4200
Describes an audio device.
4201

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

G
Gloria 已提交
4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217
| Name                         | Type                      | Readable| Writable| Description      |
| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
| deviceRole                    | [DeviceRole](#devicerole)  | Yes  | No  | Device role.|
| deviceType                    | [DeviceType](#devicetype)  | Yes  | No  | Device type.|
| id<sup>9+</sup>               | number                     | Yes  | No  | Device ID, which is unique. |
| 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.|
| displayName<sup>10+</sup>     | string                     | Yes  | No  | Display name of the device.|
| 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.|
4218 4219 4220 4221

**Example**

```js
4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238
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');
4239 4240 4241 4242
  }
});
```

4243
## AudioRendererFilter<sup>9+</sup>
4244

4245
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4246

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

G
Gloria 已提交
4249 4250 4251 4252 4253
| Name         | Type                                    | Mandatory| Description         |
| -------------| ---------------------------------------- | ---- | -------------- |
| uid          | number                                   |  No | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) |  No | Audio renderer information.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer|
| rendererId   | number                                   |  No | Unique ID of an audio stream.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer|
4254

4255
**Example**
4256

4257 4258 4259 4260 4261 4262 4263 4264 4265
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4266

4267 4268 4269 4270 4271 4272 4273 4274
## 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

G
Gloria 已提交
4275 4276 4277
| Name | Type                    | Readable| Writable| Description              |
| ----- | -------------------------- | ---- | ---- | ------------------ |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes  | No  | Audio renderer state.|
4278 4279 4280 4281

**Example**

```js
4282
let state = audioRenderer.state;
4283 4284
```

4285
### getRendererInfo<sup>8+</sup>
4286

4287
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4288

4289
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4290 4291 4292 4293 4294

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

**Parameters**

G
Gloria 已提交
4295 4296 4297
| Name  | Type                                                    | Mandatory| Description                  |
| :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes  | Callback used to return the renderer information.|
4298 4299 4300 4301

**Example**

```js
4302 4303 4304 4305 4306
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}`);
4307 4308 4309
});
```

4310
### getRendererInfo<sup>8+</sup>
4311

4312
getRendererInfo(): Promise<AudioRendererInfo\>
4313

4314
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4315 4316 4317

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

4318
**Return value**
4319

G
Gloria 已提交
4320 4321 4322
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
4323 4324 4325 4326

**Example**

```js
4327 4328 4329 4330 4331 4332 4333 4334
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}`);
});
4335 4336
```

4337
### getStreamInfo<sup>8+</sup>
4338

4339
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4340

4341
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4342 4343 4344 4345 4346

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

**Parameters**

G
Gloria 已提交
4347 4348 4349
| Name  | Type                                                | Mandatory| Description                |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
4350 4351 4352 4353

**Example**

```js
4354 4355 4356 4357 4358 4359
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}`);
4360 4361 4362
});
```

4363
### getStreamInfo<sup>8+</sup>
4364

4365
getStreamInfo(): Promise<AudioStreamInfo\>
4366

4367
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
4368

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

4371 4372
**Return value**

G
Gloria 已提交
4373 4374 4375
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
4376 4377 4378 4379

**Example**

```js
4380 4381 4382 4383 4384 4385 4386 4387 4388
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}`);
});
4389
```
4390

4391
### getAudioStreamId<sup>9+</sup>
4392

4393
getAudioStreamId(callback: AsyncCallback<number\>): void
4394

4395
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4396

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

4399 4400
**Parameters**

G
Gloria 已提交
4401 4402 4403
| Name  | Type                                                | Mandatory| Description                |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the stream ID.|
4404

4405 4406
**Example**

G
Gloria 已提交
4407
```js
4408 4409
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4410
});
4411 4412
```

4413
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4414

4415
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4416

4417
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4418

4419
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4420 4421

**Return value**
V
Vaidegi B 已提交
4422

G
Gloria 已提交
4423 4424 4425
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<number\> | Promise used to return the stream ID.|
V
Vaidegi B 已提交
4426

W
wusongqing 已提交
4427
**Example**
V
Vaidegi B 已提交
4428

G
Gloria 已提交
4429
```js
4430 4431
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4432
}).catch((err) => {
4433
  console.error(`ERROR: ${err}`);
4434 4435
});
```
V
Vaidegi B 已提交
4436

4437
### start<sup>8+</sup>
4438

4439
start(callback: AsyncCallback<void\>): void
4440

4441
Starts the renderer. This API uses an asynchronous callback to return the result.
4442

4443
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4444 4445 4446

**Parameters**

G
Gloria 已提交
4447 4448 4449
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
4450 4451 4452 4453

**Example**

```js
4454
audioRenderer.start((err) => {
4455
  if (err) {
4456
    console.error('Renderer start failed.');
4457
  } else {
4458
    console.info('Renderer start success.');
4459
  }
4460
});
V
Vaidegi B 已提交
4461 4462
```

4463
### start<sup>8+</sup>
G
Gloria 已提交
4464

4465
start(): Promise<void\>
G
Gloria 已提交
4466

4467
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
4468

4469
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4470 4471 4472

**Return value**

G
Gloria 已提交
4473 4474 4475
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
G
Gloria 已提交
4476 4477 4478 4479

**Example**

```js
4480 4481
audioRenderer.start().then(() => {
  console.info('Renderer started');
4482
}).catch((err) => {
4483
  console.error(`ERROR: ${err}`);
4484 4485 4486
});
```

4487
### pause<sup>8+</sup>
4488

4489
pause(callback: AsyncCallback\<void>): void
4490

4491
Pauses rendering. This API uses an asynchronous callback to return the result.
4492

4493
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4494 4495 4496

**Parameters**

G
Gloria 已提交
4497 4498 4499
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
4500 4501 4502 4503

**Example**

```js
4504 4505 4506 4507 4508 4509
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4510 4511 4512
});
```

4513
### pause<sup>8+</sup>
4514

4515
pause(): Promise\<void>
4516

4517
Pauses rendering. This API uses a promise to return the result.
4518

4519
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4520 4521 4522

**Return value**

G
Gloria 已提交
4523 4524 4525
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
4526 4527 4528 4529

**Example**

```js
4530 4531
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4532 4533 4534 4535 4536
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
```

4537
### drain<sup>8+</sup>
4538

4539
drain(callback: AsyncCallback\<void>): void
4540

4541
Drains the playback buffer. This API uses an asynchronous callback to return the result.
4542

4543
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4544 4545 4546

**Parameters**

G
Gloria 已提交
4547 4548 4549
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
4550 4551 4552 4553

**Example**

```js
4554
audioRenderer.drain((err) => {
4555
  if (err) {
4556
    console.error('Renderer drain failed');
4557
  } else {
4558
    console.info('Renderer drained.');
4559 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

**Return value**

G
Gloria 已提交
4573 4574 4575
| Type          | Description                     |
| -------------- | ------------------------- |
| 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
});
V
Vaidegi B 已提交
4585 4586
```

4587
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4588

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

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

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

W
wusongqing 已提交
4595
**Parameters**
V
Vaidegi B 已提交
4596

G
Gloria 已提交
4597 4598 4599
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
4600

W
wusongqing 已提交
4601
**Example**
V
Vaidegi B 已提交
4602

G
Gloria 已提交
4603
```js
4604
audioRenderer.stop((err) => {
4605
  if (err) {
4606
    console.error('Renderer stop failed');
4607
  } else {
4608
    console.info('Renderer stopped.');
4609
  }
4610
});
V
Vaidegi B 已提交
4611 4612
```

4613
### stop<sup>8+</sup>
4614

4615
stop(): Promise\<void>
V
Vaidegi B 已提交
4616

4617
Stops rendering. This API uses a promise to return the result.
4618

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

W
wusongqing 已提交
4621
**Return value**
V
Vaidegi B 已提交
4622

G
Gloria 已提交
4623 4624 4625
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
4626

W
wusongqing 已提交
4627
**Example**
V
Vaidegi B 已提交
4628

G
Gloria 已提交
4629
```js
4630 4631
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4632
}).catch((err) => {
4633
  console.error(`ERROR: ${err}`);
4634 4635
});
```
V
Vaidegi B 已提交
4636

4637
### release<sup>8+</sup>
V
Vaidegi B 已提交
4638

4639
release(callback: AsyncCallback\<void>): void
4640

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

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

W
wusongqing 已提交
4645
**Parameters**
V
Vaidegi B 已提交
4646

G
Gloria 已提交
4647 4648 4649
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
4650

W
wusongqing 已提交
4651
**Example**
V
Vaidegi B 已提交
4652

G
Gloria 已提交
4653
```js
4654
audioRenderer.release((err) => {
4655
  if (err) {
4656
    console.error('Renderer release failed');
4657
  } else {
4658
    console.info('Renderer released.');
4659
  }
4660
});
V
Vaidegi B 已提交
4661 4662
```

4663
### release<sup>8+</sup>
V
Vaidegi B 已提交
4664

4665
release(): Promise\<void>
V
Vaidegi B 已提交
4666

4667
Releases the renderer. This API uses a promise to return the result.
4668

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

W
wusongqing 已提交
4671
**Return value**
V
Vaidegi B 已提交
4672

G
Gloria 已提交
4673 4674 4675
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
4676

W
wusongqing 已提交
4677
**Example**
V
Vaidegi B 已提交
4678

G
Gloria 已提交
4679
```js
4680 4681
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4682
}).catch((err) => {
4683
  console.error(`ERROR: ${err}`);
4684
});
V
Vaidegi B 已提交
4685 4686
```

4687
### write<sup>8+</sup>
V
Vaidegi B 已提交
4688

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

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

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

W
wusongqing 已提交
4695
**Parameters**
V
Vaidegi B 已提交
4696

G
Gloria 已提交
4697 4698 4699 4700
| 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 已提交
4701

W
wusongqing 已提交
4702
**Example**
V
Vaidegi B 已提交
4703

G
Gloria 已提交
4704
```js
4705
let bufferSize;
4706 4707
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4708 4709
  bufferSize = data;
  }).catch((err) => {
4710
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4711
  });
4712 4713 4714 4715 4716 4717 4718
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 已提交
4719 4720
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4721
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4722
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4723 4724
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4725 4726
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4727 4728 4729
    }
    let readsize = await fs.read(file.fd, buf, options)
    let writeSize = await new Promise((resolve,reject)=>{
G
Gloria 已提交
4730
      audioRenderer.write(buf,(err,writeSize)=>{
G
Gloria 已提交
4731 4732 4733 4734 4735 4736 4737 4738 4739
        if(err){
          reject(err)
        }else{
          resolve(writeSize)
        }
      })
    })	  
}

V
Vaidegi B 已提交
4740 4741
```

4742
### write<sup>8+</sup>
V
Vaidegi B 已提交
4743

4744
write(buffer: ArrayBuffer): Promise\<number>
4745

4746
Writes the buffer. This API uses a promise to return the result.
4747

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

W
wusongqing 已提交
4750
**Return value**
V
Vaidegi B 已提交
4751

G
Gloria 已提交
4752
| Type            | Description                                                        |
4753
| ---------------- | ------------------------------------------------------------ |
G
Gloria 已提交
4754
| 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 已提交
4755

W
wusongqing 已提交
4756
**Example**
V
Vaidegi B 已提交
4757

G
Gloria 已提交
4758
```js
4759
let bufferSize;
4760 4761
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4762 4763
  bufferSize = data;
  }).catch((err) => {
4764
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4765
  });
4766 4767 4768 4769 4770 4771 4772
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 已提交
4773 4774
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4775
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4776
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4777 4778
for (let i = 0;i < len; i++) {
    let options = {
G
Gloria 已提交
4779 4780
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4781 4782 4783
    }
    let readsize = await fs.read(file.fd, buf, options)
    try{
G
Gloria 已提交
4784
       let writeSize = await audioRenderer.write(buf);
G
Gloria 已提交
4785 4786 4787 4788
    } catch(err) {
       console.error(`audioRenderer.write err: ${err}`);
    }   
}
V
Vaidegi B 已提交
4789 4790
```

4791
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4792

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

4795
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 已提交
4796

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

W
wusongqing 已提交
4799
**Parameters**
V
Vaidegi B 已提交
4800

G
Gloria 已提交
4801 4802 4803
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
4804

W
wusongqing 已提交
4805
**Example**
V
Vaidegi B 已提交
4806

G
Gloria 已提交
4807
```js
4808
audioRenderer.getAudioTime((err, timestamp) => {
4809
  console.info(`Current timestamp: ${timestamp}`);
4810
});
V
Vaidegi B 已提交
4811 4812
```

4813
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4814

4815
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4816

4817
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4818

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

W
wusongqing 已提交
4821
**Return value**
V
Vaidegi B 已提交
4822

G
Gloria 已提交
4823 4824 4825
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
4826

W
wusongqing 已提交
4827
**Example**
V
Vaidegi B 已提交
4828

G
Gloria 已提交
4829
```js
4830 4831
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4832
}).catch((err) => {
4833
  console.error(`ERROR: ${err}`);
4834
});
V
Vaidegi B 已提交
4835 4836
```

4837
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4838

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

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

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

W
wusongqing 已提交
4845
**Parameters**
V
Vaidegi B 已提交
4846

G
Gloria 已提交
4847 4848 4849
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
4850

W
wusongqing 已提交
4851
**Example**
V
Vaidegi B 已提交
4852

G
Gloria 已提交
4853
```js
4854 4855 4856
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4857
  }
4858
});
V
Vaidegi B 已提交
4859 4860
```

4861
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4862

4863
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4864

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

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

W
wusongqing 已提交
4869
**Return value**
V
Vaidegi B 已提交
4870

G
Gloria 已提交
4871 4872 4873
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
4874

W
wusongqing 已提交
4875
**Example**
V
Vaidegi B 已提交
4876

G
Gloria 已提交
4877
```js
4878
let bufferSize;
4879 4880
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4881
  bufferSize = data;
4882
}).catch((err) => {
4883
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4884
});
V
Vaidegi B 已提交
4885 4886
```

4887
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4888

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

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

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

W
wusongqing 已提交
4895
**Parameters**
V
Vaidegi B 已提交
4896

G
Gloria 已提交
4897 4898 4899 4900
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
4901

W
wusongqing 已提交
4902
**Example**
V
Vaidegi B 已提交
4903

G
Gloria 已提交
4904
```js
4905 4906 4907 4908 4909
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.');
4910
  }
4911
});
V
Vaidegi B 已提交
4912 4913
```

4914
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4915

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

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

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

W
wusongqing 已提交
4922
**Parameters**
V
Vaidegi B 已提交
4923

G
Gloria 已提交
4924 4925 4926
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
4927 4928 4929

**Return value**

G
Gloria 已提交
4930 4931 4932
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
4933

W
wusongqing 已提交
4934
**Example**
V
Vaidegi B 已提交
4935

G
Gloria 已提交
4936
```js
4937 4938 4939 4940
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4941
});
V
Vaidegi B 已提交
4942 4943
```

4944
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4945

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

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

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

4952
**Parameters**
V
Vaidegi B 已提交
4953

G
Gloria 已提交
4954 4955 4956
| Name  | Type                                                   | Mandatory| Description              |
| -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes  | Callback used to return the audio render rate.|
V
Vaidegi B 已提交
4957

W
wusongqing 已提交
4958
**Example**
V
Vaidegi B 已提交
4959

G
Gloria 已提交
4960
```js
4961 4962 4963
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
V
Vaidegi B 已提交
4964 4965
```

4966
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4967

4968
getRenderRate(): Promise\<AudioRendererRate>
V
Vaidegi B 已提交
4969

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

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

4974
**Return value**
V
Vaidegi B 已提交
4975

G
Gloria 已提交
4976 4977 4978
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
4979

W
wusongqing 已提交
4980
**Example**
V
Vaidegi B 已提交
4981

G
Gloria 已提交
4982
```js
4983 4984 4985 4986
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4987
});
V
Vaidegi B 已提交
4988
```
4989
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
4990

4991
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4992

4993
Sets the audio interruption mode for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4994

4995
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4996

4997
**Parameters**
V
Vaidegi B 已提交
4998

G
Gloria 已提交
4999 5000 5001
| Name    | Type                               | Mandatory  | Description       |
| ---------- | ---------------------------------- | ------ | ---------- |
| mode       | [InterruptMode](#interruptmode9)    | Yes    | Audio interruption mode. |
V
Vaidegi B 已提交
5002

5003
**Return value**
5004

G
Gloria 已提交
5005 5006 5007
| 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 已提交
5008

5009
**Example**
V
Vaidegi B 已提交
5010

5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025
```js
let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{
  console.info('setInterruptMode Success!');
}).catch((err) => {
  console.error(`setInterruptMode Fail: ${err}`);
});
```
### setInterruptMode<sup>9+</sup>

setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void

Sets the audio interruption mode for the application. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
5026

W
wusongqing 已提交
5027
**Parameters**
V
Vaidegi B 已提交
5028

G
Gloria 已提交
5029 5030 5031 5032
| Name  | Type                               | Mandatory  | Description           |
| ------- | ----------------------------------- | ------ | -------------- |
|mode     | [InterruptMode](#interruptmode9)     | Yes    | Audio interruption mode.|
|callback | AsyncCallback\<void>                 | Yes    |Callback used to return the result.|
V
Vaidegi B 已提交
5033

W
wusongqing 已提交
5034
**Example**
V
Vaidegi B 已提交
5035

G
Gloria 已提交
5036
```js
5037 5038 5039 5040
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
5041
  }
5042
  console.info('setInterruptMode Success!');
5043
});
V
Vaidegi B 已提交
5044 5045
```

5046
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
5047

5048
setVolume(volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
5049

5050
Sets the volume for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
5051

5052
**System capability**: SystemCapability.Multimedia.Audio.Renderer
5053 5054 5055

**Parameters**

G
Gloria 已提交
5056 5057 5058
| Name    | Type   | Mandatory  | Description                |
| ---------- | ------- | ------ | ------------------- |
| volume     | number  | Yes    | Volume to set, which can be within the range from 0.0 to 1.0.|
5059

W
wusongqing 已提交
5060
**Return value**
V
Vaidegi B 已提交
5061

G
Gloria 已提交
5062 5063 5064
| 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 已提交
5065

W
wusongqing 已提交
5066
**Example**
V
Vaidegi B 已提交
5067

G
Gloria 已提交
5068
```js
5069 5070 5071 5072
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
5073
});
V
Vaidegi B 已提交
5074
```
5075
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
5076

5077
setVolume(volume: number, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
5078

5079
Sets the volume for the application. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
5080

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

W
wusongqing 已提交
5083
**Parameters**
V
Vaidegi B 已提交
5084

G
Gloria 已提交
5085 5086 5087 5088
| 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 已提交
5089

W
wusongqing 已提交
5090
**Example**
V
Vaidegi B 已提交
5091

G
Gloria 已提交
5092
```js
5093 5094 5095
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
5096
  }
5097
  console.info('setVolume Success!');
5098
});
V
Vaidegi B 已提交
5099 5100
```

5101
### on('audioInterrupt')<sup>9+</sup>
V
Vaidegi B 已提交
5102

5103
on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
5104

5105
Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
5106

5107
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 已提交
5108

5109
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
5110

5111 5112
**Parameters**

G
Gloria 已提交
5113 5114 5115 5116
| 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.                                    |
5117 5118 5119 5120 5121

**Error codes**

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

G
Gloria 已提交
5122 5123 5124
| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
V
Vaidegi B 已提交
5125

W
wusongqing 已提交
5126
**Example**
V
Vaidegi B 已提交
5127

G
Gloria 已提交
5128
```js
5129 5130
let isPlaying; // An identifier specifying whether rendering is in progress.
let isDucked; // An identifier specifying whether the audio volume is reduced.
5131 5132 5133 5134 5135
onAudioInterrupt();

async function onAudioInterrupt(){
  audioRenderer.on('audioInterrupt', async(interruptEvent) => {
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
5136
      // The system forcibly interrupts audio rendering. The application must update the status and displayed content accordingly.
5137 5138
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
5139 5140 5141
          // 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.
5142 5143
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159
          // 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');
5160 5161 5162
          break;
      }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
5163
      // The application can choose to take action or ignore.
5164 5165
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
5166
          // 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.)
5167
          console.info('Resume force paused renderer or ignore');
5168
          // To continue rendering, the application must perform the required operations.
5169 5170
          break;
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
5171
          // It is recommended that the application pause rendering.
5172
          console.info('Choose to pause or ignore');
5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190
          // 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:
5191 5192 5193 5194 5195
          break;
      }
   }
  });
}
V
Vaidegi B 已提交
5196 5197
```

5198
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
5199

5200
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5201

5202
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 已提交
5203

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

W
wusongqing 已提交
5206
**Parameters**
5207

G
Gloria 已提交
5208 5209 5210 5211 5212
| 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 已提交
5213

W
wusongqing 已提交
5214
**Example**
V
Vaidegi B 已提交
5215

G
Gloria 已提交
5216
```js
5217 5218 5219
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5220
  }
5221
});
V
Vaidegi B 已提交
5222 5223 5224
```


5225
### off('markReach') <sup>8+</sup>
5226

5227
off(type: 'markReach'): void
V
Vaidegi B 已提交
5228

5229
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5230

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

5233 5234
**Parameters**

G
Gloria 已提交
5235 5236 5237
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | Yes  | Event type. The value is fixed at **'markReach'**.|
V
Vaidegi B 已提交
5238

W
wusongqing 已提交
5239
**Example**
V
Vaidegi B 已提交
5240

G
Gloria 已提交
5241
```js
5242
audioRenderer.off('markReach');
V
Vaidegi B 已提交
5243 5244
```

5245
### on('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5246

5247
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5248

5249
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 已提交
5250

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

W
wusongqing 已提交
5253
**Parameters**
5254

G
Gloria 已提交
5255 5256 5257 5258 5259
| 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 已提交
5260

W
wusongqing 已提交
5261
**Example**
V
Vaidegi B 已提交
5262

G
Gloria 已提交
5263
```js
5264 5265 5266
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5267
  }
5268
});
V
Vaidegi B 已提交
5269 5270
```

5271
### off('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5272

5273
off(type: 'periodReach'): void
5274

5275
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5276

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

5279
**Parameters**
V
Vaidegi B 已提交
5280

G
Gloria 已提交
5281 5282 5283
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | Yes  | Event type. The value is fixed at **'periodReach'**.|
V
Vaidegi B 已提交
5284

W
wusongqing 已提交
5285
**Example**
V
Vaidegi B 已提交
5286

G
Gloria 已提交
5287
```js
5288
audioRenderer.off('periodReach')
V
Vaidegi B 已提交
5289
```
5290

G
Gloria 已提交
5291
### on('stateChange')<sup>8+</sup>
W
wusongqing 已提交
5292

5293
on(type: 'stateChange', callback: Callback<AudioState\>): void
W
wusongqing 已提交
5294

5295
Subscribes to state change events.
W
wusongqing 已提交
5296

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

5299
**Parameters**
W
wusongqing 已提交
5300

G
Gloria 已提交
5301 5302 5303 5304
| 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 已提交
5305

5306
**Example**
W
wusongqing 已提交
5307

5308 5309 5310 5311 5312 5313 5314 5315 5316 5317
```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');
  }
});
```
5318

5319
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5320

5321
Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
V
Vaidegi B 已提交
5322

5323
### Attributes
5324

5325
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5326

G
Gloria 已提交
5327 5328 5329
| Name | Type                    | Readable| Writable| Description            |
| :---- | :------------------------- | :--- | :--- | :--------------- |
| state<sup>8+</sup>  | [AudioState](#audiostate8) | Yes| No  | Audio capturer state.|
V
Vaidegi B 已提交
5330

5331
**Example**
V
Vaidegi B 已提交
5332

5333 5334 5335
```js
let state = audioCapturer.state;
```
V
Vaidegi B 已提交
5336

5337
### getCapturerInfo<sup>8+</sup>
5338

5339
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5340

5341
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5342

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

W
wusongqing 已提交
5345
**Parameters**
5346

G
Gloria 已提交
5347 5348 5349
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
5350

W
wusongqing 已提交
5351
**Example**
5352

G
Gloria 已提交
5353
```js
5354
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5355
  if (err) {
5356 5357 5358 5359 5360
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5361
  }
5362 5363 5364
});
```

5365

5366
### getCapturerInfo<sup>8+</sup>
5367

5368
getCapturerInfo(): Promise<AudioCapturerInfo\>
5369

5370
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
5371

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

5374
**Return value**
5375

G
Gloria 已提交
5376 5377 5378
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
5379

W
wusongqing 已提交
5380
**Example**
5381

G
Gloria 已提交
5382
```js
5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393
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}`);
5394
});
5395 5396
```

5397
### getStreamInfo<sup>8+</sup>
5398

5399
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5400

5401
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5402

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

W
wusongqing 已提交
5405
**Parameters**
5406

G
Gloria 已提交
5407 5408 5409
| Name  | Type                                                | Mandatory| Description                            |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
5410

W
wusongqing 已提交
5411
**Example**
5412

G
Gloria 已提交
5413
```js
5414
audioCapturer.getStreamInfo((err, streamInfo) => {
5415
  if (err) {
5416 5417 5418 5419 5420 5421 5422
    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}`);
5423
  }
5424 5425 5426
});
```

5427
### getStreamInfo<sup>8+</sup>
5428

5429
getStreamInfo(): Promise<AudioStreamInfo\>
5430

5431
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
5432

5433
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5434 5435 5436

**Return value**

G
Gloria 已提交
5437 5438 5439
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
5440

W
wusongqing 已提交
5441
**Example**
5442

G
Gloria 已提交
5443
```js
5444 5445 5446 5447 5448 5449 5450 5451
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}`);
5452
});
5453
```
V
Vaidegi B 已提交
5454

5455
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5456

5457
getAudioStreamId(callback: AsyncCallback<number\>): void
V
Vaidegi B 已提交
5458

5459
Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5460

5461
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5462

W
wusongqing 已提交
5463
**Parameters**
5464

G
Gloria 已提交
5465 5466 5467
| Name  | Type                                                | Mandatory| Description                |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the stream ID.|
5468

W
wusongqing 已提交
5469
**Example**
5470

G
Gloria 已提交
5471
```js
5472 5473
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5474
});
5475
```
V
Vaidegi B 已提交
5476

5477
### getAudioStreamId<sup>9+</sup>
5478

5479 5480 5481
getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
5482

5483
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5484 5485 5486

**Return value**

G
Gloria 已提交
5487 5488 5489
| Type            | Description                  |
| :----------------| :--------------------- |
| Promise<number\> | Promise used to return the stream ID.|
V
Vaidegi B 已提交
5490

W
wusongqing 已提交
5491
**Example**
V
Vaidegi B 已提交
5492

G
Gloria 已提交
5493
```js
5494 5495 5496 5497
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5498
});
V
Vaidegi B 已提交
5499 5500
```

5501
### start<sup>8+</sup>
V
Vaidegi B 已提交
5502

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

5505
Starts capturing. This API uses an asynchronous callback to return the result.
5506

5507
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5508

W
wusongqing 已提交
5509
**Parameters**
V
Vaidegi B 已提交
5510

G
Gloria 已提交
5511 5512 5513
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
5514

W
wusongqing 已提交
5515
**Example**
V
Vaidegi B 已提交
5516

G
Gloria 已提交
5517
```js
5518
audioCapturer.start((err) => {
5519
  if (err) {
5520 5521 5522
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5523
  }
5524
});
V
Vaidegi B 已提交
5525 5526 5527
```


5528
### start<sup>8+</sup>
V
Vaidegi B 已提交
5529

5530
start(): Promise<void\>
5531

5532
Starts capturing. This API uses a promise to return the result.
5533

5534
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5535

W
wusongqing 已提交
5536
**Return value**
V
Vaidegi B 已提交
5537

G
Gloria 已提交
5538 5539 5540
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
V
Vaidegi B 已提交
5541

W
wusongqing 已提交
5542
**Example**
V
Vaidegi B 已提交
5543

G
Gloria 已提交
5544
```js
5545 5546 5547 5548 5549 5550 5551 5552 5553 5554
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}`);
5555
});
5556
```
V
Vaidegi B 已提交
5557

5558
### stop<sup>8+</sup>
5559

5560
stop(callback: AsyncCallback<void\>): void
5561

5562
Stops capturing. This API uses an asynchronous callback to return the result.
5563

5564
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5565

W
wusongqing 已提交
5566
**Parameters**
V
Vaidegi B 已提交
5567

G
Gloria 已提交
5568 5569 5570
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
5571

W
wusongqing 已提交
5572
**Example**
V
Vaidegi B 已提交
5573

G
Gloria 已提交
5574
```js
5575
audioCapturer.stop((err) => {
5576
  if (err) {
5577 5578 5579
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5580
  }
5581
});
V
Vaidegi B 已提交
5582 5583
```

5584

5585
### stop<sup>8+</sup>
5586

5587
stop(): Promise<void\>
5588

5589
Stops capturing. This API uses a promise to return the result.
5590

5591
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5592

W
wusongqing 已提交
5593
**Return value**
V
Vaidegi B 已提交
5594

G
Gloria 已提交
5595 5596 5597
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
V
Vaidegi B 已提交
5598

W
wusongqing 已提交
5599
**Example**
V
Vaidegi B 已提交
5600

G
Gloria 已提交
5601
```js
5602 5603 5604 5605 5606 5607 5608 5609
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}`);
5610
});
V
Vaidegi B 已提交
5611 5612
```

5613
### release<sup>8+</sup>
V
Vaidegi B 已提交
5614

5615
release(callback: AsyncCallback<void\>): void
5616

5617
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5618

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

W
wusongqing 已提交
5621
**Parameters**
5622

G
Gloria 已提交
5623 5624 5625
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
5626

W
wusongqing 已提交
5627
**Example**
5628

G
Gloria 已提交
5629
```js
5630
audioCapturer.release((err) => {
5631
  if (err) {
5632 5633 5634
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5635
  }
5636
});
5637 5638 5639
```


5640
### release<sup>8+</sup>
5641

5642
release(): Promise<void\>
5643

5644
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5645

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

W
wusongqing 已提交
5648
**Return value**
5649

G
Gloria 已提交
5650 5651 5652
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
5653

W
wusongqing 已提交
5654
**Example**
5655

G
Gloria 已提交
5656
```js
5657 5658 5659 5660 5661 5662 5663 5664
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}`);
5665 5666 5667
});
```

5668
### read<sup>8+</sup>
5669

5670
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
5671

5672
Reads the buffer. This API uses an asynchronous callback to return the result.
5673

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

W
wusongqing 已提交
5676
**Parameters**
5677

G
Gloria 已提交
5678 5679 5680 5681 5682
| 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.|
5683

W
wusongqing 已提交
5684
**Example**
5685

G
Gloria 已提交
5686
```js
5687 5688 5689 5690 5691 5692 5693 5694 5695 5696
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');
5697
  }
5698
});
5699 5700
```

5701
### read<sup>8+</sup>
5702

5703
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5704

5705
Reads the buffer. This API uses a promise to return the result.
5706

5707
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5708 5709 5710

**Parameters**

G
Gloria 已提交
5711 5712 5713 5714
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
5715

W
wusongqing 已提交
5716
**Return value**
5717

G
Gloria 已提交
5718 5719 5720
| 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.|
5721

W
wusongqing 已提交
5722
**Example**
5723

G
Gloria 已提交
5724
```js
5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736
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}`);
5737
});
5738
```
5739

5740
### getAudioTime<sup>8+</sup>
5741

5742
getAudioTime(callback: AsyncCallback<number\>): void
5743

5744 5745 5746
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
5747

W
wusongqing 已提交
5748
**Parameters**
5749

G
Gloria 已提交
5750 5751 5752
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the result.|
5753

W
wusongqing 已提交
5754
**Example**
5755

G
Gloria 已提交
5756
```js
5757 5758
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5759
});
5760 5761
```

5762
### getAudioTime<sup>8+</sup>
5763

5764
getAudioTime(): Promise<number\>
5765

5766
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
5767

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

W
wusongqing 已提交
5770
**Return value**
5771

G
Gloria 已提交
5772 5773 5774
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
5775

W
wusongqing 已提交
5776
**Example**
5777

G
Gloria 已提交
5778
```js
5779 5780 5781 5782
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5783 5784 5785
});
```

5786
### getBufferSize<sup>8+</sup>
5787

5788
getBufferSize(callback: AsyncCallback<number\>): void
5789

5790
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
5791

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

W
wusongqing 已提交
5794
**Parameters**
5795

G
Gloria 已提交
5796 5797 5798
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
5799

W
wusongqing 已提交
5800
**Example**
5801

G
Gloria 已提交
5802
```js
5803 5804 5805 5806 5807 5808 5809 5810
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}`);
    });
5811
  }
J
jiao_yanlin 已提交
5812
});
5813 5814
```

5815
### getBufferSize<sup>8+</sup>
5816

5817
getBufferSize(): Promise<number\>
5818

5819
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
5820

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

W
wusongqing 已提交
5823
**Return value**
5824

G
Gloria 已提交
5825 5826 5827
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
5828

W
wusongqing 已提交
5829
**Example**
5830

G
Gloria 已提交
5831
```js
5832 5833 5834 5835 5836 5837
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5838 5839 5840
});
```

5841 5842 5843 5844
### on('audioInterrupt')<sup>10+</sup>

on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void

G
Gloria 已提交
5845
Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
5846 5847 5848 5849 5850 5851 5852

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

G
Gloria 已提交
5853 5854 5855 5856
| 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.                                    |
5857 5858 5859 5860 5861

**Error codes**

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

G
Gloria 已提交
5862 5863 5864
| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 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

**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;
      }
   }
  });
}
```


5918
### on('markReach')<sup>8+</sup>
5919

5920
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
5921

5922
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
5923

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

W
wusongqing 已提交
5926
**Parameters**
5927

G
Gloria 已提交
5928 5929 5930 5931 5932
| 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.|
5933

W
wusongqing 已提交
5934
**Example**
5935

G
Gloria 已提交
5936
```js
5937 5938 5939
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5940
  }
5941
});
5942 5943
```

5944
### off('markReach')<sup>8+</sup>
5945

5946
off(type: 'markReach'): void
5947

5948
Unsubscribes from mark reached events.
5949

5950
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5951 5952 5953

**Parameters**

G
Gloria 已提交
5954 5955 5956
| Name| Type  | Mandatory| Description                                         |
| :----- | :----- | :--- | :-------------------------------------------- |
| type   | string | Yes  | Event type. The value is fixed at **'markReach'**.|
5957

W
wusongqing 已提交
5958
**Example**
5959

G
Gloria 已提交
5960
```js
5961
audioCapturer.off('markReach');
5962 5963
```

5964
### on('periodReach')<sup>8+</sup>
5965

5966
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
5967

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

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

W
wusongqing 已提交
5972
**Parameters**
5973

G
Gloria 已提交
5974 5975 5976 5977 5978
| 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.   |
5979

W
wusongqing 已提交
5980
**Example**
5981

G
Gloria 已提交
5982
```js
5983 5984 5985
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5986
  }
5987 5988 5989
});
```

5990
### off('periodReach')<sup>8+</sup>
5991

5992
off(type: 'periodReach'): void
5993

5994
Unsubscribes from period reached events.
5995

5996
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5997 5998 5999

**Parameters**

G
Gloria 已提交
6000 6001 6002
| Name| Type  | Mandatory| Description                                           |
| :----- | :----- | :--- | :---------------------------------------------- |
| type   | string | Yes | Event type. The value is fixed at **'periodReach'**.|
6003

W
wusongqing 已提交
6004
**Example**
6005

G
Gloria 已提交
6006
```js
6007
audioCapturer.off('periodReach')
6008 6009
```

G
Gloria 已提交
6010
### on('stateChange')<sup>8+</sup>
6011

6012
on(type: 'stateChange', callback: Callback<AudioState\>): void
6013

6014
Subscribes to state change events.
6015

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

W
wusongqing 已提交
6018
**Parameters**
6019

G
Gloria 已提交
6020 6021 6022 6023
| 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.                           |
6024

W
wusongqing 已提交
6025
**Example**
6026

G
Gloria 已提交
6027
```js
6028 6029 6030 6031 6032 6033
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');
6034
  }
6035 6036 6037
});
```

6038
## ToneType<sup>9+</sup>
6039

6040
Enumerates the tone types of the player.
6041

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

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

G
Gloria 已提交
6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074
| 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.         |
6075

6076
## TonePlayer<sup>9+</sup>
6077

6078
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
6079

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

6082
### load<sup>9+</sup>
6083

6084
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
6085

6086
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
6087

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

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

W
wusongqing 已提交
6092
**Parameters**
6093

G
Gloria 已提交
6094 6095 6096 6097
| Name         | Type                       | Mandatory | Description                           |
| :--------------| :-------------------------- | :-----| :------------------------------ |
| type           | [ToneType](#tonetype9)       | Yes   | Tone type.                |
| callback       | AsyncCallback<void\>        | Yes   | Callback used to return the result.|
6098

W
wusongqing 已提交
6099
**Example**
6100

G
Gloria 已提交
6101
```js
6102
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
6103
  if (err) {
6104
    console.error(`callback call load failed error: ${err.message}`);
6105
    return;
6106 6107
  } else {
    console.info('callback call load success');
6108 6109
  }
});
6110 6111
```

6112
### load<sup>9+</sup>
6113

6114
load(type: ToneType): Promise&lt;void&gt;
6115

6116
Loads the DTMF tone configuration. This API uses a promise to return the result.
6117

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

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

W
wusongqing 已提交
6122
**Parameters**
6123

G
Gloria 已提交
6124 6125 6126
| Name        | Type                   | Mandatory |  Description            |
| :------------- | :--------------------- | :---  | ---------------- |
| type           | [ToneType](#tonetype9)   | Yes   | Tone type. |
6127 6128 6129

**Return value**

G
Gloria 已提交
6130 6131 6132
| Type           | Description                       |
| :--------------| :-------------------------- |
| Promise<void\> | Promise used to return the result.|
6133

W
wusongqing 已提交
6134
**Example**
6135

G
Gloria 已提交
6136
```js
6137 6138 6139 6140
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
6141
});
6142
```
6143

6144
### start<sup>9+</sup>
6145

6146
start(callback: AsyncCallback&lt;void&gt;): void
6147

6148
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
6149

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

6152
**System capability**: SystemCapability.Multimedia.Audio.Tone
6153 6154 6155

**Parameters**

G
Gloria 已提交
6156 6157 6158
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
6159 6160 6161 6162

**Example**

```js
6163
tonePlayer.start((err) => {
6164
  if (err) {
6165
    console.error(`callback call start failed error: ${err.message}`);
6166
    return;
6167 6168
  } else {
    console.info('callback call start success');
6169 6170 6171 6172
  }
});
```

6173
### start<sup>9+</sup>
6174

6175
start(): Promise&lt;void&gt;
6176

6177
Starts DTMF tone playing. This API uses a promise to return the result.
6178

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

6181
**System capability**: SystemCapability.Multimedia.Audio.Tone
6182 6183 6184

**Return value**

G
Gloria 已提交
6185 6186 6187
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
6188 6189 6190 6191

**Example**

```js
6192 6193 6194 6195
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
6196 6197 6198
});
```

6199
### stop<sup>9+</sup>
6200

6201
stop(callback: AsyncCallback&lt;void&gt;): void
6202

6203
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
6204 6205 6206

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

6207
**System capability**: SystemCapability.Multimedia.Audio.Tone
6208 6209 6210

**Parameters**

G
Gloria 已提交
6211 6212 6213
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
6214 6215 6216 6217

**Example**

```js
6218 6219 6220 6221 6222 6223 6224
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
6225 6226 6227
});
```

6228
### stop<sup>9+</sup>
6229

6230
stop(): Promise&lt;void&gt;
6231

6232
Stops the tone that is being played. This API uses a promise to return the result.
6233

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

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

6238
**Return value**
6239

G
Gloria 已提交
6240 6241 6242
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
6243 6244 6245 6246

**Example**

```js
6247 6248 6249 6250
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
6251 6252 6253
});
```

6254
### release<sup>9+</sup>
6255

6256
release(callback: AsyncCallback&lt;void&gt;): void
6257

6258
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
6259

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

6262
**System capability**: SystemCapability.Multimedia.Audio.Tone
6263 6264 6265

**Parameters**

G
Gloria 已提交
6266 6267 6268
| Name  | Type                | Mandatory| Description                           |
| :------- | :------------------- | :--- | :---------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
6269 6270 6271 6272

**Example**

```js
6273 6274 6275 6276 6277 6278 6279
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6280 6281 6282
});
```

6283
### release<sup>9+</sup>
6284

6285
release(): Promise&lt;void&gt;
6286

6287
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
6288

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

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

6293
**Return value**
6294

G
Gloria 已提交
6295 6296 6297
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
6298 6299 6300 6301

**Example**

```js
6302 6303 6304 6305
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6306 6307 6308
});
```

6309
## ActiveDeviceType<sup>(deprecated)</sup>
6310

6311
Enumerates the active device types.
6312

6313 6314 6315
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6316

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

G
Gloria 已提交
6319 6320 6321 6322
| Name         |  Value    | Description                                                |
| ------------- | ------ | ---------------------------------------------------- |
| SPEAKER       | 2      | Speaker.                                            |
| BLUETOOTH_SCO | 7      | Bluetooth device using Synchronous Connection Oriented (SCO) links.|
6323 6324 6325 6326

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

Enumerates the returned event types for audio interruption events.
6327 6328 6329 6330 6331 6332

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

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

G
Gloria 已提交
6334 6335 6336 6337
| Name          |  Value    | Description              |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | Focus gain event.|
| TYPE_INTERRUPT | 1      | Audio interruption event.|
6338

6339
## AudioInterrupt<sup>(deprecated)</sup>
6340

6341
Describes input parameters of audio interruption events.
6342

6343 6344 6345
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6346

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

G
Gloria 已提交
6349 6350 6351 6352 6353
| 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.|
6354

6355
## InterruptAction<sup>(deprecated)</sup>
6356

6357
Describes the callback invoked for audio interruption or focus gain events.
6358

6359 6360
> **NOTE**
>
6361
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [InterruptEvent](#interruptevent9).
6362

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

G
Gloria 已提交
6365 6366 6367 6368 6369 6370
| 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.|