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

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

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

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

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

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

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

G
Gloria 已提交
22 23
## Constants

24 25
| Name                                   | Type     | Readable | Writable| Description              |
| --------------------------------------- | ----------| ---- | ---- | ------------------ |
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.    |
G
Gloria 已提交
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

687
## VolumeEvent<sup>9+</sup>
V
Vaidegi B 已提交
688

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

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

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

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

G
Gloria 已提交
711 712 713 714
## ConnectType<sup>9+</sup>

Enumerates the types of connected devices.

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

717
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
718

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

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

W
wusongqing 已提交
748
## DeviceChangeAction
749

W
wusongqing 已提交
750
Describes the device connection status and device information.
751

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

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

W
wusongqing 已提交
759
## DeviceChangeType
760

W
wusongqing 已提交
761
Enumerates the device connection statuses.
V
Vaidegi B 已提交
762

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

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

W
wusongqing 已提交
770
## AudioCapturerOptions<sup>8+</sup>
771

W
wusongqing 已提交
772
Describes audio capturer configurations.
773

W
wusongqing 已提交
774
**System capability**: SystemCapability.Multimedia.Audio.Capturer
775

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

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

W
wusongqing 已提交
783
Describes audio capturer information.
784

W
wusongqing 已提交
785
**System capability**: SystemCapability.Multimedia.Audio.Core
786

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

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

W
wusongqing 已提交
794
Enumerates the audio source types.
795

W
wusongqing 已提交
796
**System capability**: SystemCapability.Multimedia.Audio.Core
797

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

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

W
wusongqing 已提交
807
Enumerates the audio scenes.
808

W
wusongqing 已提交
809
**System capability**: SystemCapability.Multimedia.Audio.Communication
810

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

818
## AudioManager
W
wusongqing 已提交
819

W
wusongqing 已提交
820
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 已提交
821

822 823 824
### setAudioParameter

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

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

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

830 831 832
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

**System capability**: SystemCapability.Multimedia.Audio.Core
G
Gloria 已提交
833 834 835

**Parameters**

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

**Example**
843

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

854
### setAudioParameter
G
Gloria 已提交
855

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

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

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

**Return value**

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

**Example**
880

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

887
### getAudioParameter
888

889
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
890

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

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

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

W
wusongqing 已提交
897
**Parameters**
898

899 900 901 902
| 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.|
903

W
wusongqing 已提交
904
**Example**
W
wusongqing 已提交
905

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

916
### getAudioParameter
917

918
getAudioParameter(key: string): Promise&lt;string&gt;
919

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

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

924
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
925

W
wusongqing 已提交
926
**Parameters**
927

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

W
wusongqing 已提交
932
**Return value**
933

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

W
wusongqing 已提交
938
**Example**
W
wusongqing 已提交
939

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

946
### setAudioScene<sup>8+</sup>
W
wusongqing 已提交
947

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

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

952 953 954
**System API**: This is a system API.

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

W
wusongqing 已提交
956
**Parameters**
957

958 959 960 961
| 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.|
962

W
wusongqing 已提交
963
**Example**
W
wusongqing 已提交
964

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

975
### setAudioScene<sup>8+</sup>
V
Vaidegi B 已提交
976

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

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

981 982 983
**System API**: This is a system API.

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

W
wusongqing 已提交
985
**Parameters**
W
wusongqing 已提交
986

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

W
wusongqing 已提交
991
**Return value**
992

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

W
wusongqing 已提交
997
**Example**
W
wusongqing 已提交
998

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

1007
### getAudioScene<sup>8+</sup>
1008

1009
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1010

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

1013
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1014

W
wusongqing 已提交
1015
**Parameters**
W
wusongqing 已提交
1016

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

**Example**
W
wusongqing 已提交
1022

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

1033
### getAudioScene<sup>8+</sup>
W
wusongqing 已提交
1034

1035
getAudioScene\(\): Promise<AudioScene\>
W
wusongqing 已提交
1036

1037
Obtains the audio scene. This API uses a promise to return the result.
1038

1039
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1040

W
wusongqing 已提交
1041
**Return value**
W
wusongqing 已提交
1042

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

W
wusongqing 已提交
1047
**Example**
1048

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

1057
### getVolumeManager<sup>9+</sup>
1058

1059
getVolumeManager(): AudioVolumeManager
1060

1061
Obtains an **AudioVolumeManager** instance.
1062

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

W
wusongqing 已提交
1065
**Example**
W
wusongqing 已提交
1066

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

1071
### getStreamManager<sup>9+</sup>
V
Vaidegi B 已提交
1072

1073
getStreamManager(): AudioStreamManager
W
wusongqing 已提交
1074

1075
Obtains an **AudioStreamManager** instance.
W
wusongqing 已提交
1076

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

1079
**Example**
W
wusongqing 已提交
1080

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

1085
### getRoutingManager<sup>9+</sup>
1086

1087 1088 1089 1090 1091
getRoutingManager(): AudioRoutingManager

Obtains an **AudioRoutingManager** instance.

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

W
wusongqing 已提交
1093
**Example**
W
wusongqing 已提交
1094

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

1099
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1100

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

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

1105 1106
> **NOTE**
>
1107
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1108

G
Gloria 已提交
1109 1110
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1115
**Parameters**
W
wusongqing 已提交
1116

1117 1118 1119 1120 1121
| 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.                                  |
1122

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

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

1135
### setVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1136

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

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

1141 1142
> **NOTE**
>
1143
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1144

G
Gloria 已提交
1145 1146
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

W
wusongqing 已提交
1151
**Parameters**
W
wusongqing 已提交
1152

1153 1154 1155 1156
| 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**.|
1157

W
wusongqing 已提交
1158
**Return value**
1159

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

W
wusongqing 已提交
1164
**Example**
W
wusongqing 已提交
1165

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

1172
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1173

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

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

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

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

W
wusongqing 已提交
1184
**Parameters**
W
wusongqing 已提交
1185

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

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

1203
### getVolume<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1204

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

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

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

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

1215 1216 1217 1218 1219
**Parameters**

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

W
wusongqing 已提交
1221
**Return value**
W
wusongqing 已提交
1222

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

W
wusongqing 已提交
1227
**Example**
W
wusongqing 已提交
1228

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

1235
### getMinVolume<sup>(deprecated)</sup>
1236

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

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

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

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

W
wusongqing 已提交
1247
**Parameters**
W
wusongqing 已提交
1248

1249 1250 1251 1252
| 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 已提交
1253

W
wusongqing 已提交
1254
**Example**
W
wusongqing 已提交
1255

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

1266
### getMinVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1267

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

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

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

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

W
wusongqing 已提交
1278
**Parameters**
W
wusongqing 已提交
1279

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

W
wusongqing 已提交
1284
**Return value**
1285

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

W
wusongqing 已提交
1290
**Example**
W
wusongqing 已提交
1291

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

1298
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1299

1300
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
1301

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

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

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

W
wusongqing 已提交
1310
**Parameters**
W
wusongqing 已提交
1311

1312 1313 1314 1315
| 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 已提交
1316

W
wusongqing 已提交
1317
**Example**
W
wusongqing 已提交
1318

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

1329
### getMaxVolume<sup>(deprecated)</sup>
W
wusongqing 已提交
1330

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

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

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

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

W
wusongqing 已提交
1341
**Parameters**
1342

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

W
wusongqing 已提交
1347
**Return value**
W
wusongqing 已提交
1348

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

W
wusongqing 已提交
1353
**Example**
W
wusongqing 已提交
1354

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

1361
### mute<sup>(deprecated)</sup>
1362

1363
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
1364

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

1367 1368
> **NOTE**
>
1369
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1370 1371

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

W
wusongqing 已提交
1373
**Parameters**
W
wusongqing 已提交
1374

1375 1376 1377 1378 1379
| 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 已提交
1380

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

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

1393
### mute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1394

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

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

1399 1400
> **NOTE**
>
1401
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1402 1403

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

W
wusongqing 已提交
1405
**Parameters**
W
wusongqing 已提交
1406

1407 1408 1409 1410
| 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 已提交
1411

W
wusongqing 已提交
1412
**Return value**
1413

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

W
wusongqing 已提交
1418
**Example**
W
wusongqing 已提交
1419

1420

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

1427
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1428

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

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

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

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

W
wusongqing 已提交
1439
**Parameters**
W
wusongqing 已提交
1440

1441 1442 1443 1444
| 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.|
1445

W
wusongqing 已提交
1446
**Example**
W
wusongqing 已提交
1447

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

1458
### isMute<sup>(deprecated)</sup>
V
Vaidegi B 已提交
1459

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

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

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

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

W
wusongqing 已提交
1470
**Parameters**
1471

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

W
wusongqing 已提交
1476
**Return value**
1477

1478 1479 1480
| 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.|
1481

W
wusongqing 已提交
1482
**Example**
1483

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

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
### 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 已提交
1554

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

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

1559 1560
> **NOTE**
>
1561
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.
1562

1563 1564 1565 1566
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

1567
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1568

W
wusongqing 已提交
1569
**Parameters**
W
wusongqing 已提交
1570

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

W
wusongqing 已提交
1576
**Example**
W
wusongqing 已提交
1577

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

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

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

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

1594 1595
> **NOTE**
>
1596 1597
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. The substitute API is available only for system applications.

1598

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

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

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

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

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

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

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

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

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

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

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

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

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

**Parameters**

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

**Example**

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

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

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

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

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

**Return value**

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

**Example**

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

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

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

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

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

**Parameters**

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

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

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

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

**Example**

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

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

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

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

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

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

1757 1758
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
1759
| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes  | Active audio device type.      |
1760 1761
| 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 已提交
1762

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

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

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

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

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

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

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

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

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

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

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

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

1802

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1893
**Example**
1894

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

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
### 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 已提交
1930

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1985
**Return value**
1986

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

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

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

1999
### on('volumeChange')<sup>9+</sup>
2000

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

2003 2004
> **NOTE**
>
2005
> You are advised to use [on](#on9) in **AudioVolumeManager**.
2006

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

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

2017 2018 2019
| 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.|
2020
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the system volume change event.                                                  |
2021

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

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

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

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

2036
Subscribes to ringer mode change events.
2037

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

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

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

**Example**
2054

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

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

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

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

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

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

2073
**Parameters**
2074

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

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

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

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

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

2095
Unsubscribes from device change events.
2096

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

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

2103
**Parameters**
2104

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

**Example**

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

2118
### on('interrupt')
2119

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

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

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

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

W
wusongqing 已提交
2128
**Parameters**
2129

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

W
wusongqing 已提交
2136
**Example**
2137

G
Gloria 已提交
2138
```js
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
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} `);
2152
  }
2153
});
2154 2155
```

2156
### off('interrupt')
2157

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

2160
Unsubscribes from audio interruption events.
2161

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

W
wusongqing 已提交
2164
**Parameters**
2165

2166 2167 2168 2169 2170
| 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.                                      |
2171

W
wusongqing 已提交
2172
**Example**
2173

G
Gloria 已提交
2174
```js
2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185
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} `);
  }
});
2186 2187
```

2188
## AudioVolumeManager<sup>9+</sup>
2189

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

2192
### getVolumeGroupInfos<sup>9+</sup>
2193

2194 2195 2196 2197 2198 2199 2200
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
2201

W
wusongqing 已提交
2202
**Parameters**
2203

2204 2205 2206 2207
| 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.|
2208

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

2220
### getVolumeGroupInfos<sup>9+</sup>
2221

2222
getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\>
2223

2224
Obtains the volume groups. This API uses a promise to return the result.
2225

2226 2227 2228
**System API**: This is a system API.

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

2230 2231
**Parameters**

2232 2233 2234
| Name    | Type              | Mandatory| Description                |
| ---------- | ------------------| ---- | -------------------- |
| networkId | string             | Yes  | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**.  |
2235

W
wusongqing 已提交
2236
**Return value**
2237

2238 2239 2240
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
2241

W
wusongqing 已提交
2242
**Example**
2243

G
Gloria 已提交
2244
```js
2245 2246 2247 2248 2249
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))
}
```
2250

2251
### getVolumeGroupManager<sup>9+</sup>
2252

2253
getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void
2254

2255
Obtains the audio group manager. This API uses an asynchronous callback to return the result.
2256

2257
**System capability**: SystemCapability.Multimedia.Audio.Volume
2258 2259 2260

**Parameters**

G
Gloria 已提交
2261 2262
| Name    | Type                                                        | Mandatory| Description                |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
2263 2264
| groupId    | number                                    | Yes  | Volume group ID.    |
| callback   | AsyncCallback&lt;[AudioVolumeGroupManager](#audiovolumegroupmanager9)&gt; | Yes  | Callback used to return the audio group manager.|
2265 2266

**Example**
2267

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

2278 2279
```

2280
### getVolumeGroupManager<sup>9+</sup>
2281

2282
getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\>
2283

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

2286
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2287 2288 2289

**Parameters**

2290 2291 2292
| Name    | Type                                     | Mandatory| Description             |
| ---------- | ---------------------------------------- | ---- | ---------------- |
| groupId    | number                                   | Yes  | Volume group ID.    |
2293 2294 2295

**Return value**

2296 2297 2298
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt; [AudioVolumeGroupManager](#audiovolumegroupmanager9) &gt; | Promise used to return the audio group manager.|
2299 2300

**Example**
G
Gloria 已提交
2301 2302

```js
2303 2304 2305 2306 2307 2308 2309 2310
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.');
}

2311 2312
```

2313
### on('volumeChange')<sup>9+</sup>
2314

2315
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
2316

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

2319
**System capability**: SystemCapability.Multimedia.Audio.Volume
2320 2321 2322

**Parameters**

2323 2324 2325
| 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.|
2326
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes  | Callback used to return the system volume change event.                                                  |
G
Gloria 已提交
2327

2328
**Error codes**
2329

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

2332 2333
| ID| Error Message|
| ------- | --------------------------------------------|
2334
| 6800101 | if input parameter value error              |
2335 2336

**Example**
G
Gloria 已提交
2337 2338

```js
2339 2340 2341 2342
audioVolumeManager.on('volumeChange', (volumeEvent) => {
  console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
  console.info(`Volume level: ${volumeEvent.volume} `);
  console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
2343
});
2344
```
2345

2346
## AudioVolumeGroupManager<sup>9+</sup>
2347

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

2350
### setVolume<sup>9+</sup>
2351

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

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

2356
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2357

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

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

2362 2363 2364 2365 2366 2367 2368 2369 2370
**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.                                  |
2371 2372 2373 2374

**Example**

```js
2375 2376 2377 2378 2379 2380
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.');
2381 2382 2383
});
```

2384
### setVolume<sup>9+</sup>
G
Gloria 已提交
2385

2386
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
2387

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

2390
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2391

2392
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
G
Gloria 已提交
2393 2394 2395

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

2396
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2397 2398 2399

**Parameters**

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

**Return value**

2407 2408 2409
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2410 2411 2412 2413

**Example**

```js
2414 2415 2416
audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
  console.info('Promise returned to indicate a successful volume setting.');
});
G
Gloria 已提交
2417 2418
```

2419
### getVolume<sup>9+</sup>
G
Gloria 已提交
2420

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

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

2425
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2426 2427 2428

**Parameters**

2429 2430 2431 2432
| 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 已提交
2433 2434 2435 2436

**Example**

```js
2437
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
2438
  if (err) {
2439
    console.error(`Failed to obtain the volume. ${err}`);
2440
    return;
G
Gloria 已提交
2441
  }
2442
  console.info('Callback invoked to indicate that the volume is obtained.');
2443
});
G
Gloria 已提交
2444 2445
```

2446
### getVolume<sup>9+</sup>
G
Gloria 已提交
2447

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

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

2452
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2453 2454 2455

**Parameters**

2456 2457 2458
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2459 2460 2461

**Return value**

2462 2463 2464
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
G
Gloria 已提交
2465 2466 2467 2468

**Example**

```js
2469 2470
audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
2471
});
G
Gloria 已提交
2472 2473
```

2474
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2475

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

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

2480
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2481 2482 2483

**Parameters**

2484 2485 2486 2487
| 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 已提交
2488 2489 2490 2491

**Example**

```js
2492
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2493
  if (err) {
2494
    console.error(`Failed to obtain the minimum volume. ${err}`);
G
Gloria 已提交
2495 2496
    return;
  }
2497
  console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
G
Gloria 已提交
2498 2499 2500
});
```

2501
### getMinVolume<sup>9+</sup>
G
Gloria 已提交
2502

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

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

2507
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2508 2509 2510

**Parameters**

2511 2512 2513
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2514 2515 2516

**Return value**

2517 2518 2519
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
G
Gloria 已提交
2520 2521 2522 2523

**Example**

```js
2524 2525
audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
  console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
G
Gloria 已提交
2526 2527 2528
});
```

2529
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2530

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

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

2535
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2536 2537 2538

**Parameters**

2539 2540 2541 2542
| 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 已提交
2543 2544

**Example**
2545

G
Gloria 已提交
2546
```js
2547 2548 2549 2550 2551 2552 2553
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 已提交
2554 2555
```

2556
### getMaxVolume<sup>9+</sup>
G
Gloria 已提交
2557

2558
getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
2559

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

2562
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2563 2564 2565

**Parameters**

2566 2567 2568
| Name    | Type                               | Mandatory| Description        |
| ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.|
G
Gloria 已提交
2569 2570 2571

**Return value**

2572 2573 2574
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
G
Gloria 已提交
2575 2576 2577 2578

**Example**

```js
2579 2580 2581
audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
  console.info('Promised returned to indicate that the maximum volume is obtained.');
});
2582
```
G
Gloria 已提交
2583

2584
### mute<sup>9+</sup>
2585

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

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

2590
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2591

2592 2593 2594 2595 2596
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 已提交
2597 2598 2599

**Parameters**

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

**Example**

2608 2609 2610 2611 2612 2613 2614 2615
```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.');
});
2616
```
G
Gloria 已提交
2617

2618
### mute<sup>9+</sup>
G
Gloria 已提交
2619

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

2622
Mutes or unmutes a stream. This API uses a promise to return the result.
2623

2624
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
2625

2626 2627 2628 2629 2630
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 已提交
2631 2632 2633

**Parameters**

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

**Return value**

2641 2642 2643
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2644 2645 2646 2647

**Example**

```js
2648 2649 2650
audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
  console.info('Promise returned to indicate that the stream is muted.');
});
G
Gloria 已提交
2651 2652
```

2653
### isMute<sup>9+</sup>
G
Gloria 已提交
2654

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

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

2659
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2660

2661
**Parameters**
G
Gloria 已提交
2662

2663 2664 2665 2666
| 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 已提交
2667 2668 2669 2670

**Example**

```js
2671
audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
2672
  if (err) {
2673 2674
    console.error(`Failed to obtain the mute status. ${err}`);
    return;
G
Gloria 已提交
2675
  }
2676
  console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
G
Gloria 已提交
2677
});
2678
```
G
Gloria 已提交
2679

2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704
### 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}.`);
2705 2706
});
```
G
Gloria 已提交
2707

2708
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2709

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

2712
Sets the ringer mode. This API uses an asynchronous callback to return the result.
2713

2714
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2715

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

2718
**System API**: This is a system API.
G
Gloria 已提交
2719

2720
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2721

2722 2723 2724 2725 2726 2727
**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 已提交
2728 2729 2730 2731

**Example**

```js
2732
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
2733
  if (err) {
2734 2735
    console.error(`Failed to set the ringer mode.​ ${err}`);
    return;
2736
  }
2737
  console.info('Callback invoked to indicate a successful setting of the ringer mode.');
2738 2739
});
```
G
Gloria 已提交
2740

2741
### setRingerMode<sup>9+</sup>
G
Gloria 已提交
2742

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

2745
Sets the ringer mode. This API uses a promise to return the result.
2746

2747
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
G
Gloria 已提交
2748

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

2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765
**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 已提交
2766 2767 2768 2769

**Example**

```js
2770 2771 2772 2773
audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
  console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```
2774

2775
### getRingerMode<sup>9+</sup>
2776

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

2801 2802 2803 2804 2805
### getRingerMode<sup>9+</sup>

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

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

2807
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2808

2809
**Return value**
2810

2811 2812 2813
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
G
Gloria 已提交
2814

2815
**Example**
G
Gloria 已提交
2816

2817
```js
2818 2819 2820
audioVolumeGroupManager.getRingerMode().then((value) => {
  console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
});
2821
```
G
Gloria 已提交
2822

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

2825
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
2826

2827
Subscribes to ringer mode change events.
2828

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

2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844
**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 已提交
2845 2846 2847 2848

**Example**

```js
2849 2850 2851
audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => {
  console.info(`Updated ringermode: ${ringerMode}`);
});
G
Gloria 已提交
2852
```
2853
### setMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2854

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

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

2859
**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG
2860

2861
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2862 2863 2864

**Parameters**

2865 2866 2867 2868
| 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 已提交
2869 2870 2871 2872

**Example**

```js
2873 2874 2875 2876 2877 2878
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 已提交
2879 2880 2881
});
```

2882
### setMicrophoneMute<sup>9+</sup>
2883

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

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

2888 2889 2890 2891 2892 2893 2894 2895 2896
**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 已提交
2897 2898 2899

**Return value**

2900 2901 2902
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
G
Gloria 已提交
2903 2904 2905 2906

**Example**

```js
2907 2908
audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
  console.info('Promise returned to indicate that the microphone is muted.');
G
Gloria 已提交
2909 2910 2911
});
```

2912
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2913

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

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

2918
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2919 2920 2921

**Parameters**

2922 2923 2924
| 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 已提交
2925 2926 2927 2928

**Example**

```js
2929 2930 2931 2932 2933 2934
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 已提交
2935 2936 2937
});
```

2938
### isMicrophoneMute<sup>9+</sup>
G
Gloria 已提交
2939

2940
isMicrophoneMute(): Promise&lt;boolean&gt;
G
Gloria 已提交
2941

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

2944
**System capability**: SystemCapability.Multimedia.Audio.Volume
G
Gloria 已提交
2945 2946 2947

**Return value**

2948 2949 2950
| 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 已提交
2951 2952 2953 2954

**Example**

```js
2955 2956
audioVolumeGroupManager.isMicrophoneMute().then((value) => {
  console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
2957
});
2958 2959 2960
```

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

2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990
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 已提交
2991 2992
```

2993
## AudioStreamManager<sup>9+</sup>
G
Gloria 已提交
2994

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

2997 2998 2999 3000 3001
### 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 已提交
3002 3003 3004 3005 3006

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

**Parameters**

3007 3008 3009
| Name    | Type                                | Mandatory    | Description                        |
| -------- | ----------------------------------- | -------- | --------------------------- |
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes    |  Callback used to return the audio renderer information.|
G
Gloria 已提交
3010 3011 3012 3013

**Example**

```js
3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040
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 已提交
3041 3042 3043
});
```

3044
### getCurrentAudioRendererInfoArray<sup>9+</sup>
G
Gloria 已提交
3045

3046
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
G
Gloria 已提交
3047

3048
Obtains the information about the current audio renderer. This API uses a promise to return the result.
G
Gloria 已提交
3049 3050 3051 3052 3053

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

**Return value**

3054 3055 3056
| Type                                                                             | Description                                   |
| ---------------------------------------------------------------------------------| --------------------------------------- |
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)>          | Promise used to return the audio renderer information.     |
G
Gloria 已提交
3057 3058 3059 3060

**Example**

```js
3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088
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}`);
  });
}
3089
```
G
Gloria 已提交
3090

3091
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
3092

3093
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
3094

3095
Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3096 3097 3098 3099 3100

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

**Parameters**

3101 3102 3103
| Name       | Type                                | Mandatory     | Description                                                     |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
| callback   | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes   | Callback used to return the audio capturer information.|
G
Gloria 已提交
3104 3105 3106 3107

**Example**

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

3136
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
G
Gloria 已提交
3137

3138
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
G
Gloria 已提交
3139

3140
Obtains the information about the current audio capturer. This API uses a promise to return the result.
G
Gloria 已提交
3141 3142 3143

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

3144
**Return value**
G
Gloria 已提交
3145

3146 3147 3148
| Type                                                                        | Description                                |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)>      | Promise used to return the audio capturer information. |
G
Gloria 已提交
3149 3150 3151 3152

**Example**

```js
3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178
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 已提交
3179 3180
```

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

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

3185
Subscribes to audio renderer change events.
G
Gloria 已提交
3186

3187
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3188 3189 3190

**Parameters**

3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202
| 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 已提交
3203 3204 3205 3206

**Example**

```js
3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226
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 已提交
3227 3228 3229 3230
  }
});
```

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

3233
off(type: "audioRendererChange"): void
G
Gloria 已提交
3234

3235
Unsubscribes from audio renderer change events.
G
Gloria 已提交
3236

3237
**System capability**: SystemCapability.Multimedia.Audio.Renderer
G
Gloria 已提交
3238

3239
**Parameters**
G
Gloria 已提交
3240

3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251
| 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 已提交
3252 3253 3254 3255

**Example**

```js
3256 3257
audioStreamManager.off('audioRendererChange');
console.info('######### RendererChange Off is called #########');
3258 3259
```

3260
### on('audioCapturerChange')<sup>9+</sup>
3261

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

3264
Subscribes to audio capturer change events.
G
Gloria 已提交
3265

3266
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3267 3268 3269

**Parameters**

3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281
| 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              |
3282 3283

**Example**
G
Gloria 已提交
3284 3285

```js
3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304
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 已提交
3305
  }
3306 3307
});
```
G
Gloria 已提交
3308

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

3311
off(type: "audioCapturerChange"): void;
G
Gloria 已提交
3312

3313
Unsubscribes from audio capturer change events.
G
Gloria 已提交
3314

3315
**System capability**: SystemCapability.Multimedia.Audio.Capturer
G
Gloria 已提交
3316

3317
**Parameters**
G
Gloria 已提交
3318

3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329
| 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 已提交
3330 3331 3332 3333

**Example**

```js
3334 3335
audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########');
3336

3337 3338
```

3339
### isActive<sup>9+</sup>
3340

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

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

3345
**System capability**: SystemCapability.Multimedia.Audio.Renderer
3346 3347 3348

**Parameters**

3349 3350 3351 3352
| 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.|
3353 3354

**Example**
G
Gloria 已提交
3355 3356

```js
3357
audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
G
Gloria 已提交
3358
  if (err) {
3359 3360
    console.error(`Failed to obtain the active status of the stream. ${err}`);
    return;
G
Gloria 已提交
3361
  }
3362
  console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
G
Gloria 已提交
3363
});
3364 3365
```

3366
### isActive<sup>9+</sup>
3367

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

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

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

3374 3375 3376 3377 3378 3379
**Parameters**

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

3380
**Return value**
G
Gloria 已提交
3381

3382 3383 3384
| 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.|
3385 3386

**Example**
G
Gloria 已提交
3387 3388

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

3394
## AudioRoutingManager<sup>9+</sup>
3395

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

3398
### getDevices<sup>9+</sup>
3399

3400 3401 3402 3403 3404
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
3405 3406 3407

**Parameters**

3408 3409 3410 3411
| 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.|
3412 3413 3414

**Example**

3415
```js
3416
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
3417
  if (err) {
3418 3419
    console.error(`Failed to obtain the device list. ${err}`);
    return;
3420
  }
3421
  console.info('Callback invoked to indicate that the device list is obtained.');
3422 3423
});
```
3424

3425
### getDevices<sup>9+</sup>
3426

3427
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
3428

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

3431 3432 3433 3434 3435 3436 3437
**System capability**: SystemCapability.Multimedia.Audio.Device

**Parameters**

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

**Return value**

3441 3442 3443
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
3444 3445 3446 3447

**Example**

```js
3448 3449
audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
  console.info('Promise returned to indicate that the device list is obtained.');
3450
});
3451 3452
```

3453
### on<sup>9+</sup>
3454

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

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

3459
**System capability**: SystemCapability.Multimedia.Audio.Device
3460 3461 3462

**Parameters**

3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475
| 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              |
3476 3477

**Example**
3478

3479
```js
3480 3481 3482 3483 3484
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);
3485 3486
});
```
3487

3488
### off<sup>9+</sup>
3489

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

3492
Unsubscribes from device change events.
3493

3494
**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3495

3496
**Parameters**
G
Gloria 已提交
3497

3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509
| 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              |
3510 3511 3512

**Example**

G
Gloria 已提交
3513
```js
3514 3515
audioRoutingManager.off('deviceChange', (deviceChanged) => {
  console.info('Should be no callback.');
3516 3517
});
```
G
Gloria 已提交
3518

3519
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3520

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

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

3525 3526 3527
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
G
Gloria 已提交
3528 3529 3530

**Parameters**

3531 3532 3533 3534
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices           | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Input device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
G
Gloria 已提交
3535 3536 3537

**Example**
```js
3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550
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,
}];
3551

3552 3553 3554 3555 3556 3557 3558 3559
async function selectInputDevice(){
  audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select input devices result callback: SUCCESS'); }
  });
}
3560 3561
```

3562
### selectInputDevice<sup>9+</sup>
G
Gloria 已提交
3563

3564
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3565

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

3568 3569 3570 3571 3572 3573 3574 3575 3576
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.              |
3577 3578 3579

**Return value**

3580 3581 3582
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3583 3584 3585

**Example**

G
Gloria 已提交
3586
```js
3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599
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,
}];
3600

3601 3602 3603 3604 3605 3606 3607
async function getRoutingManager(){
    audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
      console.info('Select input devices result promise: SUCCESS');
    }).catch((err) => {
      console.error(`Result ERROR: ${err}`);
    });
}
3608 3609
```

3610
### setCommunicationDevice<sup>9+</sup>
3611

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

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

3616
**System capability**: SystemCapability.Multimedia.Audio.Communication
3617

3618
**Parameters**
3619

3620 3621 3622 3623 3624
| 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.|
3625 3626 3627

**Example**

G
Gloria 已提交
3628
```js
3629
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => {
3630
  if (err) {
3631 3632
    console.error(`Failed to set the active status of the device. ${err}`);
    return;
3633
  }
3634
  console.info('Callback invoked to indicate that the device is set to the active status.');
3635
});
3636 3637
```

3638
### setCommunicationDevice<sup>9+</sup>
3639

3640
setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise&lt;void&gt;
3641

3642
Sets a communication device to the active state. This API uses a promise to return the result.
3643

3644 3645 3646 3647 3648 3649 3650 3651
**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.    |
3652 3653 3654

**Return value**

3655 3656 3657
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
3658 3659 3660 3661

**Example**

```js
3662 3663
audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
  console.info('Promise returned to indicate that the device is set to the active status.');
3664 3665 3666
});
```

3667
### isCommunicationDeviceActive<sup>9+</sup>
3668

3669
isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
3670

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

3673
**System capability**: SystemCapability.Multimedia.Audio.Communication
3674 3675 3676

**Parameters**

3677 3678 3679 3680
| 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.|
3681 3682 3683 3684

**Example**

```js
3685
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => {
3686
  if (err) {
3687 3688
    console.error(`Failed to obtain the active status of the device. ${err}`);
    return;
3689
  }
3690
  console.info('Callback invoked to indicate that the active status of the device is obtained.');
3691 3692 3693
});
```

3694
### isCommunicationDeviceActive<sup>9+</sup>
3695

3696
isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise&lt;boolean&gt;
3697

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

3700
**System capability**: SystemCapability.Multimedia.Audio.Communication
3701 3702 3703

**Parameters**

3704 3705 3706
| Name    | Type                                                 | Mandatory| Description              |
| ---------- | ---------------------------------------------------- | ---- | ------------------ |
| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes  | Communication device type.|
3707 3708 3709

**Return value**

3710 3711 3712
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
3713 3714 3715 3716

**Example**

```js
3717 3718
audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => {
  console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
3719 3720 3721
});
```

3722
### selectOutputDevice<sup>9+</sup>
3723

3724
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
3725

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

3728 3729 3730
**System API**: This is a system API.

**System capability**: SystemCapability.Multimedia.Audio.Device
3731 3732 3733

**Parameters**

3734 3735 3736 3737
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
| callback                    | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
3738 3739 3740

**Example**
```js
3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753
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,
}];
3754

3755 3756 3757 3758 3759 3760 3761 3762
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
    if (err) {
      console.error(`Result ERROR: ${err}`);
    } else {
      console.info('Select output devices result callback: SUCCESS'); }
  });
}
3763 3764
```

3765
### selectOutputDevice<sup>9+</sup>
3766

3767
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3768

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

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

3773
**System capability**: SystemCapability.Multimedia.Audio.Device
3774 3775 3776

**Parameters**

3777 3778 3779
| Name                      | Type                                                        | Mandatory| Description                     |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| outputAudioDevices          | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3780 3781 3782

**Return value**

3783 3784 3785
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3786 3787 3788 3789

**Example**

```js
3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802
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,
}];
3803

3804 3805 3806 3807 3808 3809 3810
async function selectOutputDevice(){
  audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
    console.info('Select output devices result promise: SUCCESS');
  }).catch((err) => {
    console.error(`Result ERROR: ${err}`);
  });
}
3811 3812
```

3813
### selectOutputDeviceByFilter<sup>9+</sup>
3814

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

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

3819 3820 3821
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
3822 3823 3824

**Parameters**

3825 3826 3827 3828 3829
| 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.|
3830 3831 3832

**Example**
```js
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853
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,
}];
3854

3855 3856 3857 3858 3859 3860 3861 3862
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'); }
  });
}
3863 3864
```

3865
### selectOutputDeviceByFilter<sup>9+</sup>
3866

3867
selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
3868

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

3871 3872 3873
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
3874 3875 3876

**Parameters**

3877 3878 3879 3880
| Name                | Type                                                        | Mandatory| Description                     |
| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
| filter                | [AudioRendererFilter](#audiorendererfilter9)                 | Yes  | Filter criteria.              |
| outputAudioDevices    | [AudioDeviceDescriptors](#audiodevicedescriptors)            | Yes  | Output device.              |
3881 3882 3883

**Return value**

3884 3885 3886
| Type                 | Description                        |
| --------------------- | --------------------------- |
| Promise&lt;void&gt;   | Promise used to return the result.|
3887 3888 3889 3890

**Example**

```js
3891 3892 3893 3894 3895 3896 3897
let outputAudioRendererFilter = {
  uid : 20010041,
  rendererInfo : {
    content : audio.ContentType.CONTENT_TYPE_MUSIC,
    usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
    rendererFlags : 0 },
  rendererId : 0 };
3898

3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911
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,
}];
3912

3913 3914 3915 3916 3917 3918 3919 3920
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}`);
  })
}
```
3921

3922
## AudioRendererChangeInfoArray<sup>9+</sup>
3923

3924
Defines an **AudioRenderChangeInfo** array, which is read-only.
3925 3926 3927

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

3928
## AudioRendererChangeInfo<sup>9+</sup>
3929

3930 3931 3932 3933
Describes the audio renderer change event.

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

3934 3935 3936 3937 3938 3939 3940
| Name              | Type                                              | Readable | Writable | Description                                                |
| ----------------- | ------------------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
| streamId          | number                                            | Yes      | No       | Unique ID of an audio stream.                              |
| clientUid         | number                                            | Yes      | No       | UID of the audio renderer client.<br>This is a system API. |
| rendererInfo      | [AudioRendererInfo](#audiorendererinfo8)          | Yes      | No       | Audio renderer information.                                |
| rendererState     | [AudioState](#audiostate)                         | Yes      | No       | Audio state.<br>This is a system API.                      |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
3941 3942 3943 3944

**Example**

```js
G
Gloria 已提交
3945

3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975
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}`);
    }
3976 3977 3978 3979 3980
  }
});
```


3981
## AudioCapturerChangeInfoArray<sup>9+</sup>
3982

3983
Defines an **AudioCapturerChangeInfo** array, which is read-only.
3984

3985
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3986

3987
## AudioCapturerChangeInfo<sup>9+</sup>
3988

3989
Describes the audio capturer change event.
3990

3991
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3992

3993 3994 3995 3996 3997 3998 3999
| Name              | Type                                              | Readable | Writable | Description                                                |
| ----------------- | ------------------------------------------------- | -------- | -------- | ---------------------------------------------------------- |
| streamId          | number                                            | Yes      | No       | Unique ID of an audio stream.                              |
| clientUid         | number                                            | Yes      | No       | UID of the audio capturer client.<br>This is a system API. |
| capturerInfo      | [AudioCapturerInfo](#audiocapturerinfo8)          | Yes      | No       | Audio capturer information.                                |
| capturerState     | [AudioState](#audiostate)                         | Yes      | No       | Audio state.<br>This is a system API.                      |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes      | No       | Audio device description.                                  |
4000 4001 4002 4003

**Example**

```js
4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027
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}`);
4028
    }
4029 4030 4031
    if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
      resultFlag = true;
      console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
4032 4033 4034 4035 4036
    }
  }
});
```

4037
## AudioDeviceDescriptors
4038

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

4041
## AudioDeviceDescriptor
4042

4043
Describes an audio device.
4044

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

4047 4048 4049 4050
| Name                          | Type                      | Readable | Writable | Description                                                  |
| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole                    | [DeviceRole](#devicerole) | Yes      | No       | Device role.                                                 |
| deviceType                    | [DeviceType](#devicetype) | Yes      | No       | Device type.                                                 |
G
Gloria 已提交
4051
| id<sup>9+</sup>               | number                    | Yes      | No       | Device ID, which is unique.                                  |
4052 4053 4054 4055 4056 4057 4058 4059
| 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. |
4060 4061 4062 4063

**Example**

```js
4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080
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');
4081 4082 4083 4084
  }
});
```

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

4087
Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance.
4088

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

4091 4092
| Name         | Type                                     | Mandatory | Description                                                  |
| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
4093
| uid          | number                                   | Yes        | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core |
4094 4095
| 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 |
4096

4097
**Example**
4098

4099 4100 4101 4102 4103 4104 4105 4106 4107
```js
let outputAudioRendererFilter = {
  "uid":20010041,
  "rendererInfo": {
    "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
    "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
    "rendererFlags":0 },
  "rendererId":0 };
```
4108

4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119
## 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. |
4120 4121 4122 4123

**Example**

```js
4124
let state = audioRenderer.state;
4125 4126
```

4127
### getRendererInfo<sup>8+</sup>
4128

4129
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
4130

4131
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4132 4133 4134 4135 4136

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

**Parameters**

4137 4138 4139
| Name     | Type                                                     | Mandatory | Description                                       |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes       | Callback used to return the renderer information. |
4140 4141 4142 4143

**Example**

```js
4144 4145 4146 4147 4148
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}`);
4149 4150 4151
});
```

4152
### getRendererInfo<sup>8+</sup>
4153

4154
getRendererInfo(): Promise<AudioRendererInfo\>
4155

4156
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
4157 4158 4159

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

4160
**Return value**
4161

4162 4163 4164
| Type                                               | Description                                      |
| -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
4165 4166 4167 4168

**Example**

```js
4169 4170 4171 4172 4173 4174 4175 4176
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}`);
});
4177 4178
```

4179
### getStreamInfo<sup>8+</sup>
4180

4181
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
4182

4183
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
4184 4185 4186 4187 4188

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

**Parameters**

4189 4190 4191
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
4192 4193 4194 4195

**Example**

```js
4196 4197 4198 4199 4200 4201
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}`);
4202 4203 4204
});
```

4205
### getStreamInfo<sup>8+</sup>
4206

4207
getStreamInfo(): Promise<AudioStreamInfo\>
4208

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

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

4213 4214 4215 4216 4217
**Return value**

| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
4218 4219 4220 4221

**Example**

```js
4222 4223 4224 4225 4226 4227 4228 4229 4230
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}`);
});
4231
```
4232

4233
### getAudioStreamId<sup>9+</sup>
4234

4235
getAudioStreamId(callback: AsyncCallback<number\>): void
4236

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

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

4241 4242
**Parameters**

4243 4244 4245
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
4246

4247 4248
**Example**

G
Gloria 已提交
4249
```js
4250 4251
audioRenderer.getAudioStreamId((err, streamid) => {
  console.info(`Renderer GetStreamId: ${streamid}`);
4252
});
4253 4254
```

4255
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
4256

4257
getAudioStreamId(): Promise<number\>
W
wusongqing 已提交
4258

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

4261
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4262 4263

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

4265 4266 4267
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
4268

W
wusongqing 已提交
4269
**Example**
V
Vaidegi B 已提交
4270

G
Gloria 已提交
4271
```js
4272 4273
audioRenderer.getAudioStreamId().then((streamid) => {
  console.info(`Renderer getAudioStreamId: ${streamid}`);
4274
}).catch((err) => {
4275
  console.error(`ERROR: ${err}`);
4276 4277
});
```
V
Vaidegi B 已提交
4278

4279
### start<sup>8+</sup>
4280

4281
start(callback: AsyncCallback<void\>): void
4282

4283
Starts the renderer. This API uses an asynchronous callback to return the result.
4284

4285
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4286 4287 4288

**Parameters**

4289 4290 4291
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4292 4293 4294 4295

**Example**

```js
4296
audioRenderer.start((err) => {
4297
  if (err) {
4298
    console.error('Renderer start failed.');
4299
  } else {
4300
    console.info('Renderer start success.');
4301
  }
4302
});
V
Vaidegi B 已提交
4303 4304
```

4305
### start<sup>8+</sup>
G
Gloria 已提交
4306

4307
start(): Promise<void\>
G
Gloria 已提交
4308

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

4311
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4312 4313 4314

**Return value**

4315 4316 4317
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
G
Gloria 已提交
4318 4319 4320 4321

**Example**

```js
4322 4323
audioRenderer.start().then(() => {
  console.info('Renderer started');
4324
}).catch((err) => {
4325
  console.error(`ERROR: ${err}`);
4326 4327 4328
});
```

4329
### pause<sup>8+</sup>
4330

4331
pause(callback: AsyncCallback\<void>): void
4332

4333
Pauses rendering. This API uses an asynchronous callback to return the result.
4334

4335
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4336 4337 4338

**Parameters**

4339 4340 4341
| Name     | Type                 | Mandatory | Description                         |
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4342 4343 4344 4345

**Example**

```js
4346 4347 4348 4349 4350 4351
audioRenderer.pause((err) => {
  if (err) {
    console.error('Renderer pause failed');
  } else {
    console.info('Renderer paused.');
  }
4352 4353 4354
});
```

4355
### pause<sup>8+</sup>
4356

4357
pause(): Promise\<void>
4358

4359
Pauses rendering. This API uses a promise to return the result.
4360

4361
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4362 4363 4364

**Return value**

4365 4366 4367
| Type           | Description                        |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
4368 4369 4370 4371

**Example**

```js
4372 4373
audioRenderer.pause().then(() => {
  console.info('Renderer paused');
4374 4375 4376 4377 4378
}).catch((err) => {
  console.error(`ERROR: ${err}`);
});
```

4379
### drain<sup>8+</sup>
4380

4381
drain(callback: AsyncCallback\<void>): void
4382

4383
Drains the playback buffer. This API uses an asynchronous callback to return the result.
4384

4385
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4386 4387 4388 4389

**Parameters**

| Name     | Type                 | Mandatory | Description                         |
4390 4391
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
4392 4393 4394 4395

**Example**

```js
4396
audioRenderer.drain((err) => {
4397
  if (err) {
4398
    console.error('Renderer drain failed');
4399
  } else {
4400
    console.info('Renderer drained.');
4401 4402
  }
});
G
Gloria 已提交
4403 4404
```

4405
### drain<sup>8+</sup>
V
Vaidegi B 已提交
4406

4407
drain(): Promise\<void>
V
Vaidegi B 已提交
4408

4409
Drains the playback buffer. This API uses a promise to return the result.
4410

4411
**System capability**: SystemCapability.Multimedia.Audio.Renderer
4412 4413 4414 4415

**Return value**

| Type           | Description                        |
4416 4417
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4418

W
wusongqing 已提交
4419
**Example**
V
Vaidegi B 已提交
4420

G
Gloria 已提交
4421
```js
4422 4423
audioRenderer.drain().then(() => {
  console.info('Renderer drained successfully');
4424
}).catch((err) => {
4425
  console.error(`ERROR: ${err}`);
4426
});
V
Vaidegi B 已提交
4427 4428
```

4429
### stop<sup>8+</sup>
V
Vaidegi B 已提交
4430

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

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

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

W
wusongqing 已提交
4437
**Parameters**
V
Vaidegi B 已提交
4438

4439
| Name     | Type                 | Mandatory | Description                         |
4440 4441
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4442

W
wusongqing 已提交
4443
**Example**
V
Vaidegi B 已提交
4444

G
Gloria 已提交
4445
```js
4446
audioRenderer.stop((err) => {
4447
  if (err) {
4448
    console.error('Renderer stop failed');
4449
  } else {
4450
    console.info('Renderer stopped.');
4451
  }
4452
});
V
Vaidegi B 已提交
4453 4454
```

4455
### stop<sup>8+</sup>
4456

4457
stop(): Promise\<void>
V
Vaidegi B 已提交
4458

4459
Stops rendering. This API uses a promise to return the result.
4460

4461
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4462

W
wusongqing 已提交
4463
**Return value**
V
Vaidegi B 已提交
4464

4465
| Type           | Description                        |
4466 4467
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4468

W
wusongqing 已提交
4469
**Example**
V
Vaidegi B 已提交
4470

G
Gloria 已提交
4471
```js
4472 4473
audioRenderer.stop().then(() => {
  console.info('Renderer stopped successfully');
4474
}).catch((err) => {
4475
  console.error(`ERROR: ${err}`);
4476 4477
});
```
V
Vaidegi B 已提交
4478

4479
### release<sup>8+</sup>
V
Vaidegi B 已提交
4480

4481
release(callback: AsyncCallback\<void>): void
4482

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

4485
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4486

W
wusongqing 已提交
4487
**Parameters**
V
Vaidegi B 已提交
4488

4489
| Name     | Type                 | Mandatory | Description                         |
4490 4491
| -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4492

W
wusongqing 已提交
4493
**Example**
V
Vaidegi B 已提交
4494

G
Gloria 已提交
4495
```js
4496
audioRenderer.release((err) => {
4497
  if (err) {
4498
    console.error('Renderer release failed');
4499
  } else {
4500
    console.info('Renderer released.');
4501
  }
4502
});
V
Vaidegi B 已提交
4503 4504
```

4505
### release<sup>8+</sup>
V
Vaidegi B 已提交
4506

4507
release(): Promise\<void>
V
Vaidegi B 已提交
4508

4509
Releases the renderer. This API uses a promise to return the result.
4510

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

W
wusongqing 已提交
4513
**Return value**
V
Vaidegi B 已提交
4514

4515
| Type           | Description                        |
4516 4517
| -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result. |
V
Vaidegi B 已提交
4518

W
wusongqing 已提交
4519
**Example**
V
Vaidegi B 已提交
4520

G
Gloria 已提交
4521
```js
4522 4523
audioRenderer.release().then(() => {
  console.info('Renderer released successfully');
4524
}).catch((err) => {
4525
  console.error(`ERROR: ${err}`);
4526
});
V
Vaidegi B 已提交
4527 4528
```

4529
### write<sup>8+</sup>
V
Vaidegi B 已提交
4530

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

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

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

W
wusongqing 已提交
4537
**Parameters**
V
Vaidegi B 已提交
4538

4539 4540 4541 4542
| 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 已提交
4543

W
wusongqing 已提交
4544
**Example**
V
Vaidegi B 已提交
4545

G
Gloria 已提交
4546
```js
4547
let bufferSize;
4548 4549
audioRenderer.getBufferSize().then((data)=> {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4550 4551
  bufferSize = data;
  }).catch((err) => {
4552
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4553
  });
4554 4555 4556 4557 4558 4559 4560
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 已提交
4561 4562
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4563
let buf = new ArrayBuffer(bufferSize);
4564
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4565 4566
for (let i = 0;i < len; i++) {
    let options = {
4567 4568
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4569 4570 4571
    }
    let readsize = await fs.read(file.fd, buf, options)
    let writeSize = await new Promise((resolve,reject)=>{
4572
      audioRenderer.write(buf,(err,writeSize)=>{
G
Gloria 已提交
4573 4574 4575 4576 4577 4578 4579 4580
        if(err){
          reject(err)
        }else{
          resolve(writeSize)
        }
      })
    })	  
}
V
Vaidegi B 已提交
4581 4582
```

4583
### write<sup>8+</sup>
V
Vaidegi B 已提交
4584

4585
write(buffer: ArrayBuffer): Promise\<number>
4586

4587
Writes the buffer. This API uses a promise to return the result.
4588

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

W
wusongqing 已提交
4591
**Return value**
V
Vaidegi B 已提交
4592

4593 4594 4595
| 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 已提交
4596

W
wusongqing 已提交
4597
**Example**
V
Vaidegi B 已提交
4598

G
Gloria 已提交
4599
```js
4600
let bufferSize;
4601 4602
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4603 4604
  bufferSize = data;
  }).catch((err) => {
4605
  console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4606
  });
4607 4608 4609 4610 4611 4612 4613
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 已提交
4614 4615
let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY);
let stat = await fs.stat(path);
4616
let buf = new ArrayBuffer(bufferSize);
4617
let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1);
G
Gloria 已提交
4618 4619
for (let i = 0;i < len; i++) {
    let options = {
4620 4621
      offset: i * bufferSize,
      length: bufferSize
G
Gloria 已提交
4622 4623 4624
    }
    let readsize = await fs.read(file.fd, buf, options)
    try{
4625
       let writeSize = await audioRenderer.write(buf);
G
Gloria 已提交
4626 4627 4628 4629
    } catch(err) {
       console.error(`audioRenderer.write err: ${err}`);
    }   
}
V
Vaidegi B 已提交
4630 4631
```

4632
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4633

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

4636
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 已提交
4637

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

W
wusongqing 已提交
4640
**Parameters**
V
Vaidegi B 已提交
4641

4642 4643 4644
| Name     | Type                   | Mandatory | Description                            |
| -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the timestamp. |
V
Vaidegi B 已提交
4645

W
wusongqing 已提交
4646
**Example**
V
Vaidegi B 已提交
4647

G
Gloria 已提交
4648
```js
4649
audioRenderer.getAudioTime((err, timestamp) => {
4650
  console.info(`Current timestamp: ${timestamp}`);
4651
});
V
Vaidegi B 已提交
4652 4653
```

4654
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
4655

4656
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
4657

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

4660
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4661

W
wusongqing 已提交
4662
**Return value**
V
Vaidegi B 已提交
4663

4664
| Type             | Description                           |
4665 4666
| ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp. |
V
Vaidegi B 已提交
4667

W
wusongqing 已提交
4668
**Example**
V
Vaidegi B 已提交
4669

G
Gloria 已提交
4670
```js
4671 4672
audioRenderer.getAudioTime().then((timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
4673
}).catch((err) => {
4674
  console.error(`ERROR: ${err}`);
4675
});
V
Vaidegi B 已提交
4676 4677
```

4678
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4679

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

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

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

W
wusongqing 已提交
4686
**Parameters**
V
Vaidegi B 已提交
4687

4688
| Name     | Type                   | Mandatory | Description                              |
4689 4690
| -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes       | Callback used to return the buffer size. |
V
Vaidegi B 已提交
4691

W
wusongqing 已提交
4692
**Example**
V
Vaidegi B 已提交
4693

G
Gloria 已提交
4694
```js
4695 4696 4697
let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
  if (err) {
    console.error('getBufferSize error');
4698
  }
4699
});
V
Vaidegi B 已提交
4700 4701
```

4702
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
4703

4704
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
4705

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

4708
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4709

W
wusongqing 已提交
4710
**Return value**
V
Vaidegi B 已提交
4711

4712
| Type             | Description                             |
4713 4714
| ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size. |
V
Vaidegi B 已提交
4715

W
wusongqing 已提交
4716
**Example**
V
Vaidegi B 已提交
4717

G
Gloria 已提交
4718
```js
4719
let bufferSize;
4720 4721
audioRenderer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
4722
  bufferSize = data;
4723
}).catch((err) => {
4724
  console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
4725
});
V
Vaidegi B 已提交
4726 4727
```

4728
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4729

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

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

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

W
wusongqing 已提交
4736
**Parameters**
V
Vaidegi B 已提交
4737

4738 4739 4740 4741
| Name     | Type                                     | Mandatory | Description                         |
| -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes       | Audio render rate.                  |
| callback | AsyncCallback\<void>                     | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4742

W
wusongqing 已提交
4743
**Example**
V
Vaidegi B 已提交
4744

G
Gloria 已提交
4745
```js
4746 4747 4748 4749 4750
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.');
4751
  }
4752
});
V
Vaidegi B 已提交
4753 4754
```

4755
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4756

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

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

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

W
wusongqing 已提交
4763
**Parameters**
V
Vaidegi B 已提交
4764

4765 4766 4767 4768 4769 4770 4771 4772 4773
| 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 已提交
4774

W
wusongqing 已提交
4775
**Example**
V
Vaidegi B 已提交
4776

G
Gloria 已提交
4777
```js
4778 4779 4780 4781
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
  console.info('setRenderRate SUCCESS');
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4782
});
V
Vaidegi B 已提交
4783 4784
```

4785
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4786

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

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

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

4793
**Parameters**
V
Vaidegi B 已提交
4794

4795 4796 4797
| Name     | Type                                                    | Mandatory | Description                                    |
| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes       | Callback used to return the audio render rate. |
V
Vaidegi B 已提交
4798

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

G
Gloria 已提交
4801
```js
4802 4803 4804
audioRenderer.getRenderRate((err, renderrate) => {
  console.info(`getRenderRate: ${renderrate}`);
});
V
Vaidegi B 已提交
4805 4806
```

4807
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
4808

4809
getRenderRate(): Promise\<AudioRendererRate>
V
Vaidegi B 已提交
4810

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

4813
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
4814

4815
**Return value**
V
Vaidegi B 已提交
4816

4817 4818 4819
| Type                                              | Description                                   |
| ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
V
Vaidegi B 已提交
4820

W
wusongqing 已提交
4821
**Example**
V
Vaidegi B 已提交
4822

G
Gloria 已提交
4823
```js
4824 4825 4826 4827
audioRenderer.getRenderRate().then((renderRate) => {
  console.info(`getRenderRate: ${renderRate}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
4828
});
V
Vaidegi B 已提交
4829
```
4830
### setInterruptMode<sup>9+</sup>
V
Vaidegi B 已提交
4831

4832
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
4833

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

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

4838
**Parameters**
V
Vaidegi B 已提交
4839

4840 4841 4842
| Name | Type                             | Mandatory | Description              |
| ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode. |
V
Vaidegi B 已提交
4843

4844
**Return value**
4845

4846 4847 4848
| 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 已提交
4849

4850
**Example**
V
Vaidegi B 已提交
4851

4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866
```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 已提交
4867

W
wusongqing 已提交
4868
**Parameters**
V
Vaidegi B 已提交
4869

4870 4871 4872 4873
| Name     | Type                             | Mandatory | Description                         |
| -------- | -------------------------------- | --------- | ----------------------------------- |
| mode     | [InterruptMode](#interruptmode9) | Yes       | Audio interruption mode.            |
| callback | AsyncCallback\<void>             | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
4874

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

G
Gloria 已提交
4877
```js
4878 4879 4880 4881
let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{
  if(err){
    console.error(`setInterruptMode Fail: ${err}`);
4882
  }
4883
  console.info('setInterruptMode Success!');
4884
});
V
Vaidegi B 已提交
4885 4886
```

4887
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4888

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

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

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

**Parameters**

4897 4898 4899
| Name   | Type   | Mandatory | Description                                                  |
| ------ | ------ | --------- | ------------------------------------------------------------ |
| volume | number | Yes       | Volume to set, which can be within the range from 0.0 to 1.0. |
4900

W
wusongqing 已提交
4901
**Return value**
V
Vaidegi B 已提交
4902

4903 4904 4905
| 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 已提交
4906

W
wusongqing 已提交
4907
**Example**
V
Vaidegi B 已提交
4908

G
Gloria 已提交
4909
```js
4910 4911 4912 4913
audioRenderer.setVolume(0.5).then(data=>{
  console.info('setVolume Success!');
}).catch((err) => {
  console.error(`setVolume Fail: ${err}`);
4914
});
V
Vaidegi B 已提交
4915
```
4916
### setVolume<sup>9+</sup>
V
Vaidegi B 已提交
4917

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

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

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

W
wusongqing 已提交
4924
**Parameters**
V
Vaidegi B 已提交
4925

4926 4927 4928 4929
| 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 已提交
4930

W
wusongqing 已提交
4931
**Example**
V
Vaidegi B 已提交
4932

G
Gloria 已提交
4933
```js
4934 4935 4936
audioRenderer.setVolume(0.5, (err, data)=>{
  if(err){
    console.error(`setVolume Fail: ${err}`);
4937
  }
4938
  console.info('setVolume Success!');
4939
});
V
Vaidegi B 已提交
4940 4941
```

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

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

4946
Subscribes to audio interruption events. This API uses a callback to obtain interrupt events.
4947

4948
Same as [on('interrupt')](#oninterrupt), this API is used to listen for focus changes. The **AudioRenderer** instance proactively gains the focus when the **start** event occurs and releases the focus when the **pause** or **stop** event occurs. Therefore, you do not need to request to gain or release the focus.
V
Vaidegi B 已提交
4949

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

4952 4953
**Parameters**

4954 4955 4956 4957
| 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.        |
4958 4959 4960 4961 4962 4963 4964

**Error codes**

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

| ID      | Error Message                  |
| ------- | ------------------------------ |
4965
| 6800101 | if input parameter value error |
V
Vaidegi B 已提交
4966

W
wusongqing 已提交
4967
**Example**
V
Vaidegi B 已提交
4968

G
Gloria 已提交
4969
```js
4970 4971 4972 4973 4974 4975 4976 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
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 已提交
5019 5020
```

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

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

5025
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 已提交
5026

5027
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5028

W
wusongqing 已提交
5029
**Parameters**
5030

5031 5032 5033 5034 5035
| 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 已提交
5036

W
wusongqing 已提交
5037
**Example**
V
Vaidegi B 已提交
5038

G
Gloria 已提交
5039
```js
5040 5041 5042
audioRenderer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5043
  }
5044
});
V
Vaidegi B 已提交
5045 5046 5047
```


5048
### off('markReach') <sup>8+</sup>
5049

5050
off(type: 'markReach'): void
V
Vaidegi B 已提交
5051

5052
Unsubscribes from mark reached events.
V
Vaidegi B 已提交
5053

5054
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5055

5056 5057 5058 5059 5060
**Parameters**

| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
V
Vaidegi B 已提交
5061

W
wusongqing 已提交
5062
**Example**
V
Vaidegi B 已提交
5063

G
Gloria 已提交
5064
```js
5065
audioRenderer.off('markReach');
V
Vaidegi B 已提交
5066 5067
```

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

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

5072
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 已提交
5073

5074
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5075

W
wusongqing 已提交
5076
**Parameters**
5077

5078 5079 5080 5081 5082
| 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 已提交
5083

W
wusongqing 已提交
5084
**Example**
V
Vaidegi B 已提交
5085

G
Gloria 已提交
5086
```js
5087 5088 5089
audioRenderer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5090
  }
5091
});
V
Vaidegi B 已提交
5092 5093
```

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

5096
off(type: 'periodReach'): void
5097

5098
Unsubscribes from period reached events.
V
Vaidegi B 已提交
5099

5100
**System capability**: SystemCapability.Multimedia.Audio.Renderer
V
Vaidegi B 已提交
5101

5102
**Parameters**
V
Vaidegi B 已提交
5103

5104 5105 5106
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
V
Vaidegi B 已提交
5107

W
wusongqing 已提交
5108
**Example**
V
Vaidegi B 已提交
5109

G
Gloria 已提交
5110
```js
5111
audioRenderer.off('periodReach')
V
Vaidegi B 已提交
5112
```
5113

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

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

5118
Subscribes to state change events.
W
wusongqing 已提交
5119

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

5122
**Parameters**
W
wusongqing 已提交
5123

5124 5125 5126 5127
| 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 已提交
5128

5129
**Example**
W
wusongqing 已提交
5130

5131 5132 5133 5134 5135 5136 5137 5138 5139 5140
```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');
  }
});
```
5141

5142
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
5143

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

5146
### Attributes
5147

5148
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5149

5150 5151 5152
| Name               | Type                       | Readable | Writable | Description           |
| :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes      | No       | Audio capturer state. |
V
Vaidegi B 已提交
5153

5154
**Example**
V
Vaidegi B 已提交
5155

5156 5157 5158
```js
let state = audioCapturer.state;
```
V
Vaidegi B 已提交
5159

5160
### getCapturerInfo<sup>8+</sup>
5161

5162
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
5163

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

5166
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5167

W
wusongqing 已提交
5168
**Parameters**
5169

5170 5171 5172
| Name     | Type                              | Mandatory | Description                                       |
| :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes       | Callback used to return the capturer information. |
5173

W
wusongqing 已提交
5174
**Example**
5175

G
Gloria 已提交
5176
```js
5177
audioCapturer.getCapturerInfo((err, capturerInfo) => {
5178
  if (err) {
5179 5180 5181 5182 5183
    console.error('Failed to get capture info');
  } else {
    console.info('Capturer getCapturerInfo:');
    console.info(`Capturer source: ${capturerInfo.source}`);
    console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
5184
  }
5185 5186 5187
});
```

5188

5189
### getCapturerInfo<sup>8+</sup>
5190

5191
getCapturerInfo(): Promise<AudioCapturerInfo\>
5192

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

5195
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5196

5197
**Return value**
5198

5199 5200 5201
| Type                                              | Description                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
5202

W
wusongqing 已提交
5203
**Example**
5204

G
Gloria 已提交
5205
```js
5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216
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}`);
5217
});
5218 5219
```

5220
### getStreamInfo<sup>8+</sup>
5221

5222
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
5223

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

5226
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5227

W
wusongqing 已提交
5228
**Parameters**
5229

5230 5231 5232
| Name     | Type                                                 | Mandatory | Description                                     |
| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes       | Callback used to return the stream information. |
5233

W
wusongqing 已提交
5234
**Example**
5235

G
Gloria 已提交
5236
```js
5237
audioCapturer.getStreamInfo((err, streamInfo) => {
5238
  if (err) {
5239 5240 5241 5242 5243 5244 5245
    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}`);
5246
  }
5247 5248 5249
});
```

5250
### getStreamInfo<sup>8+</sup>
5251

5252
getStreamInfo(): Promise<AudioStreamInfo\>
5253

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

5256
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5257 5258 5259

**Return value**

5260 5261 5262
| Type                                           | Description                                    |
| :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
5263

W
wusongqing 已提交
5264
**Example**
5265

G
Gloria 已提交
5266
```js
5267 5268 5269 5270 5271 5272 5273 5274
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}`);
5275
});
5276
```
V
Vaidegi B 已提交
5277

5278
### getAudioStreamId<sup>9+</sup>
V
Vaidegi B 已提交
5279

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

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

5284
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5285

W
wusongqing 已提交
5286
**Parameters**
5287

5288 5289 5290
| Name     | Type                   | Mandatory | Description                            |
| :------- | :--------------------- | :-------- | :------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the stream ID. |
5291

W
wusongqing 已提交
5292
**Example**
5293

G
Gloria 已提交
5294
```js
5295 5296
audioCapturer.getAudioStreamId((err, streamid) => {
  console.info(`audioCapturer GetStreamId: ${streamid}`);
5297
});
5298
```
V
Vaidegi B 已提交
5299

5300
### getAudioStreamId<sup>9+</sup>
5301

5302 5303 5304
getAudioStreamId(): Promise<number\>

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

5306
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5307 5308 5309

**Return value**

5310 5311 5312
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the stream ID. |
V
Vaidegi B 已提交
5313

W
wusongqing 已提交
5314
**Example**
V
Vaidegi B 已提交
5315

G
Gloria 已提交
5316
```js
5317 5318 5319 5320
audioCapturer.getAudioStreamId().then((streamid) => {
  console.info(`audioCapturer getAudioStreamId: ${streamid}`);
}).catch((err) => {
  console.error(`ERROR: ${err}`);
5321
});
V
Vaidegi B 已提交
5322 5323
```

5324
### start<sup>8+</sup>
V
Vaidegi B 已提交
5325

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

5328
Starts capturing. This API uses an asynchronous callback to return the result.
5329

5330
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5331

W
wusongqing 已提交
5332
**Parameters**
V
Vaidegi B 已提交
5333

5334 5335 5336
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5337

W
wusongqing 已提交
5338
**Example**
V
Vaidegi B 已提交
5339

G
Gloria 已提交
5340
```js
5341
audioCapturer.start((err) => {
5342
  if (err) {
5343 5344 5345
    console.error('Capturer start failed.');
  } else {
    console.info('Capturer start success.');
5346
  }
5347
});
V
Vaidegi B 已提交
5348 5349 5350
```


5351
### start<sup>8+</sup>
V
Vaidegi B 已提交
5352

5353
start(): Promise<void\>
5354

5355
Starts capturing. This API uses a promise to return the result.
5356

5357
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5358

W
wusongqing 已提交
5359
**Return value**
V
Vaidegi B 已提交
5360

5361 5362 5363
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5364

W
wusongqing 已提交
5365
**Example**
V
Vaidegi B 已提交
5366

G
Gloria 已提交
5367
```js
5368 5369 5370 5371 5372 5373 5374 5375 5376 5377
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}`);
5378
});
5379
```
V
Vaidegi B 已提交
5380

5381
### stop<sup>8+</sup>
5382

5383
stop(callback: AsyncCallback<void\>): void
5384

5385
Stops capturing. This API uses an asynchronous callback to return the result.
5386

5387
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5388

W
wusongqing 已提交
5389
**Parameters**
V
Vaidegi B 已提交
5390

5391 5392 5393
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
V
Vaidegi B 已提交
5394

W
wusongqing 已提交
5395
**Example**
V
Vaidegi B 已提交
5396

G
Gloria 已提交
5397
```js
5398
audioCapturer.stop((err) => {
5399
  if (err) {
5400 5401 5402
    console.error('Capturer stop failed');
  } else {
    console.info('Capturer stopped.');
5403
  }
5404
});
V
Vaidegi B 已提交
5405 5406
```

5407

5408
### stop<sup>8+</sup>
5409

5410
stop(): Promise<void\>
5411

5412
Stops capturing. This API uses a promise to return the result.
5413

5414
**System capability**: SystemCapability.Multimedia.Audio.Capturer
V
Vaidegi B 已提交
5415

W
wusongqing 已提交
5416
**Return value**
V
Vaidegi B 已提交
5417

5418 5419 5420
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
V
Vaidegi B 已提交
5421

W
wusongqing 已提交
5422
**Example**
V
Vaidegi B 已提交
5423

G
Gloria 已提交
5424
```js
5425 5426 5427 5428 5429 5430 5431 5432
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}`);
5433
});
V
Vaidegi B 已提交
5434 5435
```

5436
### release<sup>8+</sup>
V
Vaidegi B 已提交
5437

5438
release(callback: AsyncCallback<void\>): void
5439

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

5442
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5443

W
wusongqing 已提交
5444
**Parameters**
5445

5446 5447 5448
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5449

W
wusongqing 已提交
5450
**Example**
5451

G
Gloria 已提交
5452
```js
5453
audioCapturer.release((err) => {
5454
  if (err) {
5455 5456 5457
    console.error('capturer release failed');
  } else {
    console.info('capturer released.');
5458
  }
5459
});
5460 5461 5462
```


5463
### release<sup>8+</sup>
5464

5465
release(): Promise<void\>
5466

5467
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
5468

5469
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5470

W
wusongqing 已提交
5471
**Return value**
5472

5473 5474 5475
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5476

W
wusongqing 已提交
5477
**Example**
5478

G
Gloria 已提交
5479
```js
5480 5481 5482 5483 5484 5485 5486 5487
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}`);
5488 5489 5490
});
```

5491
### read<sup>8+</sup>
5492

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

5495
Reads the buffer. This API uses an asynchronous callback to return the result.
5496

5497
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5498

W
wusongqing 已提交
5499
**Parameters**
5500

5501 5502 5503 5504 5505
| 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.  |
5506

W
wusongqing 已提交
5507
**Example**
5508

G
Gloria 已提交
5509
```js
5510 5511 5512 5513 5514 5515 5516 5517 5518 5519
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');
5520
  }
5521
});
5522 5523
```

5524
### read<sup>8+</sup>
5525

5526
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
5527

5528
Reads the buffer. This API uses a promise to return the result.
5529

5530
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5531 5532 5533

**Parameters**

5534 5535 5536 5537
| Name           | Type    | Mandatory | Description                          |
| :------------- | :------ | :-------- | :----------------------------------- |
| size           | number  | Yes       | Number of bytes to read.             |
| isBlockingRead | boolean | Yes       | Whether to block the read operation. |
5538

W
wusongqing 已提交
5539
**Return value**
5540

5541 5542 5543
| 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. |
5544

W
wusongqing 已提交
5545
**Example**
5546

G
Gloria 已提交
5547
```js
5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559
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}`);
5560
});
5561
```
5562

5563
### getAudioTime<sup>8+</sup>
5564

5565
getAudioTime(callback: AsyncCallback<number\>): void
5566

5567 5568 5569
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
5570

W
wusongqing 已提交
5571
**Parameters**
5572

5573 5574 5575
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the result. |
5576

W
wusongqing 已提交
5577
**Example**
5578

G
Gloria 已提交
5579
```js
5580 5581
audioCapturer.getAudioTime((err, timestamp) => {
  console.info(`Current timestamp: ${timestamp}`);
5582
});
5583 5584
```

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

5587
getAudioTime(): Promise<number\>
5588

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

5591
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5592

W
wusongqing 已提交
5593
**Return value**
5594

5595 5596 5597
| Type             | Description                           |
| :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the timestamp. |
5598

W
wusongqing 已提交
5599
**Example**
5600

G
Gloria 已提交
5601
```js
5602 5603 5604 5605
audioCapturer.getAudioTime().then((audioTime) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
5606 5607 5608
});
```

5609
### getBufferSize<sup>8+</sup>
5610

5611
getBufferSize(callback: AsyncCallback<number\>): void
5612

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

5615
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5616

W
wusongqing 已提交
5617
**Parameters**
5618

5619 5620 5621
| Name     | Type                   | Mandatory | Description                              |
| :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes       | Callback used to return the buffer size. |
5622

W
wusongqing 已提交
5623
**Example**
5624

G
Gloria 已提交
5625
```js
5626 5627 5628 5629 5630 5631 5632 5633
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}`);
    });
5634
  }
J
jiao_yanlin 已提交
5635
});
5636 5637
```

5638
### getBufferSize<sup>8+</sup>
5639

5640
getBufferSize(): Promise<number\>
5641

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

5644
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5645

W
wusongqing 已提交
5646
**Return value**
5647

5648 5649 5650
| Type             | Description                             |
| :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size. |
5651

W
wusongqing 已提交
5652
**Example**
5653

G
Gloria 已提交
5654
```js
5655 5656 5657 5658 5659 5660
let bufferSize;
audioCapturer.getBufferSize().then((data) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
  bufferSize = data;
}).catch((err) => {
  console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
5661 5662 5663
});
```

5664
### on('markReach')<sup>8+</sup>
5665

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

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

5670
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5671

W
wusongqing 已提交
5672
**Parameters**
5673

5674 5675 5676 5677 5678
| 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.                |
5679

W
wusongqing 已提交
5680
**Example**
5681

G
Gloria 已提交
5682
```js
5683 5684 5685
audioCapturer.on('markReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5686
  }
5687
});
5688 5689
```

5690
### off('markReach')<sup>8+</sup>
5691

5692
off(type: 'markReach'): void
5693

5694
Unsubscribes from mark reached events.
5695

5696
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5697 5698 5699

**Parameters**

5700 5701 5702
| Name | Type   | Mandatory | Description                                        |
| :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'markReach'**. |
5703

W
wusongqing 已提交
5704
**Example**
5705

G
Gloria 已提交
5706
```js
5707
audioCapturer.off('markReach');
5708 5709
```

5710
### on('periodReach')<sup>8+</sup>
5711

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

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

5716
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5717

W
wusongqing 已提交
5718
**Parameters**
5719

5720 5721 5722 5723 5724
| 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.                |
5725

W
wusongqing 已提交
5726
**Example**
5727

G
Gloria 已提交
5728
```js
5729 5730 5731
audioCapturer.on('periodReach', 1000, (position) => {
  if (position == 1000) {
    console.info('ON Triggered successfully');
5732
  }
5733 5734 5735
});
```

5736
### off('periodReach')<sup>8+</sup>
5737

5738
off(type: 'periodReach'): void
5739

5740
Unsubscribes from period reached events.
5741

5742
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5743 5744 5745

**Parameters**

5746 5747 5748
| Name | Type   | Mandatory | Description                                          |
| :--- | :----- | :-------- | :--------------------------------------------------- |
| type | string | Yes       | Event type. The value is fixed at **'periodReach'**. |
5749

W
wusongqing 已提交
5750
**Example**
5751

G
Gloria 已提交
5752
```js
5753
audioCapturer.off('periodReach')
5754 5755
```

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

5758
on(type: 'stateChange', callback: Callback<AudioState\>): void
5759

5760
Subscribes to state change events.
5761

5762
**System capability**: SystemCapability.Multimedia.Audio.Capturer
5763

W
wusongqing 已提交
5764
**Parameters**
5765

5766 5767 5768 5769
| 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.                    |
5770

W
wusongqing 已提交
5771
**Example**
5772

G
Gloria 已提交
5773
```js
5774 5775 5776 5777 5778 5779
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');
5780
  }
5781 5782 5783
});
```

5784
## ToneType<sup>9+</sup>
5785

5786
Enumerates the tone types of the player.
5787

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

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

5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820
| 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.          |
5821

5822
## TonePlayer<sup>9+</sup>
5823

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

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

5828
### load<sup>9+</sup>
5829

5830
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
5831

5832
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
5833

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

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

W
wusongqing 已提交
5838
**Parameters**
5839

5840 5841 5842 5843
| Name     | Type                   | Mandatory | Description                         |
| :------- | :--------------------- | :-------- | :---------------------------------- |
| type     | [ToneType](#tonetype9) | Yes       | Tone type.                          |
| callback | AsyncCallback<void\>   | Yes       | Callback used to return the result. |
5844

W
wusongqing 已提交
5845
**Example**
5846

G
Gloria 已提交
5847
```js
5848
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
5849
  if (err) {
5850
    console.error(`callback call load failed error: ${err.message}`);
5851
    return;
5852 5853
  } else {
    console.info('callback call load success');
5854 5855
  }
});
5856 5857
```

5858
### load<sup>9+</sup>
5859

5860
load(type: ToneType): Promise&lt;void&gt;
5861

5862
Loads the DTMF tone configuration. This API uses a promise to return the result.
5863

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

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

W
wusongqing 已提交
5868
**Parameters**
5869

5870 5871 5872
| Name | Type                   | Mandatory | Description |
| :--- | :--------------------- | :-------- | ----------- |
| type | [ToneType](#tonetype9) | Yes       | Tone type.  |
5873 5874 5875

**Return value**

5876 5877 5878
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5879

W
wusongqing 已提交
5880
**Example**
5881

G
Gloria 已提交
5882
```js
5883 5884 5885 5886
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
  console.info('promise call load ');
}).catch(() => {
  console.error('promise call load fail');
5887
});
5888
```
5889

5890
### start<sup>9+</sup>
5891

5892
start(callback: AsyncCallback&lt;void&gt;): void
5893

5894
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
5895

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

5898
**System capability**: SystemCapability.Multimedia.Audio.Tone
5899 5900 5901

**Parameters**

5902 5903 5904
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5905 5906 5907 5908

**Example**

```js
5909
tonePlayer.start((err) => {
5910
  if (err) {
5911
    console.error(`callback call start failed error: ${err.message}`);
5912
    return;
5913 5914
  } else {
    console.info('callback call start success');
5915 5916 5917 5918
  }
});
```

5919
### start<sup>9+</sup>
5920

5921
start(): Promise&lt;void&gt;
5922

5923
Starts DTMF tone playing. This API uses a promise to return the result.
5924

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

5927
**System capability**: SystemCapability.Multimedia.Audio.Tone
5928 5929 5930

**Return value**

5931 5932 5933
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5934 5935 5936 5937

**Example**

```js
5938 5939 5940 5941
tonePlayer.start().then(() => {
  console.info('promise call start');
}).catch(() => {
  console.error('promise call start fail');
5942 5943 5944
});
```

5945
### stop<sup>9+</sup>
5946

5947
stop(callback: AsyncCallback&lt;void&gt;): void
5948

5949
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
5950 5951 5952

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

5953
**System capability**: SystemCapability.Multimedia.Audio.Tone
5954 5955 5956

**Parameters**

5957 5958 5959
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
5960 5961 5962 5963

**Example**

```js
5964 5965 5966 5967 5968 5969 5970
tonePlayer.stop((err) => {
  if (err) {
    console.error(`callback call stop error: ${err.message}`);
    return;
  } else {
    console.error('callback call stop success ');
  }
5971 5972 5973
});
```

5974
### stop<sup>9+</sup>
5975

5976
stop(): Promise&lt;void&gt;
5977

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

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

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

5984
**Return value**
5985

5986 5987 5988
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
5989 5990 5991 5992

**Example**

```js
5993 5994 5995 5996
tonePlayer.stop().then(() => {
  console.info('promise call stop finish');
}).catch(() => {
  console.error('promise call stop fail');
5997 5998 5999
});
```

6000
### release<sup>9+</sup>
6001

6002
release(callback: AsyncCallback&lt;void&gt;): void
6003

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

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

6008
**System capability**: SystemCapability.Multimedia.Audio.Tone
6009 6010 6011

**Parameters**

6012 6013 6014
| Name     | Type                 | Mandatory | Description                         |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes       | Callback used to return the result. |
6015 6016 6017 6018

**Example**

```js
6019 6020 6021 6022 6023 6024 6025
tonePlayer.release((err) => {
  if (err) {
    console.error(`callback call release failed error: ${err.message}`);
    return;
  } else {
    console.info('callback call release success ');
  }
6026 6027 6028
});
```

6029
### release<sup>9+</sup>
6030

6031
release(): Promise&lt;void&gt;
6032

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

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

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

6039
**Return value**
6040

6041 6042 6043
| Type           | Description                        |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
6044 6045 6046 6047

**Example**

```js
6048 6049 6050 6051
tonePlayer.release().then(() => {
  console.info('promise call release');
}).catch(() => {
  console.error('promise call release fail');
6052 6053 6054
});
```

6055
## ActiveDeviceType<sup>(deprecated)</sup>
6056

6057
Enumerates the active device types.
6058

6059 6060 6061
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead.
6062

6063 6064 6065 6066 6067 6068 6069 6070 6071 6072
**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.
6073 6074 6075 6076 6077 6078

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

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

6080 6081 6082 6083
| Name           | Value | Description               |
| -------------- | ----- | ------------------------- |
| TYPE_ACTIVATED | 0     | Focus gain event.         |
| TYPE_INTERRUPT | 1     | Audio interruption event. |
6084

6085
## AudioInterrupt<sup>(deprecated)</sup>
6086

6087
Describes input parameters of audio interruption events.
6088

6089 6090 6091
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
6092

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

6095 6096 6097 6098 6099
| 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. |
6100

6101
## InterruptAction<sup>(deprecated)</sup>
6102

6103
Describes the callback invoked for audio interruption or focus gain events.
6104

6105 6106
> **NOTE**
>
6107
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [InterruptEvent](#interruptevent9).
6108

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

6111 6112 6113 6114 6115 6116
| 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. |