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

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

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

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

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

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

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

G
Gloria 已提交
22 23
## Constants

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

**Example**

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

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

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

42
getAudioManager(): AudioManager
43

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

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

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

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

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

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

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

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

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

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

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

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

G
Gloria 已提交
76
```js
77
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 352
| ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup>      | 0      | Audio stream for voice calls.|
| RINGTONE                     | 2      | Audio stream for ringtones.    |
| MEDIA                        | 3      | Audio stream for media purpose.    |
| VOICE_ASSISTANT<sup>8+</sup> | 9      | Audio stream for voice assistant.|
353 354 355 356 357 358 359 360 361 362
| ALL<sup>9+</sup>             | 100    | All public audio streams.<br>This is a system API.|

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

Enumerates the result types of audio interruption requests.

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

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

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

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

Enumerates the audio interruption modes.

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

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

379
## DeviceFlag
W
wusongqing 已提交
380

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

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

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

## DeviceRole
W
wusongqing 已提交
396

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

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

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

406
## DeviceType
W
wusongqing 已提交
407

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

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

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

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

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

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

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

## AudioRingMode
W
wusongqing 已提交
436

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

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

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

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

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

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

453
| Name                               |  Value   | Description                      |
454 455 456 457 458 459
| ---------------------------------- | ------ | -------------------------- |
| 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 已提交
460
| 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.|
461

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

Enumerates the audio error codes.

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

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

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

Enumerates the audio channels.

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

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

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

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

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

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

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

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

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

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

520 521
## ContentType

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

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

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

535 536
## StreamUsage

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

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

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

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

551
Enumerates the audio interruption request types.
552

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

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

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

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

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

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

567
| Name          | Value    | Description            |
W
wusongqing 已提交
568 569 570 571 572 573 574 575
| -------------- | ------ | ---------------- |
| STATE_INVALID  | -1     | Invalid state.      |
| STATE_NEW      | 0      | Creating instance state.|
| STATE_PREPARED | 1      | Prepared.      |
| STATE_RUNNING  | 2      | Running.    |
| STATE_STOPPED  | 3      | Stopped.      |
| STATE_RELEASED | 4      | Released.      |
| STATE_PAUSED   | 5      | Paused.      |
V
Vaidegi B 已提交
576

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

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

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

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

589
## InterruptType
V
Vaidegi B 已提交
590

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

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

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

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

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

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

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

## InterruptHint
V
Vaidegi B 已提交
612

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

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

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

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

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

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

632 633 634 635 636 637
| Name        | Type                                              | Mandatory| Description              |
| ------------ | ------------------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8)          | Yes  | Audio sampling rate.|
| channels     | [AudioChannel](#audiochannel8)                    | Yes  | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8)          | Yes  | Audio sample format.    |
| encodingType | [AudioEncodingType](#audioencodingtype8)          | Yes  | Audio encoding type.    |
638 639

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

Describes audio renderer information.

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

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

651 652 653 654 655 656 657 658 659 660 661 662 663
## InterruptResult<sup>9+</sup>

Describes the audio interruption result.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

703 704 705 706 707 708 709
## MicStateChangeEvent<sup>9+</sup>

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

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

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

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

Enumerates the types of connected devices.

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

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

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

726 727 728 729 730 731 732 733
## VolumeGroupInfos<sup>9+</sup>

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

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

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

G
Gloria 已提交
734 735 736 737 738 739 740 741 742 743 744 745 746
## VolumeGroupInfo<sup>9+</sup>

Describes the volume group information.

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

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

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

W
wusongqing 已提交
750
## DeviceChangeAction
751

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

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

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

W
wusongqing 已提交
761
## DeviceChangeType
762

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

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

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

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

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

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

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

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

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

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

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

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

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

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

800
| Name                                        |  Value    | Description                  |
801 802 803 804 805
| :------------------------------------------- | :----- | :--------------------- |
| SOURCE_TYPE_INVALID                          | -1     | Invalid audio source.        |
| SOURCE_TYPE_MIC                              | 0      | Mic source.           |
| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup>   | 1      | Voice recognition source.       |
| SOURCE_TYPE_VOICE_COMMUNICATION              | 7      | Voice communication source.|
806 807

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

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

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

813
| Name                  |  Value    | Description                                         |
W
wusongqing 已提交
814 815
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
816 817
| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API.|
| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API.|
W
wusongqing 已提交
818
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
819

820
## AudioManager
W
wusongqing 已提交
821

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

824 825 826
### setAudioParameter

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

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

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

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

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

**Parameters**

838 839 840 841 842
| Name  | Type                     | Mandatory| Description                    |
| -------- | ------------------------- | ---- | ------------------------ |
| key      | string                    | Yes  | Key of the audio parameter to set.  |
| value    | string                    | Yes  | Value of the audio parameter to set.  |
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
G
Gloria 已提交
843 844

**Example**
845

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

856
### setAudioParameter
G
Gloria 已提交
857

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

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

862 863 864 865 866 867 868 869 870 871 872 873
This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only.

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

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

**Parameters**

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

**Return value**

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

**Example**
882

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

889
### getAudioParameter
890

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

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

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

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

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

901 902 903 904
| Name  | Type                       | Mandatory| Description                        |
| -------- | --------------------------- | ---- | ---------------------------- |
| key      | string                      | Yes  | Key of the audio parameter whose value is to be obtained.      |
| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the value of the audio parameter.|
905

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

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

918
### getAudioParameter
919

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

960 961 962 963
| Name  | Type                                | Mandatory| Description                |
| :------- | :----------------------------------- | :--- | :------------------- |
| scene    | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.      |
| callback | AsyncCallback<void\>                 | Yes  | Callback used to return the result.|
964

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

**Example**
W
wusongqing 已提交
1024

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

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

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

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

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

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

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

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

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

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

1061
getVolumeManager(): AudioVolumeManager
1062

1063
Obtains an **AudioVolumeManager** instance.
1064

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

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

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

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

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

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

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

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

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

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

1089 1090 1091 1092 1093
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

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

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

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

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

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

1107 1108 1109 1110
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.

G
Gloria 已提交
1111 1112
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

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

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

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

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

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

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

1143 1144 1145 1146
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**.

G
Gloria 已提交
1147 1148
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

1155 1156 1157 1158
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
1159

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

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

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

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

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

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

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

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

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

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

1188 1189 1190 1191 1192 1193
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|

**Example**
W
wusongqing 已提交
1194

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

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

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

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

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

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

1217 1218 1219 1220 1221
**Parameters**

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

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

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

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

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

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

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

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

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

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

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

1251 1252 1253 1254
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
W
wusongqing 已提交
1255

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1314 1315 1316 1317
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
W
wusongqing 已提交
1318

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1409 1410 1411 1412
| Name    | Type                               | Mandatory| Description                                 |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
W
wusongqing 已提交
1413

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

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

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

1422

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1480 1481 1482
| Type                  | Description                                                  |
| ---------------------- | ------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
1483

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

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

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

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

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

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

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

**Parameters**

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

**Example**

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

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1632 1633 1634 1635 1636
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.

**System capability**: SystemCapability.Multimedia.Audio.Communication
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646

**Parameters**

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

**Example**

```js
1647
audioManager.getRingerMode((err, value) => {
1648 1649 1650 1651 1652 1653 1654 1655
  if (err) {
    console.error(`Failed to obtain the ringer mode.​ ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
});
```

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

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

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

1662 1663 1664 1665 1666
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**.

**System capability**: SystemCapability.Multimedia.Audio.Communication
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676

**Return value**

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

**Example**

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

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

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

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

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

**System capability**: SystemCapability.Multimedia.Audio.Device
1693 1694 1695

**Parameters**

1696 1697 1698 1699
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the device list.|
1700

1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
**Example**
```js
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the device list. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the device list is obtained.');
});
```
1711

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

1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;

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

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

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

**Parameters**

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

**Return value**

| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
1735 1736 1737 1738

**Example**

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

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

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

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

1750 1751 1752 1753 1754
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1803

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

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

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

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

1816 1817 1818 1819 1820
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1889 1890 1891 1892
| Name  | Type                     | Mandatory| Description                                         |
| -------- | ------------------------- | ---- | --------------------------------------------- |
| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                     |
1893

1894
**Example**
1895

1896 1897 1898 1899 1900 1901 1902 1903 1904
```js
audioManager.setMicrophoneMute(true, (err) => {
  if (err) {
    console.error(`Failed to mute the microphone. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the microphone is muted.');
});
```
1905

1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
### setMicrophoneMute<sup>(deprecated)</sup>

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

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

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

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

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

**Parameters**

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

**Return value**

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

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

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

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

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

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

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

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

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

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

1956 1957 1958
| Name  | Type                        | Mandatory| Description                                                   |
| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
V
Vaidegi B 已提交
1959

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

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

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

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

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

1978 1979 1980 1981 1982 1983 1984
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**.

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

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

1986
**Return value**
1987

1988 1989 1990
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
1991

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

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

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

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

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

2008 2009 2010 2011 2012 2013 2014
Subscribes to system volume change events.

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

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

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

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

2018 2019 2020 2021
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
2022

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

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

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

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

2037
Subscribes to ringer mode change events.
2038

2039 2040 2041
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('ringerModeChange')](#onringermodechange9) in **AudioVolumeGroupManager**.
2042

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

2045 2046 2047 2048 2049 2050 2051 2052
**System capability**: SystemCapability.Multimedia.Audio.Communication

**Parameters**

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

**Example**
2055

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

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

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

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

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

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

2074
**Parameters**
2075

2076 2077 2078 2079
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes  | Callback used to return the device update details.                        |
2080

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

G
Gloria 已提交
2083
```js
2084 2085 2086 2087 2088
audioManager.on('deviceChange', (deviceChanged) => {
  console.info(`device change type : ${deviceChanged.type} `);
  console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
  console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
2089 2090 2091
});
```

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

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

2096
Unsubscribes from device change events.
2097

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

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

2104
**Parameters**
2105

2106 2107 2108 2109
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No  | Callback used to return the device update details.                        |
2110 2111 2112 2113

**Example**

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

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

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

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

2125 2126 2127 2128 2129 2130 2131
Same as [on('audioInterrupt')](#onaudiointerrupt9), this API is used to listen for focus changes. However, this API is used in scenarios without audio streams (no **AudioRenderer** instance is created), such as frequency modulation (FM) and voice wakeup.

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

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

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

2135 2136 2137 2138 2139
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | Yes  | Event type. The value **'interrupt'** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | Yes  | Callback invoked for the audio interruption event.                                      |
2140

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

G
Gloria 已提交
2143
```js
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156
let interAudioInterrupt = {
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
};
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
  if (InterruptAction.actionType === 0) {
    console.info('An event to gain the audio focus starts.');
    console.info(`Focus gain event: ${InterruptAction} `);
  }
  if (InterruptAction.actionType === 1) {
    console.info('An audio interruption event starts.');
    console.info(`Audio interruption event: ${InterruptAction} `);
2157
  }
2158
});
2159 2160
```

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

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

2165
Unsubscribes from audio interruption events.
2166

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

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

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

2175 2176 2177 2178 2179
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | Yes  | Event type. The value **'interrupt'** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptactiondeprecated)> | No  | Callback invoked for the audio interruption event.                                      |
2180

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

G
Gloria 已提交
2183
```js
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
let interAudioInterrupt = {
  streamUsage:2,
  contentType:0,
  pauseWhenDucked:true
};
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
  if (InterruptAction.actionType === 0) {
      console.info('An event to release the audio focus starts.');
      console.info(`Focus release event: ${InterruptAction} `);
  }
});
2195 2196
```

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

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

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

2203 2204 2205 2206 2207 2208 2209
getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void

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

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

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

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

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

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

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

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

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

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

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

2239 2240
**Parameters**

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

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

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

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

G
Gloria 已提交
2253
```js
2254 2255 2256 2257 2258
async function getVolumeGroupInfos(){
  let volumegroupinfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
  console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
}
```
2259

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

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

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

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

**Parameters**

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

**Example**
2276

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

2287 2288
```

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

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

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

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

**Parameters**

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

**Return value**

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

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

```js
2312 2313 2314 2315 2316 2317 2318 2319
let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
let audioVolumeGroupManager;
getVolumeGroupManager();
async function getVolumeGroupManager(){
  audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
  console.info('Callback invoked to indicate that the volume group infos list is obtained.');
}

2320 2321
```

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

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

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

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

**Parameters**

2332 2333 2334 2335
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when the system volume changes.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
G
Gloria 已提交
2336

2337
**Error codes**
2338

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

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

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

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

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

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

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

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

2363
Sets the volume for a stream. This API uses an asynchronous callback to return the result.
2364

2365
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2366

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

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

2371 2372 2373 2374 2375 2376 2377 2378 2379
**System capability**: SystemCapability.Multimedia.Audio.Volume

**Parameters**

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

**Example**

```js
2384 2385 2386 2387 2388 2389
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.');
2390 2391 2392
});
```

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

2395
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
2396

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

2399
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2400

2401
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
G
Gloria 已提交
2402 2403 2404

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

2405
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2406 2407 2408

**Parameters**

2409 2410 2411 2412
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
G
Gloria 已提交
2413 2414 2415

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

2438 2439 2440 2441
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
G
Gloria 已提交
2442 2443 2444 2445

**Example**

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

2493 2494 2495 2496
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
G
Gloria 已提交
2497 2498 2499 2500

**Example**

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

2548 2549 2550 2551
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
G
Gloria 已提交
2552 2553

**Example**
2554

G
Gloria 已提交
2555
```js
2556 2557 2558 2559 2560 2561 2562
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
  if (err) {
    console.error(`Failed to obtain the maximum volume. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
});
G
Gloria 已提交
2563 2564
```

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

2601 2602 2603 2604 2605
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

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

**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2606 2607 2608

**Parameters**

2609 2610 2611 2612 2613
| Name    | Type                               | Mandatory| Description                                 |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.               |
G
Gloria 已提交
2614 2615 2616

**Example**

2617 2618 2619 2620 2621 2622 2623 2624
```js
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
  if (err) {
    console.error(`Failed to mute the stream. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the stream is muted.');
});
2625
```
G
Gloria 已提交
2626

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

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

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

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

2635 2636 2637 2638 2639
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.

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

**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2640 2641 2642

**Parameters**

2643 2644 2645 2646
| Name    | Type                               | Mandatory| Description                                 |
| ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                         |
| mute       | boolean                             | Yes  | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
G
Gloria 已提交
2647 2648 2649

**Return value**

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

**Example**

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

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

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

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

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

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

2672 2673 2674 2675
| Name    | Type                               | Mandatory| Description                                           |
| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                   |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
G
Gloria 已提交
2676 2677 2678 2679

**Example**

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

2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713
### isMute<sup>9+</sup>

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

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

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

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

2731 2732 2733 2734 2735 2736
**Parameters**

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

**Example**

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

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

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

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

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

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

2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774
**System API**: This is a system API.

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

**Parameters**

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

**Return value**

| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2775 2776 2777 2778

**Example**

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

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

2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804
getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void

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

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

**Parameters**

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

**Example**

```js
audioVolumeGroupManager.getRingerMode((err, value) => {
  if (err) {
    console.error(`Failed to obtain the ringer mode.​ ${err}`);
    return;
G
Gloria 已提交
2805
  }
2806
  console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
G
Gloria 已提交
2807 2808 2809
});
```

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

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

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

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

2818
**Return value**
2819

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

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

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

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

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

2836
Subscribes to ringer mode change events.
2837

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

2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
**Parameters**

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

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
G
Gloria 已提交
2854 2855 2856 2857

**Example**

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

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

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

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

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

**Parameters**

2874 2875 2876 2877
| Name  | Type                     | Mandatory| Description                                         |
| -------- | ------------------------- | ---- | --------------------------------------------- |
| mute     | boolean                   | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                     |
G
Gloria 已提交
2878 2879 2880 2881

**Example**

```js
2882 2883 2884 2885 2886 2887
audioVolumeGroupManager.setMicrophoneMute(true, (err) => {
  if (err) {
    console.error(`Failed to mute the microphone. ${err}`);
    return;
  }
  console.info('Callback invoked to indicate that the microphone is muted.');
G
Gloria 已提交
2888 2889 2890
});
```

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

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

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

2897 2898 2899 2900 2901 2902 2903 2904 2905
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

2931 2932 2933
| Name  | Type                        | Mandatory| Description                                                   |
| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
G
Gloria 已提交
2934 2935 2936 2937

**Example**

```js
2938 2939 2940 2941 2942 2943
audioVolumeGroupManager.isMicrophoneMute((err, value) => {
  if (err) {
    console.error(`Failed to obtain the mute status of the microphone. ${err}`);
    return;
  }
  console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
G
Gloria 已提交
2944 2945 2946
});
```

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

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

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

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

**Return value**

2957 2958 2959
| Type                  | Description                                                        |
| ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
G
Gloria 已提交
2960 2961 2962 2963

**Example**

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

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

2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999
on(type: 'micStateChange', callback: Callback&lt;MicStateChangeEvent&gt;): void

Subscribes to system microphone state change events.

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

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

**Parameters**

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

**Error codes**

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

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

**Example**

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

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

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

3006 3007 3008 3009 3010
### getCurrentAudioRendererInfoArray<sup>9+</sup>

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

Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3011 3012 3013 3014 3015

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

**Parameters**

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

**Example**

```js
3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049
audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
  console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
  if (err) {
    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
  } else {
    if (AudioRendererChangeInfoArray != null) {
      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
        let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }
G
Gloria 已提交
3050 3051 3052
});
```

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

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

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

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

**Return value**

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

**Example**

```js
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097
async function getCurrentAudioRendererInfoArray(){
  await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
    console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
    if (AudioRendererChangeInfoArray != null) {
      for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
        let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
        console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
        console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
        console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
        console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
        console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
        for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }).catch((err) => {
    console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
  });
}
3098
```
G
Gloria 已提交
3099

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

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

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

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

**Parameters**

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

**Example**

```js
3117 3118
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
  console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
3119
  if (err) {
3120
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
3121
  } else {
3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140
    if (AudioCapturerChangeInfoArray != null) {
      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
        }
      }
    }
G
Gloria 已提交
3141 3142 3143 3144
  }
});
```

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

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

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

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

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

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

**Example**

```js
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187
async function getCurrentAudioCapturerInfoArray(){
  await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
    console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
    if (AudioCapturerChangeInfoArray != null) {
      for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
        console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
        console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
        console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
        console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
        console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
        for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
          console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
          console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
          console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
          console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
          console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
          console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
          console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
          console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
        }
      }
    }
  }).catch((err) => {
    console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
  });
}
G
Gloria 已提交
3188 3189
```

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

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

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

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

**Parameters**

3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211
| Name     | Type       | Mandatory     | Description                                                                    |
| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
| type     | string     | Yes       | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.    |
| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes |  Callback used to return the result.       |

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
G
Gloria 已提交
3212 3213 3214 3215

**Example**

```js
3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235
audioStreamManager.on('audioRendererChange',  (AudioRendererChangeInfoArray) => {
  for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
    let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
    console.info(`## RendererChange on is called for ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
    console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
    console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
    console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 
    console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);  
    for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
    }
G
Gloria 已提交
3236 3237 3238 3239
  }
});
```

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

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

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

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

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

3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260
| Name    | Type    | Mandatory| Description             |
| -------- | ------- | ---- | ---------------- |
| type     | string  | Yes  | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.|

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
G
Gloria 已提交
3261 3262 3263 3264

**Example**

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

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

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

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

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

**Parameters**

3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290
| Name    | Type    | Mandatory     | Description                                                                                          |
| -------- | ------- | --------- | ----------------------------------------------------------------------- |
| type     | string  | Yes       | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.    |
| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes    | Callback used to return the result.  |

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
3291 3292

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

```js
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) =>  {
  for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
    console.info(`## CapChange on is called for element ${i} ##`);
    console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
    console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
    console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
    console.info(`Flag  ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
    console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);  
    let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
    for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
      console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
      console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
      console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
      console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
      console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
      console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
      console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
      console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
    }
G
Gloria 已提交
3314
  }
3315 3316
});
```
G
Gloria 已提交
3317

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

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

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

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

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

3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338
| Name      | Type    | Mandatory| Description                                                         |
| -------- | -------- | --- | ------------------------------------------------------------- |
| type     | string   |Yes  | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.|

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
G
Gloria 已提交
3339 3340 3341 3342

**Example**

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

3346 3347
```

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

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

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

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

**Parameters**

3358 3359 3360 3361
| Name    | Type                               | Mandatory| Description                                             |
| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream types.                                     |
| callback   | AsyncCallback&lt;boolean&gt;        | Yes  | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
3362 3363

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

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

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

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

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

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

3383 3384 3385 3386 3387 3388
**Parameters**

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

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

3391 3392 3393
| Type                  | Description                                                    |
| ---------------------- | -------------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
3394 3395

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

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

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

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

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

3409 3410 3411 3412 3413
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void

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

**System capability**: SystemCapability.Multimedia.Audio.Device
3414 3415 3416

**Parameters**

3417 3418 3419 3420
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback   | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes  | Callback used to return the device list.|
3421 3422 3423

**Example**

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| deviceFlag | [DeviceFlag](#deviceflag)                                    | Yes  | Audio device flag.    |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes  | Callback used to return the device update details.                        |

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
3485 3486

**Example**
3487

3488
```js
3489 3490 3491 3492 3493
audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
  console.info('device change type : ' + deviceChanged.type);
  console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
  console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
3494 3495
});
```
3496

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

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

3501
Unsubscribes from device change events.
3502

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

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

3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.|
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No  | Callback used to return the device update details.                        |

**Error codes**

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

| ID| Error Message|
| ------- | --------------------------------------------|
| 6800101 | if input parameter value error              |
3519 3520 3521

**Example**

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

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

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

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

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

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

**Parameters**

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

**Example**
```js
3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559
let inputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.INPUT_DEVICE,
    deviceType : audio.DeviceType.EARPIECE,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3560

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

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

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

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

3577 3578 3579 3580 3581 3582 3583 3584 3585
Selects an audio input device. Only one input device can be selected. This API uses a promise to return the result.

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

**Parameters**

| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
3586 3587 3588

**Return value**

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

**Example**

G
Gloria 已提交
3595
```js
3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608
let inputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.INPUT_DEVICE,
    deviceType : audio.DeviceType.EARPIECE,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3609

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

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

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

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

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

3627
**Parameters**
3628

3629 3630 3631 3632 3633
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.      |
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
3634 3635 3636

**Example**

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

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

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

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

3653 3654 3655 3656 3657 3658 3659 3660
**System capability**: SystemCapability.Multimedia.Audio.Communication

**Parameters**

| Name    | Type                                                  | Mandatory| Description              |
| ---------- | ----------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9)  | Yes  | Communication device type.|
| active     | boolean                                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
3661 3662 3663

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

3686 3687 3688 3689
| Name    | Type                                                 | Mandatory| Description                    |
| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.      |
| callback   | AsyncCallback&lt;boolean&gt;                         | Yes  | Callback used to return the active state of the device.|
3690 3691 3692 3693

**Example**

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

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

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

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

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

**Parameters**

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

**Return value**

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

**Example**

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

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

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

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

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

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

**Parameters**

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

**Example**
```js
3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3763

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

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

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

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

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

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

**Parameters**

3786 3787 3788
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3789 3790 3791

**Return value**

3792 3793 3794
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3795 3796 3797 3798

**Example**

```js
3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3812

3813 3814 3815 3816 3817 3818 3819
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  });
}
3820 3821
```

3822
### selectOutputDeviceByFilter<sup>9+</sup>
3823

3824
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3825

3826
**System API**: This is a system API.
3827

3828 3829 3830
Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
3831 3832 3833

**Parameters**

3834 3835 3836 3837 3838
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| filter                      | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
3839 3840 3841

**Example**
```js
3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
  
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3863

3864 3865 3866 3867 3868 3869 3870 3871
async function selectOutputDeviceByFilter(){
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices by filter result callback: SUCCESS'); }
  });
}
3872 3873
```

3874
### selectOutputDeviceByFilter<sup>9+</sup>
3875

3876
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3877

3878
**System API**: This is a system API.
3879

3880 3881 3882
Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.Audio.Device
3883 3884 3885

**Parameters**

3886 3887 3888 3889
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3890 3891 3892

**Return value**

3893 3894 3895
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3896 3897 3898 3899

**Example**

```js
3900 3901 3902 3903 3904 3905 3906
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3907

3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920
let outputAudioDeviceDescriptor = [{
    deviceRole : audio.DeviceRole.OUTPUT_DEVICE,
    deviceType : audio.DeviceType.SPEAKER,
    id : 1,
    name : "",
    address : "",
    sampleRates : [44100],
    channelCounts : [2],
    channelMasks : [0],
    networkId : audio.LOCAL_NETWORK_ID,
    interruptGroupId : 1,
    volumeGroupId : 1,
}];
3921

3922 3923 3924 3925 3926 3927 3928 3929
async function selectOutputDeviceByFilter(){
  audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices by filter result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  })
}
```
3930

3931
## AudioRendererChangeInfoArray<sup>9+</sup>
3932

3933
Defines an **AudioRenderChangeInfo** array, which is read-only.
3934 3935 3936

**System capability**: SystemCapability.Multimedia.Audio.Renderer

3937
## AudioRendererChangeInfo<sup>9+</sup>
3938

3939 3940 3941 3942 3943 3944 3945 3946 3947 3948
Describes the audio renderer change event.

**System capability**: SystemCapability.Multimedia.Audio.Renderer

| Name          | Type                                     | Readable | Writable | Description                                                |
| ------------- | ---------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
| streamId      | number                                   | Yes      | No       | Unique ID of an audio stream.                              |
| clientUid     | number                                   | Yes      | No       | UID of the audio renderer client.<br>This is a system API. |
| rendererInfo  | [AudioRendererInfo](#audiorendererinfo8) | Yes      | No       | Audio renderer information.                                |
| rendererState | [AudioState](#audiostate)                | Yes      | No       | Audio state.<br>This is a system API.                      |
3949 3950 3951 3952

**Example**

```js
G
Gloria 已提交
3953

3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983
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}`);
    }
3984 3985 3986 3987 3988
  }
});
```


3989
## AudioCapturerChangeInfoArray<sup>9+</sup>
3990

3991
Defines an **AudioCapturerChangeInfo** array, which is read-only.
3992

3993
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3994

3995
## AudioCapturerChangeInfo<sup>9+</sup>
3996

3997
Describes the audio capturer change event.
3998

3999
**System capability**: SystemCapability.Multimedia.Audio.Capturer
4000

4001 4002 4003 4004 4005 4006
| 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.                      |
4007 4008 4009 4010

**Example**

```js
4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034
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}`);
4035
    }
4036 4037 4038
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4039 4040 4041 4042 4043
    }
  }
});
```

4044
## AudioDeviceDescriptors
4045

4046
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.
4047

4048
## AudioDeviceDescriptor
4049

4050
Describes an audio device.
4051

4052
**System capability**: SystemCapability.Multimedia.Audio.Device
4053

4054 4055 4056 4057
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
G
Gloria 已提交
4058
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID, which is unique.                                  |
4059 4060 4061 4062 4063 4064 4065 4066
| name<sup>9+</sup>             | string                    | Yes      | No       | Device name.                                                 |
| address<sup>9+</sup>          | string                    | Yes      | No       | Device address.                                              |
| sampleRates<sup>9+</sup>      | Array&lt;number&gt;       | Yes      | No       | Supported sampling rates.                                    |
| channelCounts<sup>9+</sup>    | Array&lt;number&gt;       | Yes      | No       | Number of channels supported.                                |
| channelMasks<sup>9+</sup>     | Array&lt;number&gt;       | Yes      | No       | Supported channel masks.                                     |
| networkId<sup>9+</sup>        | string                    | Yes      | No       | ID of the device network.<br>This is a system API.           |
| interruptGroupId<sup>9+</sup> | number                    | Yes      | No       | ID of the interruption group to which the device belongs.<br>This is a system API. |
| volumeGroupId<sup>9+</sup>    | number                    | Yes      | No       | ID of the volume group to which the device belongs.<br>This is a system API. |
4067 4068 4069 4070

**Example**

```js
4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087
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');
4088 4089 4090 4091
  }
});
```

4092
## AudioRendererFilter<sup>9+</sup>
4093

4094
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4095

4096
**System API**: This is a system API.
4097

4098 4099 4100 4101 4102
| Name         | Type                                     | Mandatory | Description                                                  |
| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
| uid          | number                                   | Yes       | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No        | Audio renderer information.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer |
| rendererId   | number                                   | No        | Unique ID of an audio stream.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer |
4103

4104
**Example**
4105

4106 4107 4108 4109 4110 4111 4112 4113 4114
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4115

4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126
## AudioRenderer<sup>8+</sup>

Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.

### Attributes

**System capability**: SystemCapability.Multimedia.Audio.Renderer

| Name               | Type                       | Readable | Writable | Description           |
| ------------------ | -------------------------- | -------- | -------- | --------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio renderer state. |
4127 4128 4129 4130

**Example**

```js
4131
let state = audioRenderer.state;
4132 4133
```

4134
### getRendererInfo<sup>8+</sup>
4135

4136
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4137

4138
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4139 4140 4141 4142 4143

**System capability**: SystemCapability.Multimedia.Audio.Renderer

**Parameters**

4144 4145 4146
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
4147 4148 4149 4150

**Example**

```js
4151 4152 4153 4154 4155
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}`);
4156 4157 4158
});
```

4159
### getRendererInfo<sup>8+</sup>
4160

4161
getRendererInfo(): Promise<AudioRendererInfo\>
4162

4163
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4164 4165 4166

**System capability**: SystemCapability.Multimedia.Audio.Renderer

4167
**Return value**
4168

4169 4170 4171
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
4172 4173 4174 4175

**Example**

```js
4176 4177 4178 4179 4180 4181 4182 4183
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}`);
});
4184 4185
```

4186
### getStreamInfo<sup>8+</sup>
4187

4188
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4189

4190
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4191 4192 4193 4194 4195

**System capability**: SystemCapability.Multimedia.Audio.Renderer

**Parameters**

4196 4197 4198
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
4199 4200 4201 4202

**Example**

```js
4203 4204 4205 4206 4207 4208
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}`);
4209 4210 4211
});
```

4212
### getStreamInfo<sup>8+</sup>
4213

4214
getStreamInfo(): Promise<AudioStreamInfo\>
4215

4216
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
4217

4218
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4219

4220 4221 4222 4223 4224
**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
4225 4226 4227 4228

**Example**

```js
4229 4230 4231 4232 4233 4234 4235 4236 4237
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}`);
});
4238
```
4239

4240
### getAudioStreamId<sup>9+</sup>
4241

4242
getAudioStreamId(callback: AsyncCallback<number\>): void
4243

4244
Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4245

4246
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4247

4248 4249
**Parameters**

4250 4251 4252
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
4253

4254 4255
**Example**

G
Gloria 已提交
4256
```js
4257 4258
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4259
});
4260 4261
```

4262
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4263

4264
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4265

4266
Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
4267

4268
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4269 4270

**Return value**
V
Vaidegi B 已提交
4271

4272 4273 4274
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
4275

W
wusongqing 已提交
4276
**Example**
V
Vaidegi B 已提交
4277

G
Gloria 已提交
4278
```js
4279 4280
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4281
}).catch((err) => {
4282
  console.error(`ERROR: ${err}`);
4283 4284
});
```
V
Vaidegi B 已提交
4285

4286
### start<sup>8+</sup>
4287

4288
start(callback: AsyncCallback<void\>): void
4289

4290
Starts the renderer. This API uses an asynchronous callback to return the result.
4291

4292
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4293 4294 4295

**Parameters**

4296 4297 4298
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4299 4300 4301 4302

**Example**

```js
4303
audioRenderer.start((err) => {
4304
  if (err) {
4305
    console.error('Renderer start failed.');
4306
  } else {
4307
    console.info('Renderer start success.');
4308
  }
4309
});
V
Vaidegi B 已提交
4310 4311
```

4312
### start<sup>8+</sup>
G
Gloria 已提交
4313

4314
start(): Promise<void\>
G
Gloria 已提交
4315

4316
Starts the renderer. This API uses a promise to return the result.
G
Gloria 已提交
4317

4318
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4319 4320 4321

**Return value**

4322 4323 4324
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
4325 4326 4327 4328

**Example**

```js
4329 4330
audioRenderer.start().then(() => {
  console.info('Renderer started');
4331
}).catch((err) => {
4332
  console.error(`ERROR: ${err}`);
4333 4334 4335
});
```

4336
### pause<sup>8+</sup>
4337

4338
pause(callback: AsyncCallback\<void>): void
4339

4340
Pauses rendering. This API uses an asynchronous callback to return the result.
4341

4342
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4343 4344 4345

**Parameters**

4346 4347 4348
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4349 4350 4351 4352

**Example**

```js
4353 4354 4355 4356 4357 4358
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4359 4360 4361
});
```

4362
### pause<sup>8+</sup>
4363

4364
pause(): Promise\<void>
4365

4366
Pauses rendering. This API uses a promise to return the result.
4367

4368
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4369 4370 4371

**Return value**

4372 4373 4374
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
4375 4376 4377 4378

**Example**

```js
4379 4380
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4381 4382 4383 4384 4385
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
```

4386
### drain<sup>8+</sup>
4387

4388
drain(callback: AsyncCallback\<void>): void
4389

4390
Drains the playback buffer. This API uses an asynchronous callback to return the result.
4391

4392
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4393 4394 4395 4396

**Parameters**

| Name     | Type                 | Mandatory | Description                         |
4397 4398
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4399 4400 4401 4402

**Example**

```js
4403
audioRenderer.drain((err) => {
4404
  if (err) {
4405
    console.error('Renderer drain failed');
4406
  } else {
4407
    console.info('Renderer drained.');
4408 4409
  }
});
G
Gloria 已提交
4410 4411
```

4412
### drain<sup>8+</sup>
V
Vaidegi B 已提交
4413

4414
drain(): Promise\<void>
V
Vaidegi B 已提交
4415

4416
Drains the playback buffer. This API uses a promise to return the result.
4417

4418
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4419 4420 4421 4422

**Return value**

| Type           | Description                        |
4423 4424
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4425

W
wusongqing 已提交
4426
**Example**
V
Vaidegi B 已提交
4427

G
Gloria 已提交
4428
```js
4429 4430
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
4431
}).catch((err) => {
4432
  console.error(`ERROR: ${err}`);
4433
});
V
Vaidegi B 已提交
4434 4435
```

4436
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4437

4438
stop(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
4439

4440
Stops rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4441

4442
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4443

W
wusongqing 已提交
4444
**Parameters**
V
Vaidegi B 已提交
4445

4446
| Name     | Type                 | Mandatory | Description                         |
4447 4448
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4449

W
wusongqing 已提交
4450
**Example**
V
Vaidegi B 已提交
4451

G
Gloria 已提交
4452
```js
4453
audioRenderer.stop((err) => {
4454
  if (err) {
4455
    console.error('Renderer stop failed');
4456
  } else {
4457
    console.info('Renderer stopped.');
4458
  }
4459
});
V
Vaidegi B 已提交
4460 4461
```

4462
### stop<sup>8+</sup>
4463

4464
stop(): Promise\<void>
V
Vaidegi B 已提交
4465

4466
Stops rendering. This API uses a promise to return the result.
4467

4468
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4469

W
wusongqing 已提交
4470
**Return value**
V
Vaidegi B 已提交
4471

4472
| Type           | Description                        |
4473 4474
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4475

W
wusongqing 已提交
4476
**Example**
V
Vaidegi B 已提交
4477

G
Gloria 已提交
4478
```js
4479 4480
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4481
}).catch((err) => {
4482
  console.error(`ERROR: ${err}`);
4483 4484
});
```
V
Vaidegi B 已提交
4485

4486
### release<sup>8+</sup>
V
Vaidegi B 已提交
4487

4488
release(callback: AsyncCallback\<void>): void
4489

4490
Releases the renderer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4491

4492
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4493

W
wusongqing 已提交
4494
**Parameters**
V
Vaidegi B 已提交
4495

4496
| Name     | Type                 | Mandatory | Description                         |
4497 4498
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4499

W
wusongqing 已提交
4500
**Example**
V
Vaidegi B 已提交
4501

G
Gloria 已提交
4502
```js
4503
audioRenderer.release((err) => {
4504
  if (err) {
4505
    console.error('Renderer release failed');
4506
  } else {
4507
    console.info('Renderer released.');
4508
  }
4509
});
V
Vaidegi B 已提交
4510 4511
```

4512
### release<sup>8+</sup>
V
Vaidegi B 已提交
4513

4514
release(): Promise\<void>
V
Vaidegi B 已提交
4515

4516
Releases the renderer. This API uses a promise to return the result.
4517

4518
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4519

W
wusongqing 已提交
4520
**Return value**
V
Vaidegi B 已提交
4521

4522
| Type           | Description                        |
4523 4524
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4525

W
wusongqing 已提交
4526
**Example**
V
Vaidegi B 已提交
4527

G
Gloria 已提交
4528
```js
4529 4530
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4531
}).catch((err) => {
4532
  console.error(`ERROR: ${err}`);
4533
});
V
Vaidegi B 已提交
4534 4535
```

4536
### write<sup>8+</sup>
V
Vaidegi B 已提交
4537

4538
write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
4539

4540
Writes the buffer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4541

4542
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4543

W
wusongqing 已提交
4544
**Parameters**
V
Vaidegi B 已提交
4545

4546 4547 4548 4549
| 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 已提交
4550

W
wusongqing 已提交
4551
**Example**
V
Vaidegi B 已提交
4552

G
Gloria 已提交
4553
```js
4554
let bufferSize;
4555 4556
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4557 4558
  bufferSize = data;
  }).catch((err) => {
4559
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4560
  });
4561 4562 4563 4564 4565 4566 4567
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 已提交
4568 4569
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4570
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587
let len = stat.size % this.bufferSize == 0 ? Math.floor(stat.size / this.bufferSize) : Math.floor(stat.size / this.bufferSize + 1);
for (let i = 0;i < len; i++) {
    let options = {
      offset: i * this.bufferSize,
      length: this.bufferSize
    }
    let readsize = await fs.read(file.fd, buf, options)
    let writeSize = await new Promise((resolve,reject)=>{
      this.audioRenderer.write(buf,(err,writeSize)=>{
        if(err){
          reject(err)
        }else{
          resolve(writeSize)
        }
      })
    })	  
}
V
Vaidegi B 已提交
4588 4589
```

4590
### write<sup>8+</sup>
V
Vaidegi B 已提交
4591

4592
write(buffer: ArrayBuffer): Promise\<number>
4593

4594
Writes the buffer. This API uses a promise to return the result.
4595

4596
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4597

W
wusongqing 已提交
4598
**Return value**
V
Vaidegi B 已提交
4599

4600 4601 4602
| Type             | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
V
Vaidegi B 已提交
4603

W
wusongqing 已提交
4604
**Example**
V
Vaidegi B 已提交
4605

G
Gloria 已提交
4606
```js
4607
let bufferSize;
4608 4609
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4610 4611
  bufferSize = data;
  }).catch((err) => {
4612
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4613
  });
4614 4615 4616 4617 4618 4619 4620
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 已提交
4621 4622
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4623
let buf = new ArrayBuffer(bufferSize);
G
Gloria 已提交
4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636
let len = stat.size % this.bufferSize == 0 ? Math.floor(stat.size / this.bufferSize) : Math.floor(stat.size / this.bufferSize + 1);
for (let i = 0;i < len; i++) {
    let options = {
      offset: i * this.bufferSize,
      length: this.bufferSize
    }
    let readsize = await fs.read(file.fd, buf, options)
    try{
       let writeSize = await this.audioRenderer.write(buf);
    } catch(err) {
       console.error(`audioRenderer.write err: ${err}`);
    }   
}
V
Vaidegi B 已提交
4637 4638
```

4639
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4640

4641
getAudioTime(callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
4642

4643
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4644

4645
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4646

W
wusongqing 已提交
4647
**Parameters**
V
Vaidegi B 已提交
4648

4649 4650 4651
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
V
Vaidegi B 已提交
4652

W
wusongqing 已提交
4653
**Example**
V
Vaidegi B 已提交
4654

G
Gloria 已提交
4655
```js
4656
audioRenderer.getAudioTime((err, timestamp) => {
4657
  console.info(`Current timestamp: ${timestamp}`);
4658
});
V
Vaidegi B 已提交
4659 4660
```

4661
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4662

4663
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4664

4665
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
4666

4667
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4668

W
wusongqing 已提交
4669
**Return value**
V
Vaidegi B 已提交
4670

4671
| Type             | Description                           |
4672 4673
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4674

W
wusongqing 已提交
4675
**Example**
V
Vaidegi B 已提交
4676

G
Gloria 已提交
4677
```js
4678 4679
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4680
}).catch((err) => {
4681
  console.error(`ERROR: ${err}`);
4682
});
V
Vaidegi B 已提交
4683 4684
```

4685
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4686

4687
getBufferSize(callback: AsyncCallback\<number>): void
V
Vaidegi B 已提交
4688

4689
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4690

4691
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4692

W
wusongqing 已提交
4693
**Parameters**
V
Vaidegi B 已提交
4694

4695
| Name     | Type                   | Mandatory | Description                              |
4696 4697
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4698

W
wusongqing 已提交
4699
**Example**
V
Vaidegi B 已提交
4700

G
Gloria 已提交
4701
```js
4702 4703 4704
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4705
  }
4706
});
V
Vaidegi B 已提交
4707 4708
```

4709
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4710

4711
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4712

4713
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
4714

4715
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4716

W
wusongqing 已提交
4717
**Return value**
V
Vaidegi B 已提交
4718

4719
| Type             | Description                             |
4720 4721
| ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4722

W
wusongqing 已提交
4723
**Example**
V
Vaidegi B 已提交
4724

G
Gloria 已提交
4725
```js
4726
let bufferSize;
4727 4728
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4729
  bufferSize = data;
4730
}).catch((err) => {
4731
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4732
});
V
Vaidegi B 已提交
4733 4734
```

4735
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4736

4737
setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
4738

4739
Sets the render rate. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4740

4741
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4742

W
wusongqing 已提交
4743
**Parameters**
V
Vaidegi B 已提交
4744

4745 4746 4747 4748
| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4749

W
wusongqing 已提交
4750
**Example**
V
Vaidegi B 已提交
4751

G
Gloria 已提交
4752
```js
4753 4754 4755 4756 4757
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.');
4758
  }
4759
});
V
Vaidegi B 已提交
4760 4761
```

4762
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4763

4764
setRenderRate(rate: AudioRendererRate): Promise\<void>
V
Vaidegi B 已提交
4765

4766
Sets the render rate. This API uses a promise to return the result.
V
Vaidegi B 已提交
4767

4768
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4769

W
wusongqing 已提交
4770
**Parameters**
V
Vaidegi B 已提交
4771

4772 4773 4774 4775 4776 4777 4778 4779 4780
| Name | Type                                     | Mandatory | Description        |
| ---- | ---------------------------------------- | --------- | ------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate. |

**Return value**

| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4781

W
wusongqing 已提交
4782
**Example**
V
Vaidegi B 已提交
4783

G
Gloria 已提交
4784
```js
4785 4786 4787 4788
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4789
});
V
Vaidegi B 已提交
4790 4791
```

4792
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4793

4794
getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
V
Vaidegi B 已提交
4795

4796
Obtains the current render rate. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4797

4798
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4799

4800
**Parameters**
V
Vaidegi B 已提交
4801

4802 4803 4804
| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
4805

W
wusongqing 已提交
4806
**Example**
V
Vaidegi B 已提交
4807

G
Gloria 已提交
4808
```js
4809 4810 4811
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
V
Vaidegi B 已提交
4812 4813
```

4814
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4815

4816
getRenderRate(): Promise\<AudioRendererRate>
V
Vaidegi B 已提交
4817

4818
Obtains the current render rate. This API uses a promise to return the result.
V
Vaidegi B 已提交
4819

4820
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4821

4822
**Return value**
V
Vaidegi B 已提交
4823

4824 4825 4826
| Type                                              | Description                                   |
| ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
V
Vaidegi B 已提交
4827

W
wusongqing 已提交
4828
**Example**
V
Vaidegi B 已提交
4829

G
Gloria 已提交
4830
```js
4831 4832 4833 4834
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4835
});
V
Vaidegi B 已提交
4836
```
4837
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
4838

4839
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4840

4841
Sets the audio interruption mode for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4842

4843
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4844

4845
**Parameters**
V
Vaidegi B 已提交
4846

4847 4848 4849
| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
V
Vaidegi B 已提交
4850

4851
**Return value**
4852

4853 4854 4855
| 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 已提交
4856

4857
**Example**
V
Vaidegi B 已提交
4858

4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873
```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 已提交
4874

W
wusongqing 已提交
4875
**Parameters**
V
Vaidegi B 已提交
4876

4877 4878 4879 4880
| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4881

W
wusongqing 已提交
4882
**Example**
V
Vaidegi B 已提交
4883

G
Gloria 已提交
4884
```js
4885 4886 4887 4888
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
4889
  }
4890
  console.info('setInterruptMode Success!');
4891
});
V
Vaidegi B 已提交
4892 4893
```

4894
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4895

4896
setVolume(volume: number): Promise&lt;void&gt;
V
Vaidegi B 已提交
4897

4898
Sets the volume for the application. This API uses a promise to return the result.
V
Vaidegi B 已提交
4899

4900
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4901 4902 4903

**Parameters**

4904 4905 4906
| Name   | Type   | Mandatory | Description                                                  |
| ------ | ------ | --------- | ------------------------------------------------------------ |
| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
4907

W
wusongqing 已提交
4908
**Return value**
V
Vaidegi B 已提交
4909

4910 4911 4912
| 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 已提交
4913

W
wusongqing 已提交
4914
**Example**
V
Vaidegi B 已提交
4915

G
Gloria 已提交
4916
```js
4917 4918 4919 4920
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
4921
});
V
Vaidegi B 已提交
4922
```
4923
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4924

4925
setVolume(volume: number, callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
4926

4927
Sets the volume for the application. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
4928

4929
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4930

W
wusongqing 已提交
4931
**Parameters**
V
Vaidegi B 已提交
4932

4933 4934 4935 4936
| 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 已提交
4937

W
wusongqing 已提交
4938
**Example**
V
Vaidegi B 已提交
4939

G
Gloria 已提交
4940
```js
4941 4942 4943
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
4944
  }
4945
  console.info('setVolume Success!');
4946
});
V
Vaidegi B 已提交
4947 4948
```

4949
### on('audioInterrupt')<sup>9+</sup>
V
Vaidegi B 已提交
4950

4951
on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
4952

4953
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
4954

4955
Same as [on('interrupt')](#oninterruptdeprecated), this API has obtained the focus before **start**, **pause**, or **stop** of **AudioRenderer** is called. Therefore, you do not need to request the focus.
V
Vaidegi B 已提交
4956

4957
**System capability**: SystemCapability.Multimedia.Audio.Interrupt
V
Vaidegi B 已提交
4958

4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972
**Parameters**

| Name     | Type                                         | Mandatory | Description                                                  |
| -------- | -------------------------------------------- | --------- | ------------------------------------------------------------ |
| type     | string                                       | Yes       | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio playback is interrupted. |
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes       | Callback used to return the audio interruption event.        |

**Error codes**

For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md).

| ID      | Error Message                  |
| ------- | ------------------------------ |
| 6800101 | if input parameter value error |
V
Vaidegi B 已提交
4973

W
wusongqing 已提交
4974
**Example**
V
Vaidegi B 已提交
4975

G
Gloria 已提交
4976
```js
4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025
let isPlay;
let started;
onAudioInterrupt();

async function onAudioInterrupt(){
  audioRenderer.on('audioInterrupt', async(interruptEvent) => {
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
          console.info('Force paused. Stop writing');
          isPlay = false;
          break;
        case audio.InterruptHint.INTERRUPT_HINT_STOP:
          console.info('Force stopped. Stop writing');
          isPlay = false;
          break;
      }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
      switch (interruptEvent.hintType) {
        case audio.InterruptHint.INTERRUPT_HINT_RESUME:
          console.info('Resume force paused renderer or ignore');
          await audioRenderer.start().then(async function () {
            console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
            started = true;
          }).catch((err) => {
            console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err}`);
            started = false;
          });
          if (started) {
            isPlay = true;
            console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`);
          } else {
            console.error('AudioInterruptMusic Renderer start failed');
          }
          break;
        case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
          console.info('Choose to pause or ignore');
          if (isPlay == true) {
            isPlay == false;
            console.info('AudioInterruptMusic: Media PAUSE : TRUE');
          } else {
            isPlay = true;
            console.info('AudioInterruptMusic: Media PLAY : TRUE');
          }
          break;
      }
   }
  });
}
V
Vaidegi B 已提交
5026 5027
```

5028
### on('markReach')<sup>8+</sup>
V
Vaidegi B 已提交
5029

5030
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5031

5032
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 已提交
5033

5034
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5035

W
wusongqing 已提交
5036
**Parameters**
5037

5038 5039 5040 5041 5042
| 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 已提交
5043

W
wusongqing 已提交
5044
**Example**
V
Vaidegi B 已提交
5045

G
Gloria 已提交
5046
```js
5047 5048 5049
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5050
  }
5051
});
V
Vaidegi B 已提交
5052 5053 5054
```


5055
### off('markReach') <sup>8+</sup>
5056

5057
off(type: 'markReach'): void
V
Vaidegi B 已提交
5058

5059
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5060

5061
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5062

5063 5064 5065 5066 5067
**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
5068

W
wusongqing 已提交
5069
**Example**
V
Vaidegi B 已提交
5070

G
Gloria 已提交
5071
```js
5072
audioRenderer.off('markReach');
V
Vaidegi B 已提交
5073 5074
```

5075
### on('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5076

5077
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
V
Vaidegi B 已提交
5078

5079
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 已提交
5080

5081
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5082

W
wusongqing 已提交
5083
**Parameters**
5084

5085 5086 5087 5088 5089
| 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 已提交
5090

W
wusongqing 已提交
5091
**Example**
V
Vaidegi B 已提交
5092

G
Gloria 已提交
5093
```js
5094 5095 5096
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5097
  }
5098
});
V
Vaidegi B 已提交
5099 5100
```

5101
### off('periodReach') <sup>8+</sup>
V
Vaidegi B 已提交
5102

5103
off(type: 'periodReach'): void
5104

5105
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5106

5107
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5108

5109
**Parameters**
V
Vaidegi B 已提交
5110

5111 5112 5113
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
5114

W
wusongqing 已提交
5115
**Example**
V
Vaidegi B 已提交
5116

G
Gloria 已提交
5117
```js
5118
audioRenderer.off('periodReach')
V
Vaidegi B 已提交
5119
```
5120

G
Gloria 已提交
5121
### on('stateChange') <sup>8+</sup>
W
wusongqing 已提交
5122

5123
on(type: 'stateChange', callback: Callback<AudioState\>): void
W
wusongqing 已提交
5124

5125
Subscribes to state change events.
W
wusongqing 已提交
5126

5127
**System capability**: SystemCapability.Multimedia.Audio.Renderer
5128

5129
**Parameters**
W
wusongqing 已提交
5130

5131 5132 5133 5134
| 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 已提交
5135

5136
**Example**
W
wusongqing 已提交
5137

5138 5139 5140 5141 5142 5143 5144 5145 5146 5147
```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');
  }
});
```
5148

5149
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5150

5151
Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
V
Vaidegi B 已提交
5152

5153
### Attributes
5154

5155
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5156

5157 5158 5159
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
V
Vaidegi B 已提交
5160

5161
**Example**
V
Vaidegi B 已提交
5162

5163 5164 5165
```js
let state = audioCapturer.state;
```
V
Vaidegi B 已提交
5166

5167
### getCapturerInfo<sup>8+</sup>
5168

5169
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5170

5171
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5172

5173
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5174

W
wusongqing 已提交
5175
**Parameters**
5176

5177 5178 5179
| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
5180

W
wusongqing 已提交
5181
**Example**
5182

G
Gloria 已提交
5183
```js
5184
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5185
  if (err) {
5186 5187 5188 5189 5190
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5191
  }
5192 5193 5194
});
```

5195

5196
### getCapturerInfo<sup>8+</sup>
5197

5198
getCapturerInfo(): Promise<AudioCapturerInfo\>
5199

5200
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
5201

5202
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5203

5204
**Return value**
5205

5206 5207 5208
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
5209

W
wusongqing 已提交
5210
**Example**
5211

G
Gloria 已提交
5212
```js
5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223
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}`);
5224
});
5225 5226
```

5227
### getStreamInfo<sup>8+</sup>
5228

5229
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5230

5231
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5232

5233
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5234

W
wusongqing 已提交
5235
**Parameters**
5236

5237 5238 5239
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5240

W
wusongqing 已提交
5241
**Example**
5242

G
Gloria 已提交
5243
```js
5244
audioCapturer.getStreamInfo((err, streamInfo) => {
5245
  if (err) {
5246 5247 5248 5249 5250 5251 5252
    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}`);
5253
  }
5254 5255 5256
});
```

5257
### getStreamInfo<sup>8+</sup>
5258

5259
getStreamInfo(): Promise<AudioStreamInfo\>
5260

5261
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
5262

5263
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5264 5265 5266

**Return value**

5267 5268 5269
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5270

W
wusongqing 已提交
5271
**Example**
5272

G
Gloria 已提交
5273
```js
5274 5275 5276 5277 5278 5279 5280 5281
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}`);
5282
});
5283
```
V
Vaidegi B 已提交
5284

5285
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5286

5287
getAudioStreamId(callback: AsyncCallback<number\>): void
V
Vaidegi B 已提交
5288

5289
Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5290

5291
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5292

W
wusongqing 已提交
5293
**Parameters**
5294

5295 5296 5297
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5298

W
wusongqing 已提交
5299
**Example**
5300

G
Gloria 已提交
5301
```js
5302 5303
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5304
});
5305
```
V
Vaidegi B 已提交
5306

5307
### getAudioStreamId<sup>9+</sup>
5308

5309 5310 5311
getAudioStreamId(): Promise<number\>

Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result.
5312

5313
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5314 5315 5316

**Return value**

5317 5318 5319
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
5320

W
wusongqing 已提交
5321
**Example**
V
Vaidegi B 已提交
5322

G
Gloria 已提交
5323
```js
5324 5325 5326 5327
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5328
});
V
Vaidegi B 已提交
5329 5330
```

5331
### start<sup>8+</sup>
V
Vaidegi B 已提交
5332

5333
start(callback: AsyncCallback<void\>): void
V
Vaidegi B 已提交
5334

5335
Starts capturing. This API uses an asynchronous callback to return the result.
5336

5337
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5338

W
wusongqing 已提交
5339
**Parameters**
V
Vaidegi B 已提交
5340

5341 5342 5343
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5344

W
wusongqing 已提交
5345
**Example**
V
Vaidegi B 已提交
5346

G
Gloria 已提交
5347
```js
5348
audioCapturer.start((err) => {
5349
  if (err) {
5350 5351 5352
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5353
  }
5354
});
V
Vaidegi B 已提交
5355 5356 5357
```


5358
### start<sup>8+</sup>
V
Vaidegi B 已提交
5359

5360
start(): Promise<void\>
5361

5362
Starts capturing. This API uses a promise to return the result.
5363

5364
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5365

W
wusongqing 已提交
5366
**Return value**
V
Vaidegi B 已提交
5367

5368 5369 5370
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5371

W
wusongqing 已提交
5372
**Example**
V
Vaidegi B 已提交
5373

G
Gloria 已提交
5374
```js
5375 5376 5377 5378 5379 5380 5381 5382 5383 5384
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}`);
5385
});
5386
```
V
Vaidegi B 已提交
5387

5388
### stop<sup>8+</sup>
5389

5390
stop(callback: AsyncCallback<void\>): void
5391

5392
Stops capturing. This API uses an asynchronous callback to return the result.
5393

5394
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5395

W
wusongqing 已提交
5396
**Parameters**
V
Vaidegi B 已提交
5397

5398 5399 5400
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5401

W
wusongqing 已提交
5402
**Example**
V
Vaidegi B 已提交
5403

G
Gloria 已提交
5404
```js
5405
audioCapturer.stop((err) => {
5406
  if (err) {
5407 5408 5409
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5410
  }
5411
});
V
Vaidegi B 已提交
5412 5413
```

5414

5415
### stop<sup>8+</sup>
5416

5417
stop(): Promise<void\>
5418

5419
Stops capturing. This API uses a promise to return the result.
5420

5421
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5422

W
wusongqing 已提交
5423
**Return value**
V
Vaidegi B 已提交
5424

5425 5426 5427
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5428

W
wusongqing 已提交
5429
**Example**
V
Vaidegi B 已提交
5430

G
Gloria 已提交
5431
```js
5432 5433 5434 5435 5436 5437 5438 5439
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}`);
5440
});
V
Vaidegi B 已提交
5441 5442
```

5443
### release<sup>8+</sup>
V
Vaidegi B 已提交
5444

5445
release(callback: AsyncCallback<void\>): void
5446

5447
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
5448

5449
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5450

W
wusongqing 已提交
5451
**Parameters**
5452

5453 5454 5455
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5456

W
wusongqing 已提交
5457
**Example**
5458

G
Gloria 已提交
5459
```js
5460
audioCapturer.release((err) => {
5461
  if (err) {
5462 5463 5464
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5465
  }
5466
});
5467 5468 5469
```


5470
### release<sup>8+</sup>
5471

5472
release(): Promise<void\>
5473

5474
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5475

5476
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5477

W
wusongqing 已提交
5478
**Return value**
5479

5480 5481 5482
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5483

W
wusongqing 已提交
5484
**Example**
5485

G
Gloria 已提交
5486
```js
5487 5488 5489 5490 5491 5492 5493 5494
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}`);
5495 5496 5497
});
```

5498
### read<sup>8+</sup>
5499

5500
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
5501

5502
Reads the buffer. This API uses an asynchronous callback to return the result.
5503

5504
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5505

W
wusongqing 已提交
5506
**Parameters**
5507

5508 5509 5510 5511 5512
| 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.  |
5513

W
wusongqing 已提交
5514
**Example**
5515

G
Gloria 已提交
5516
```js
5517 5518 5519 5520 5521 5522 5523 5524 5525 5526
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');
5527
  }
5528
});
5529 5530
```

5531
### read<sup>8+</sup>
5532

5533
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5534

5535
Reads the buffer. This API uses a promise to return the result.
5536

5537
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5538 5539 5540

**Parameters**

5541 5542 5543 5544
| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
5545

W
wusongqing 已提交
5546
**Return value**
5547

5548 5549 5550
| 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. |
5551

W
wusongqing 已提交
5552
**Example**
5553

G
Gloria 已提交
5554
```js
5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566
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}`);
5567
});
5568
```
5569

5570
### getAudioTime<sup>8+</sup>
5571

5572
getAudioTime(callback: AsyncCallback<number\>): void
5573

5574 5575 5576
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
5577

W
wusongqing 已提交
5578
**Parameters**
5579

5580 5581 5582
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
5583

W
wusongqing 已提交
5584
**Example**
5585

G
Gloria 已提交
5586
```js
5587 5588
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5589
});
5590 5591
```

5592
### getAudioTime<sup>8+</sup>
5593

5594
getAudioTime(): Promise<number\>
5595

5596
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
5597

5598
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5599

W
wusongqing 已提交
5600
**Return value**
5601

5602 5603 5604
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the timestamp. |
5605

W
wusongqing 已提交
5606
**Example**
5607

G
Gloria 已提交
5608
```js
5609 5610 5611 5612
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5613 5614 5615
});
```

5616
### getBufferSize<sup>8+</sup>
5617

5618
getBufferSize(callback: AsyncCallback<number\>): void
5619

5620
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
5621

5622
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5623

W
wusongqing 已提交
5624
**Parameters**
5625

5626 5627 5628
| Name     | Type                   | Mandatory | Description                              |
| :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |
5629

W
wusongqing 已提交
5630
**Example**
5631

G
Gloria 已提交
5632
```js
5633 5634 5635 5636 5637 5638 5639 5640
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}`);
    });
5641
  }
J
jiao_yanlin 已提交
5642
});
5643 5644
```

5645
### getBufferSize<sup>8+</sup>
5646

5647
getBufferSize(): Promise<number\>
5648

5649
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
5650

5651
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5652

W
wusongqing 已提交
5653
**Return value**
5654

5655 5656 5657
| Type             | Description                             |
| :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size. |
5658

W
wusongqing 已提交
5659
**Example**
5660

G
Gloria 已提交
5661
```js
5662 5663 5664 5665 5666 5667
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5668 5669 5670
});
```

5671
### on('markReach')<sup>8+</sup>
5672

5673
on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
5674

5675
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked.
5676

5677
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5678

W
wusongqing 已提交
5679
**Parameters**
5680

5681 5682 5683 5684 5685
| 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.                |
5686

W
wusongqing 已提交
5687
**Example**
5688

G
Gloria 已提交
5689
```js
5690 5691 5692
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5693
  }
5694
});
5695 5696
```

5697
### off('markReach')<sup>8+</sup>
5698

5699
off(type: 'markReach'): void
5700

5701
Unsubscribes from mark reached events.
5702

5703
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5704 5705 5706

**Parameters**

5707 5708 5709
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
5710

W
wusongqing 已提交
5711
**Example**
5712

G
Gloria 已提交
5713
```js
5714
audioCapturer.off('markReach');
5715 5716
```

5717
### on('periodReach')<sup>8+</sup>
5718

5719
on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
5720

5721
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.
5722

5723
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5724

W
wusongqing 已提交
5725
**Parameters**
5726

5727 5728 5729 5730 5731
| 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.                |
5732

W
wusongqing 已提交
5733
**Example**
5734

G
Gloria 已提交
5735
```js
5736 5737 5738
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5739
  }
5740 5741 5742
});
```

5743
### off('periodReach')<sup>8+</sup>
5744

5745
off(type: 'periodReach'): void
5746

5747
Unsubscribes from period reached events.
5748

5749
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5750 5751 5752

**Parameters**

5753 5754 5755
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
5756

W
wusongqing 已提交
5757
**Example**
5758

G
Gloria 已提交
5759
```js
5760
audioCapturer.off('periodReach')
5761 5762
```

G
Gloria 已提交
5763
### on('stateChange') <sup>8+</sup>
5764

5765
on(type: 'stateChange', callback: Callback<AudioState\>): void
5766

5767
Subscribes to state change events.
5768

5769
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5770

W
wusongqing 已提交
5771
**Parameters**
5772

5773 5774 5775 5776
| 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.                    |
5777

W
wusongqing 已提交
5778
**Example**
5779

G
Gloria 已提交
5780
```js
5781 5782 5783 5784 5785 5786
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');
5787
  }
5788 5789 5790
});
```

5791
## ToneType<sup>9+</sup>
5792

5793
Enumerates the tone types of the player.
5794

5795
**System API**: This is a system API.
5796

5797
**System capability**: SystemCapability.Multimedia.Audio.Tone
5798

5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827
| 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.          |
5828

5829
## TonePlayer<sup>9+</sup>
5830

5831
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
5832

5833
**System API**: This is a system API.
5834

5835
### load<sup>9+</sup>
5836

5837
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
5838

5839
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
5840

5841
**System API**: This is a system API.
5842

5843
**System capability**: SystemCapability.Multimedia.Audio.Tone
5844

W
wusongqing 已提交
5845
**Parameters**
5846

5847 5848 5849 5850
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
5851

W
wusongqing 已提交
5852
**Example**
5853

G
Gloria 已提交
5854
```js
5855
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
5856
  if (err) {
5857
    console.error(`callback call load failed error: ${err.message}`);
5858
    return;
5859 5860
  } else {
    console.info('callback call load success');
5861 5862
  }
});
5863 5864
```

5865
### load<sup>9+</sup>
5866

5867
load(type: ToneType): Promise&lt;void&gt;
5868

5869
Loads the DTMF tone configuration. This API uses a promise to return the result.
5870

5871
**System API**: This is a system API.
5872

5873
**System capability**: SystemCapability.Multimedia.Audio.Tone
5874

W
wusongqing 已提交
5875
**Parameters**
5876

5877 5878 5879
| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
5880 5881 5882

**Return value**

5883 5884 5885
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5886

W
wusongqing 已提交
5887
**Example**
5888

G
Gloria 已提交
5889
```js
5890 5891 5892 5893
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
5894
});
5895
```
5896

5897
### start<sup>9+</sup>
5898

5899
start(callback: AsyncCallback&lt;void&gt;): void
5900

5901
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
5902

5903
**System API**: This is a system API.
5904

5905
**System capability**: SystemCapability.Multimedia.Audio.Tone
5906 5907 5908

**Parameters**

5909 5910 5911
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5912 5913 5914 5915

**Example**

```js
5916
tonePlayer.start((err) => {
5917
  if (err) {
5918
    console.error(`callback call start failed error: ${err.message}`);
5919
    return;
5920 5921
  } else {
    console.info('callback call start success');
5922 5923 5924 5925
  }
});
```

5926
### start<sup>9+</sup>
5927

5928
start(): Promise&lt;void&gt;
5929

5930
Starts DTMF tone playing. This API uses a promise to return the result.
5931

5932
**System API**: This is a system API.
5933

5934
**System capability**: SystemCapability.Multimedia.Audio.Tone
5935 5936 5937

**Return value**

5938 5939 5940
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5941 5942 5943 5944

**Example**

```js
5945 5946 5947 5948
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
5949 5950 5951
});
```

5952
### stop<sup>9+</sup>
5953

5954
stop(callback: AsyncCallback&lt;void&gt;): void
5955

5956
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
5957 5958 5959

**System API**: This is a system API.

5960
**System capability**: SystemCapability.Multimedia.Audio.Tone
5961 5962 5963

**Parameters**

5964 5965 5966
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5967 5968 5969 5970

**Example**

```js
5971 5972 5973 5974 5975 5976 5977
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
5978 5979 5980
});
```

5981
### stop<sup>9+</sup>
5982

5983
stop(): Promise&lt;void&gt;
5984

5985
Stops the tone that is being played. This API uses a promise to return the result.
5986

5987
**System API**: This is a system API.
5988

5989
**System capability**: SystemCapability.Multimedia.Audio.Tone
5990

5991
**Return value**
5992

5993 5994 5995
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5996 5997 5998 5999

**Example**

```js
6000 6001 6002 6003
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
6004 6005 6006
});
```

6007
### release<sup>9+</sup>
6008

6009
release(callback: AsyncCallback&lt;void&gt;): void
6010

6011
Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result.
6012

6013
**System API**: This is a system API.
6014

6015
**System capability**: SystemCapability.Multimedia.Audio.Tone
6016 6017 6018

**Parameters**

6019 6020 6021
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6022 6023 6024 6025

**Example**

```js
6026 6027 6028 6029 6030 6031 6032
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6033 6034 6035
});
```

6036
### release<sup>9+</sup>
6037

6038
release(): Promise&lt;void&gt;
6039

6040
Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result.
6041

6042
**System API**: This is a system API.
6043

6044
**System capability**: SystemCapability.Multimedia.Audio.Tone
6045

6046
**Return value**
6047

6048 6049 6050
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6051 6052 6053 6054

**Example**

```js
6055 6056 6057 6058
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6059 6060 6061
});
```

6062
## ActiveDeviceType<sup>(deprecated)</sup>
6063

6064
Enumerates the active device types.
6065

6066 6067 6068
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6069

6070 6071 6072 6073 6074 6075 6076 6077 6078 6079
**System capability**: SystemCapability.Multimedia.Audio.Device

| Name          | Value | Description                                                  |
| ------------- | ----- | ------------------------------------------------------------ |
| SPEAKER       | 2     | Speaker.                                                     |
| BLUETOOTH_SCO | 7     | Bluetooth device using Synchronous Connection Oriented (SCO) links. |

## InterruptActionType<sup>(deprecated)</sup>

Enumerates the returned event types for audio interruption events.
6080 6081 6082 6083 6084 6085

> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.

**System capability**: SystemCapability.Multimedia.Audio.Renderer
6086

6087 6088 6089 6090
| Name           | Value | Description               |
| -------------- | ----- | ------------------------- |
| TYPE_ACTIVATED | 0     | Focus gain event.         |
| TYPE_INTERRUPT | 1     | Audio interruption event. |
6091

6092
## AudioInterrupt<sup>(deprecated)</sup>
6093

6094
Describes input parameters of audio interruption events.
6095

6096 6097 6098
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6099

6100
**System capability**: SystemCapability.Multimedia.Audio.Renderer
6101

6102 6103 6104 6105 6106
| 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. |
6107

6108
## InterruptAction<sup>(deprecated)</sup>
6109

6110
Describes the callback invoked for audio interruption or focus gain events.
6111

6112 6113 6114
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6115

6116
**System capability**: SystemCapability.Multimedia.Audio.Renderer
6117

6118 6119 6120 6121 6122 6123
| 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. |