js-apis-audio.md 114.9 KB
Newer Older
1
# Audio Management
V
Vaidegi B 已提交
2

W
wusongqing 已提交
3 4
>  **NOTE**<br/>
>  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.
V
Vaidegi B 已提交
5

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

W
wusongqing 已提交
8 9 10
- [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.
11 12

## Modules to Import
W
wusongqing 已提交
13 14 15 16 17

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

W
wusongqing 已提交
18

19
## audio.getAudioManager
V
Vaidegi B 已提交
20

21
getAudioManager(): AudioManager
22

23
Obtains an **AudioManager** instance.
W
wusongqing 已提交
24

W
wusongqing 已提交
25
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
26

W
wusongqing 已提交
27 28 29 30
**Return value**
| Type                         | Description        |
| ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | **AudioManager** instance.|
W
wusongqing 已提交
31

W
wusongqing 已提交
32
**Example**
W
wusongqing 已提交
33 34 35 36
```
var audioManager = audio.getAudioManager();
```

37
## audio.createAudioRenderer<sup>8+</sup>
38

39
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
40

W
wusongqing 已提交
41 42 43
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
45
**Parameters**
46

W
wusongqing 已提交
47 48 49 50
| Name  | Type                                           | Mandatory| Description            |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options  | [AudioRendererOptions](#audiorendereroptions8)  | Yes  | Renderer configurations.    |
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes  | Callback used to return the **AudioRenderer** instance.|
51

W
wusongqing 已提交
52
**Example**
53 54

```
55
import audio from '@ohos.multimedia.audio';
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

audio.createAudioRenderer(audioRendererOptions,(err, data) => {
    if (err) {
76
        console.error(`AudioRenderer Created : Error: ${err.message}`);
77 78
    }
    else {
79 80
        console.info('AudioRenderer Created : Success : SUCCESS');
        let audioRenderer = data;
81 82 83
    }
});
```
W
wusongqing 已提交
84

85
## audio.createAudioRenderer<sup>8+</sup>
86

W
wusongqing 已提交
87 88 89
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>

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

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

W
wusongqing 已提交
93
**Parameters**
94

W
wusongqing 已提交
95 96 97
| Name | Type                                          | Mandatory| Description        |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes  | Renderer configurations.|
V
Vaidegi B 已提交
98

W
wusongqing 已提交
99
**Return value**
V
Vaidegi B 已提交
100

W
wusongqing 已提交
101 102 103
| Type                                     | Description            |
| ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
V
Vaidegi B 已提交
104

W
wusongqing 已提交
105
**Example**
V
Vaidegi B 已提交
106 107

```
108 109
import audio from '@ohos.multimedia.audio';

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_1,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioRendererInfo = {
    content: audio.ContentType.CONTENT_TYPE_SPEECH,
    usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
    rendererFlags: 1
}

var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}

128 129 130 131 132 133 134
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created : ERROR : '+err.message);
});
V
Vaidegi B 已提交
135 136
```

137
## audio.createAudioCapturer<sup>8+</sup>
138

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

W
wusongqing 已提交
141
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
142

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

W
wusongqing 已提交
145
**Parameters**
V
Vaidegi B 已提交
146

W
wusongqing 已提交
147 148 149 150 151 152
| Name  | Type                                           | Mandatory| Description            |
| :------- | :---------------------------------------------- | :--- | :--------------- |
| options  | [AudioCapturerOptions](#audiocaptureroptions8)  | Yes  | Capturer configurations.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes  | Callback used to return the **AudioCapturer** instance.|

**Example**
153 154

```
155
import audio from '@ohos.multimedia.audio';
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
}

audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
    if (err) {
        console.error(`AudioCapturer Created : Error: ${err.message}`);
    }
    else {
        console.info('AudioCapturer Created : Success : SUCCESS');
179
        let audioCapturer = data;
180 181 182 183
    }
});
```

184
## audio.createAudioCapturer<sup>8+</sup>
185

186
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
187

W
wusongqing 已提交
188 189 190
Obtains an **AudioCapturer** instance. This API uses a promise to return the result.

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

W
wusongqing 已提交
192
**Parameters**
193

W
wusongqing 已提交
194 195 196
| Name | Type                                          | Mandatory| Description            |
| :------ | :--------------------------------------------- | :--- | :--------------- |
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes  | Capturer configurations.|
197

W
wusongqing 已提交
198
**Return value**
V
Vaidegi B 已提交
199

W
wusongqing 已提交
200 201 202
| Type                                     | Description          |
| ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
V
Vaidegi B 已提交
203

W
wusongqing 已提交
204
**Example**
V
Vaidegi B 已提交
205 206

```
207 208
import audio from '@ohos.multimedia.audio';

209 210 211 212 213 214 215 216 217 218 219 220 221
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
    encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}

var audioCapturerInfo = {
    source: audio.SourceType.SOURCE_TYPE_MIC,
    capturerFlags: 1
}

var audioCapturerOptions = {
222 223
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
224
}
V
Vaidegi B 已提交
225

226
var audioCapturer;
W
wusongqing 已提交
227
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
228 229 230 231 232
    audioCapturer = data;
    console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => {
    console.info('AudioCapturer Created : ERROR : '+err.message);
});
233
```
V
Vaidegi B 已提交
234

235
## AudioVolumeType
W
wusongqing 已提交
236

W
wusongqing 已提交
237
Enumerates the audio stream types.
W
wusongqing 已提交
238

W
wusongqing 已提交
239 240 241 242 243 244 245 246
**System capability**: SystemCapability.Multimedia.Audio.Volume

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| 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.|
Z
zengyawen 已提交
247

V
Vaidegi B 已提交
248

W
wusongqing 已提交
249 250 251 252 253 254 255 256 257 258 259
## InterruptMode<sup>9+</sup>

Enumerates the audio interruption modes.

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

| Name                        | Default Value| Description      |
| ---------------------------- | ------ | ---------- |
| SHARE_MODE      | 0      | Share mode.|
| INDEPENDENT_MODE| 1      | Independent mode.    |

260
## DeviceFlag
W
wusongqing 已提交
261

W
wusongqing 已提交
262
Enumerates the audio device flags.
W
wusongqing 已提交
263

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

W
wusongqing 已提交
266 267 268 269 270
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1      | Output device.|
| INPUT_DEVICES_FLAG  | 2      | Input device.|
| ALL_DEVICES_FLAG    | 3      | All devices.|
V
Vaidegi B 已提交
271

272 273

## DeviceRole
W
wusongqing 已提交
274

W
wusongqing 已提交
275 276 277
Enumerates the audio device roles.

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

W
wusongqing 已提交
279 280 281 282
| Name         | Default Value| Description          |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
283

V
Vaidegi B 已提交
284

285
## DeviceType
W
wusongqing 已提交
286

W
wusongqing 已提交
287
Enumerates the audio device types.
W
wusongqing 已提交
288

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

W
wusongqing 已提交
291 292 293 294 295 296 297 298 299 300 301
| Name            | Default Value| Description                                                     |
| ---------------- | ------ | --------------------------------------------------------- |
| 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.                                      |
Z
zengyawen 已提交
302

W
wusongqing 已提交
303
## ActiveDeviceType
V
Vaidegi B 已提交
304

W
wusongqing 已提交
305 306
Enumerates the active device types.

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

W
wusongqing 已提交
309 310 311 312
| Name         | Default Value| Description                                                |
| ------------- | ------ | ---------------------------------------------------- |
| SPEAKER       | 2      | Speaker.                                            |
| BLUETOOTH_SCO | 7      | Bluetooth device using the SCO links.|
W
wusongqing 已提交
313 314

## AudioRingMode
W
wusongqing 已提交
315

W
wusongqing 已提交
316
Enumerates the ringer modes.
W
wusongqing 已提交
317

W
wusongqing 已提交
318
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
319

W
wusongqing 已提交
320 321 322 323 324
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | Silent mode.|
| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
| RINGER_MODE_NORMAL  | 2      | Normal mode.|
325 326

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

W
wusongqing 已提交
328
Enumerate the audio sample formats.
V
Vaidegi B 已提交
329

W
wusongqing 已提交
330
**System capability**: SystemCapability.Multimedia.Audio.Core
331

W
wusongqing 已提交
332 333 334 335 336 337 338
| Name                 | Default Value| Description                      |
| --------------------- | ------ | -------------------------- |
| 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.|
| SAMPLE_FORMAT_S32LE   | 3      | Signed 32-bit integer, little endian.|
339 340

## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
341 342 343

Enumerates the audio channels.

W
wusongqing 已提交
344
**System capability**: SystemCapability.Multimedia.Audio.Core
345

W
wusongqing 已提交
346 347 348 349
| Name     | Default Value  | Description    |
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
350 351

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
352 353 354

Enumerates the audio sampling rates.

W
wusongqing 已提交
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
**System capability**: SystemCapability.Multimedia.Audio.Core

| Name             | Default Value| Description           |
| ----------------- | ------ | --------------- |
| 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.|
370 371 372

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

V
Vaidegi B 已提交
373 374
Enumerates the audio encoding types.

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

W
wusongqing 已提交
377 378 379 380
| Name                 | Default Value| Description     |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
381

382 383
## ContentType

W
wusongqing 已提交
384
Enumerates the audio content types.
385

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

W
wusongqing 已提交
388 389 390 391 392 393 394 395
| Name                              | Default Value| Description      |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN               | 0      | Unknown content.|
| CONTENT_TYPE_SPEECH                | 1      | Speech.    |
| CONTENT_TYPE_MUSIC                 | 2      | Music.    |
| CONTENT_TYPE_MOVIE                 | 3      | Movie.    |
| CONTENT_TYPE_SONIFICATION          | 4      | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5      | Ringtone.    |
V
Vaidegi B 已提交
396

397 398
## StreamUsage

W
wusongqing 已提交
399
Enumerates the audio stream usage.
V
Vaidegi B 已提交
400

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

W
wusongqing 已提交
403 404 405 406 407 408
| Name                              | Default Value| Description      |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN               | 0      | Unknown usage.|
| STREAM_USAGE_MEDIA                 | 1      | Used for media.    |
| STREAM_USAGE_VOICE_COMMUNICATION   | 2      | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6      | Used for notification.|
V
Vaidegi B 已提交
409

410 411
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
412 413
Enumerates the audio states.

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

W
wusongqing 已提交
416 417 418 419 420 421 422 423 424
| Name          | Default Value| Description            |
| -------------- | ------ | ---------------- |
| 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 已提交
425

426 427
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
428 429
Enumerates the audio renderer rates.

W
wusongqing 已提交
430
**System capability**: SystemCapability.Multimedia.Audio.Renderer
431

W
wusongqing 已提交
432 433 434 435 436
| Name              | Default Value| Description      |
| ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0      | Normal rate.|
| RENDER_RATE_DOUBLE | 1      | Double rate.   |
| RENDER_RATE_HALF   | 2      | Half rate. |
V
Vaidegi B 已提交
437

438
## InterruptType
V
Vaidegi B 已提交
439

W
wusongqing 已提交
440
Enumerates the audio interruption types.
V
Vaidegi B 已提交
441

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

W
wusongqing 已提交
444 445 446 447
| Name                | Default Value| Description                  |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
448 449

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

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

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

W
wusongqing 已提交
455 456 457 458
| Name           | Default Value| Description                                |
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0      | Forced action taken by the system.  |
| INTERRUPT_SHARE | 1      | The application can choose to take action or ignore.|
459 460

## InterruptHint
V
Vaidegi B 已提交
461

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

W
wusongqing 已提交
464
**System capability**: SystemCapability.Multimedia.Audio.Renderer
465

W
wusongqing 已提交
466 467 468 469 470 471 472 473
| Name                              | Default Value| Description                                        |
| ---------------------------------- | ------ | -------------------------------------------- |
| 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.                              |
474 475 476

## InterruptActionType

W
wusongqing 已提交
477
Enumerates the returned event types for audio interruption events.
478

W
wusongqing 已提交
479
**System capability**: SystemCapability.Multimedia.Audio.Renderer
480

W
wusongqing 已提交
481 482 483 484
| Name          | Default Value| Description              |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | Focus gain event.|
| TYPE_INTERRUPT | 1      | Audio interruption event.|
485 486

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

488
Describes audio stream information.
V
Vaidegi B 已提交
489

W
wusongqing 已提交
490
**System capability**: SystemCapability.Multimedia.Audio.Core
491

W
wusongqing 已提交
492 493 494 495 496 497
| 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.    |
498 499

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
500 501 502

Describes audio renderer information.

W
wusongqing 已提交
503
**System capability**: SystemCapability.Multimedia.Audio.Core
504

W
wusongqing 已提交
505 506 507 508 509
| Name         | Type                       | Mandatory| Description            |
| ------------- | --------------------------- | ---- | ---------------- |
| content       | [ContentType](#contenttype) | Yes  | Audio content type.      |
| usage         | [StreamUsage](#streamusage) | Yes  | Audio stream usage.|
| rendererFlags | number                      | Yes  | Audio renderer flags.|
V
Vaidegi B 已提交
510

511
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
512

W
wusongqing 已提交
513
Describes audio renderer configurations.
514

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

W
wusongqing 已提交
517 518 519 520
| Name        | Type                                    | Mandatory| Description            |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
521

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

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

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

W
wusongqing 已提交
528 529 530 531 532
| Name     | Type                                      | Mandatory| Description                                |
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
| 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 已提交
533

W
wusongqing 已提交
534
## AudioInterrupt
G
Geevarghese V K 已提交
535

W
wusongqing 已提交
536
Describes input parameters of audio interruption events.
G
Geevarghese V K 已提交
537

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

W
wusongqing 已提交
540 541 542 543 544
| 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.|
V
Vaidegi B 已提交
545

W
wusongqing 已提交
546
## InterruptAction
547

W
wusongqing 已提交
548
Describes the callback invoked for audio interruption or focus gain events.
549

W
wusongqing 已提交
550
**System capability**: SystemCapability.Multimedia.Audio.Renderer
551

W
wusongqing 已提交
552 553 554 555
| Name      | Type                                       | Mandatory| Description                                                        |
| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | 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.                                              |
W
wusongqing 已提交
556
| hint       | [InterruptHint](#interrupthint)              | No  | Hint provided along with the audio interruption event.                                              |
W
wusongqing 已提交
557
| 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.|
V
Vaidegi B 已提交
558

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

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

W
wusongqing 已提交
563
This is a system API and cannot be called by third-party applications.
564

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

W
wusongqing 已提交
567 568 569 570 571
| Name      | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume level. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| updateUi   | boolean                             | Yes  | Whether to show the volume change in UI.                                    |
572

W
wusongqing 已提交
573
## DeviceChangeAction
574

W
wusongqing 已提交
575
Describes the device connection status and device information.
576

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

W
wusongqing 已提交
579 580
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
W
wusongqing 已提交
581 582
| type              | [DeviceChangeType](#devicechangetype)          | Yes  | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
V
Vaidegi B 已提交
583

W
wusongqing 已提交
584
## DeviceChangeType
585

W
wusongqing 已提交
586
Enumerates the device connection statuses.
V
Vaidegi B 已提交
587

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

W
wusongqing 已提交
590 591 592 593
| Name      | Default Value| Description          |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
594

W
wusongqing 已提交
595
## AudioCapturerOptions<sup>8+</sup>
596

W
wusongqing 已提交
597
Describes audio capturer configurations.
598

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

W
wusongqing 已提交
601 602 603 604
| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|
605

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

W
wusongqing 已提交
608
Describes audio capturer information.
609

W
wusongqing 已提交
610
**System capability**: SystemCapability.Multimedia.Audio.Core
611

W
wusongqing 已提交
612 613 614 615
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
616 617

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

W
wusongqing 已提交
619
Enumerates the audio source types.
620

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

W
wusongqing 已提交
623 624 625 626 627
| Name                           | Default Value| Description                  |
| :------------------------------ | :----- | :--------------------- |
| SOURCE_TYPE_INVALID             | -1     | Invalid audio source.        |
| SOURCE_TYPE_MIC                 | 0      | Mic source.           |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7      | Voice communication source.|
628 629

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

W
wusongqing 已提交
631
Enumerates the audio scenes.
632

W
wusongqing 已提交
633
**System capability**: SystemCapability.Multimedia.Audio.Communication
634

W
wusongqing 已提交
635 636 637 638 639 640
| Name                  | Default Value| Description                                         |
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT    | 0      | Default audio scene.                               |
| AUDIO_SCENE_RINGING    | 1      | Ringing audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_PHONE_CALL | 2      | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3      | Voice chat audio scene.                               |
W
wusongqing 已提交
641

642
## AudioManager
W
wusongqing 已提交
643

W
wusongqing 已提交
644
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 已提交
645

646 647
### setVolume

W
wusongqing 已提交
648
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
649 650 651

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

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

W
wusongqing 已提交
654
**Parameters**
655

W
wusongqing 已提交
656 657 658 659
| 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**.|
W
wusongqing 已提交
660
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
661

W
wusongqing 已提交
662
**Example**
W
wusongqing 已提交
663 664

```
665 666 667 668 669 670
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
    if (err) {
        console.error('Failed to set the volume. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate a successful volume setting.');
671
});
W
wusongqing 已提交
672
```
W
wusongqing 已提交
673

674
### setVolume
W
wusongqing 已提交
675

W
wusongqing 已提交
676
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
677 678 679

Sets the volume for a stream. This API uses a promise to return the result.

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

W
wusongqing 已提交
682
**Parameters**
683

W
wusongqing 已提交
684 685 686 687
| 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**.|
688

W
wusongqing 已提交
689
**Return value**
690

W
wusongqing 已提交
691 692 693
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
694

W
wusongqing 已提交
695
**Example**
W
wusongqing 已提交
696 697

```
698
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
W
wusongqing 已提交
699
    console.log('Promise returned to indicate a successful volume setting.');
700 701 702 703
});
```

### getVolume
W
wusongqing 已提交
704

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

W
wusongqing 已提交
707
Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
708

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

W
wusongqing 已提交
711
**Parameters**
712

W
wusongqing 已提交
713 714 715 716
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
717

W
wusongqing 已提交
718
**Example**
W
wusongqing 已提交
719 720 721 722

```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
723 724
       console.error('Failed to obtain the volume. ${err.message}');
       return;
W
wusongqing 已提交
725 726
   }
   console.log('Callback invoked to indicate that the volume is obtained.');
727
});
W
wusongqing 已提交
728 729
```

730
### getVolume
V
Vaidegi B 已提交
731

W
wusongqing 已提交
732
getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
W
wusongqing 已提交
733

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

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

W
wusongqing 已提交
738
**Parameters**
W
wusongqing 已提交
739

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

W
wusongqing 已提交
744
**Return value**
745

W
wusongqing 已提交
746 747 748
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
749

W
wusongqing 已提交
750
**Example**
W
wusongqing 已提交
751 752

```
753
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
754
    console.log('Promise returned to indicate that the volume is obtained.' + value);
755 756 757 758 759
});
```

### getMinVolume

W
wusongqing 已提交
760
getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
761

W
wusongqing 已提交
762
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
763

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

W
wusongqing 已提交
766
**Parameters**
W
wusongqing 已提交
767

W
wusongqing 已提交
768 769 770 771
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
772

W
wusongqing 已提交
773
**Example**
W
wusongqing 已提交
774 775 776 777 778

```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the minimum volume. ${err.message}');
779
        return;
W
wusongqing 已提交
780 781
    }
    console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
782
});
W
wusongqing 已提交
783 784
```

785
### getMinVolume
V
Vaidegi B 已提交
786

W
wusongqing 已提交
787
getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
W
wusongqing 已提交
788

W
wusongqing 已提交
789
Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
W
wusongqing 已提交
790

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

W
wusongqing 已提交
793
**Parameters**
794

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

W
wusongqing 已提交
799
**Return value**
W
wusongqing 已提交
800

W
wusongqing 已提交
801 802 803
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
W
wusongqing 已提交
804

W
wusongqing 已提交
805
**Example**
806 807 808 809 810 811 812 813 814

```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
    console.log('Promised returned to indicate that the minimum volume is obtained.' + value);
});
```

### getMaxVolume

W
wusongqing 已提交
815
getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
816

W
wusongqing 已提交
817
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
818

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

W
wusongqing 已提交
821
**Parameters**
822

W
wusongqing 已提交
823 824 825 826
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
827

W
wusongqing 已提交
828
**Example**
W
wusongqing 已提交
829 830 831 832 833 834 835 836

```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the maximum volume. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the maximum volume is obtained.' + value);
837
});
W
wusongqing 已提交
838 839
```

840
### getMaxVolume
V
Vaidegi B 已提交
841

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

W
wusongqing 已提交
844
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
W
wusongqing 已提交
845

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

W
wusongqing 已提交
848
**Parameters**
W
wusongqing 已提交
849

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

W
wusongqing 已提交
854
**Return value**
855

W
wusongqing 已提交
856 857 858
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
W
wusongqing 已提交
859

W
wusongqing 已提交
860
**Example**
W
wusongqing 已提交
861 862

```
863
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
W
wusongqing 已提交
864
    console.log('Promised returned to indicate that the maximum volume is obtained.');
865
});
W
wusongqing 已提交
866 867
```

868
### mute
V
Vaidegi B 已提交
869

W
wusongqing 已提交
870
mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
W
wusongqing 已提交
871

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

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

W
wusongqing 已提交
876
**Parameters**
W
wusongqing 已提交
877

W
wusongqing 已提交
878 879 880 881 882
| 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.               |
883

W
wusongqing 已提交
884
**Example**
W
wusongqing 已提交
885 886 887 888 889

```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
    if (err) {
        console.error('Failed to mute the stream. ${err.message}');
890
        return;
W
wusongqing 已提交
891 892
    }
    console.log('Callback invoked to indicate that the stream is muted.');
893
});
W
wusongqing 已提交
894 895
```

896
### mute
V
Vaidegi B 已提交
897

W
wusongqing 已提交
898 899 900
mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;

Mutes or unmutes a stream. This API uses a promise to return the result.
V
Vaidegi B 已提交
901

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

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

W
wusongqing 已提交
906 907 908 909
| 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.|
910

W
wusongqing 已提交
911
**Return value**
W
wusongqing 已提交
912

W
wusongqing 已提交
913 914 915
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
916

W
wusongqing 已提交
917
**Example**
918

W
wusongqing 已提交
919 920

```
921
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
W
wusongqing 已提交
922
    console.log('Promise returned to indicate that the stream is muted.');
923
});
W
wusongqing 已提交
924 925
```

V
Vaidegi B 已提交
926

927
### isMute
V
Vaidegi B 已提交
928

W
wusongqing 已提交
929
isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
930

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

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

W
wusongqing 已提交
935
**Parameters**
W
wusongqing 已提交
936

W
wusongqing 已提交
937 938 939 940
| 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.|
941

W
wusongqing 已提交
942
**Example**
W
wusongqing 已提交
943 944 945 946

```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
947 948
       console.error('Failed to obtain the mute status. ${err.message}');
       return;
W
wusongqing 已提交
949 950
   }
   console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
951
});
W
wusongqing 已提交
952 953 954
```


955
### isMute
V
Vaidegi B 已提交
956

W
wusongqing 已提交
957
isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
V
Vaidegi B 已提交
958

W
wusongqing 已提交
959
Checks whether a stream is muted. This method uses a promise to return the result.
W
wusongqing 已提交
960

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

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

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

W
wusongqing 已提交
969
**Return value**
970

W
wusongqing 已提交
971 972 973
| 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.|
974

W
wusongqing 已提交
975
**Example**
W
wusongqing 已提交
976 977

```
978
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
979
    console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
980
});
W
wusongqing 已提交
981 982
```

983
### isActive
V
Vaidegi B 已提交
984

W
wusongqing 已提交
985
isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
986

W
wusongqing 已提交
987
Checks whether a stream is active. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
988

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

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

W
wusongqing 已提交
993 994 995 996
| 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.|
997

W
wusongqing 已提交
998
**Example**
W
wusongqing 已提交
999 1000 1001 1002 1003

```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the active status of the stream. ${err.message}');
1004
        return;
W
wusongqing 已提交
1005 1006
    }
    console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
1007
});
W
wusongqing 已提交
1008 1009
```

1010
### isActive
V
Vaidegi B 已提交
1011

W
wusongqing 已提交
1012
isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
W
wusongqing 已提交
1013

W
wusongqing 已提交
1014
Checks whether a stream is active. This method uses a promise to return the result.
W
wusongqing 已提交
1015

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

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

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

W
wusongqing 已提交
1024
**Return value**
1025

W
wusongqing 已提交
1026 1027 1028
| 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.|
1029

W
wusongqing 已提交
1030
**Example**
W
wusongqing 已提交
1031 1032

```
1033
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
1034
    console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
1035
});
W
wusongqing 已提交
1036 1037
```

1038
### setRingerMode
V
Vaidegi B 已提交
1039

W
wusongqing 已提交
1040
setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1041

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

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

W
wusongqing 已提交
1046
**Parameters**
W
wusongqing 已提交
1047

W
wusongqing 已提交
1048 1049 1050 1051
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1052

W
wusongqing 已提交
1053
**Example**
W
wusongqing 已提交
1054 1055 1056 1057 1058 1059 1060 1061

```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
   if (err) {
       console.error('Failed to set the ringer mode.​ ${err.message}');
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the ringer mode.');
1062
});
W
wusongqing 已提交
1063 1064
```

1065
### setRingerMode
V
Vaidegi B 已提交
1066

W
wusongqing 已提交
1067
setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
V
Vaidegi B 已提交
1068

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

W
wusongqing 已提交
1071
**System capability**: SystemCapability.Multimedia.Audio.Communication
1072

W
wusongqing 已提交
1073
**Parameters**
W
wusongqing 已提交
1074

W
wusongqing 已提交
1075 1076 1077
| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1078

W
wusongqing 已提交
1079
**Return value**
1080

W
wusongqing 已提交
1081 1082 1083
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1084

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

```
1088
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
W
wusongqing 已提交
1089
    console.log('Promise returned to indicate a successful setting of the ringer mode.');
1090
});
W
wusongqing 已提交
1091 1092
```

V
Vaidegi B 已提交
1093

1094
### getRingerMode
V
Vaidegi B 已提交
1095

W
wusongqing 已提交
1096
getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
W
wusongqing 已提交
1097

W
wusongqing 已提交
1098
Obtains the ringer mode. This API uses an asynchronous callback to return the result.
1099

W
wusongqing 已提交
1100
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1101

W
wusongqing 已提交
1102
**Parameters**
W
wusongqing 已提交
1103

W
wusongqing 已提交
1104 1105 1106
| Name  | Type                                                | Mandatory| Description                    |
| -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes  | Callback used to return the ringer mode.|
W
wusongqing 已提交
1107

W
wusongqing 已提交
1108
**Example**
W
wusongqing 已提交
1109 1110 1111 1112

```
audioManager.getRingerMode((err, value) => {
   if (err) {
1113 1114
       console.error('Failed to obtain the ringer mode.​ ${err.message}');
       return;
W
wusongqing 已提交
1115 1116
   }
   console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
1117
});
W
wusongqing 已提交
1118 1119
```

V
Vaidegi B 已提交
1120

1121
### getRingerMode
V
Vaidegi B 已提交
1122

W
wusongqing 已提交
1123
getRingerMode(): Promise&lt;AudioRingMode&gt;
W
wusongqing 已提交
1124

W
wusongqing 已提交
1125
Obtains the ringer mode. This API uses a promise to return the result.
W
wusongqing 已提交
1126

W
wusongqing 已提交
1127
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1128

W
wusongqing 已提交
1129
**Return value**
W
wusongqing 已提交
1130

W
wusongqing 已提交
1131 1132 1133
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
W
wusongqing 已提交
1134

W
wusongqing 已提交
1135
**Example**
W
wusongqing 已提交
1136 1137

```
1138
audioManager.getRingerMode().then((value) => {
W
wusongqing 已提交
1139
    console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
1140
});
W
wusongqing 已提交
1141 1142
```

1143
### setAudioParameter
V
Vaidegi B 已提交
1144

W
wusongqing 已提交
1145
setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1146

1147 1148
Sets an audio parameter. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
1149
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1150

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

W
wusongqing 已提交
1153 1154 1155 1156 1157
| 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.|
W
wusongqing 已提交
1158

W
wusongqing 已提交
1159
**Example**
W
wusongqing 已提交
1160 1161

```
1162
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
W
wusongqing 已提交
1163 1164
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
1165
        return;
W
wusongqing 已提交
1166 1167
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
1168
});
W
wusongqing 已提交
1169 1170
```

1171
### setAudioParameter
V
Vaidegi B 已提交
1172

W
wusongqing 已提交
1173
setAudioParameter(key: string, value: string): Promise&lt;void&gt;
V
Vaidegi B 已提交
1174

1175
Sets an audio parameter. This API uses a promise to return the result.
W
wusongqing 已提交
1176

W
wusongqing 已提交
1177
**System capability**: SystemCapability.Multimedia.Audio.Core
1178

W
wusongqing 已提交
1179
**Parameters**
W
wusongqing 已提交
1180

W
wusongqing 已提交
1181 1182 1183 1184
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
1185

W
wusongqing 已提交
1186
**Return value**
1187

W
wusongqing 已提交
1188 1189 1190
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1191

W
wusongqing 已提交
1192
**Example**
W
wusongqing 已提交
1193 1194

```
1195
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
W
wusongqing 已提交
1196
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1197
});
W
wusongqing 已提交
1198 1199
```

1200
### getAudioParameter
V
Vaidegi B 已提交
1201

W
wusongqing 已提交
1202
getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
W
wusongqing 已提交
1203

W
wusongqing 已提交
1204
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
1205

W
wusongqing 已提交
1206
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1207

W
wusongqing 已提交
1208
**Parameters**
W
wusongqing 已提交
1209

W
wusongqing 已提交
1210 1211 1212 1213
| 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.|
W
wusongqing 已提交
1214

W
wusongqing 已提交
1215
**Example**
W
wusongqing 已提交
1216 1217

```
1218
audioManager.getAudioParameter('key_example', (err, value) => {
W
wusongqing 已提交
1219 1220
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1221
        return;
W
wusongqing 已提交
1222 1223
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1224
});
W
wusongqing 已提交
1225 1226
```

1227
### getAudioParameter
V
Vaidegi B 已提交
1228

W
wusongqing 已提交
1229
getAudioParameter(key: string): Promise&lt;string&gt;
W
wusongqing 已提交
1230

W
wusongqing 已提交
1231
Obtains the value of an audio parameter. This API uses a promise to return the result.
W
wusongqing 已提交
1232

W
wusongqing 已提交
1233
**System capability**: SystemCapability.Multimedia.Audio.Core
1234

W
wusongqing 已提交
1235
**Parameters**
1236

W
wusongqing 已提交
1237 1238 1239
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1240

W
wusongqing 已提交
1241
**Return value**
W
wusongqing 已提交
1242

W
wusongqing 已提交
1243 1244 1245
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1246

W
wusongqing 已提交
1247
**Example**
W
wusongqing 已提交
1248 1249

```
1250
audioManager.getAudioParameter('key_example').then((value) => {
W
wusongqing 已提交
1251
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1252
});
W
wusongqing 已提交
1253 1254
```

1255 1256
### getDevices

W
wusongqing 已提交
1257
getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
1258

W
wusongqing 已提交
1259
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1260

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

W
wusongqing 已提交
1263
**Parameters**
W
wusongqing 已提交
1264

W
wusongqing 已提交
1265 1266 1267 1268
| 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.|
W
wusongqing 已提交
1269

W
wusongqing 已提交
1270
**Example**
W
wusongqing 已提交
1271
```
1272
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1273
   if (err) {
1274 1275
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1276 1277
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1278
});
W
wusongqing 已提交
1279 1280
```

1281
### getDevices
V
Vaidegi B 已提交
1282

W
wusongqing 已提交
1283
getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
W
wusongqing 已提交
1284

W
wusongqing 已提交
1285
Obtains the audio devices with a specific flag. This API uses a promise to return the result.
W
wusongqing 已提交
1286

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

W
wusongqing 已提交
1289
**Parameters**
W
wusongqing 已提交
1290

W
wusongqing 已提交
1291 1292 1293
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
W
wusongqing 已提交
1294

W
wusongqing 已提交
1295
**Return value**
1296

W
wusongqing 已提交
1297 1298 1299
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
W
wusongqing 已提交
1300

W
wusongqing 已提交
1301
**Example**
W
wusongqing 已提交
1302 1303

```
1304
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1305
    console.log('Promise returned to indicate that the device list is obtained.');
1306
});
W
wusongqing 已提交
1307 1308
```

1309
### setDeviceActive
V
Vaidegi B 已提交
1310

W
wusongqing 已提交
1311
setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1312

1313
Sets a device to the active state. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1314

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

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

W
wusongqing 已提交
1319 1320 1321 1322 1323
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.      |
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.          |
| callback   | AsyncCallback&lt;void&gt;             | Yes  | Callback used to return the result.|
1324

W
wusongqing 已提交
1325
**Example**
W
wusongqing 已提交
1326 1327

```
W
wusongqing 已提交
1328
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1329 1330
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1331
        return;
W
wusongqing 已提交
1332 1333
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1334
});
W
wusongqing 已提交
1335 1336
```

1337
### setDeviceActive
V
Vaidegi B 已提交
1338

W
wusongqing 已提交
1339
setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
1340

1341
Sets a device to the active state. This API uses a promise to return the result.
W
wusongqing 已提交
1342

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

W
wusongqing 已提交
1345
**Parameters**
1346

W
wusongqing 已提交
1347 1348 1349 1350
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
| active     | boolean                               | Yes  | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.    |
W
wusongqing 已提交
1351

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

W
wusongqing 已提交
1354 1355 1356
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1357

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

W
wusongqing 已提交
1360 1361

```
W
wusongqing 已提交
1362
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1363
    console.log('Promise returned to indicate that the device is set to the active status.');
1364
});
W
wusongqing 已提交
1365 1366
```

1367
### isDeviceActive
V
Vaidegi B 已提交
1368

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

W
wusongqing 已提交
1371
Checks whether a device is active. This API uses an asynchronous callback to return the result.
W
wusongqing 已提交
1372

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

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

W
wusongqing 已提交
1377 1378 1379 1380
| Name    | Type                                 | Mandatory| Description                    |
| ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.      |
| callback   | AsyncCallback&lt;boolean&gt;          | Yes  | Callback used to return the active state of the device.|
1381

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

```
W
wusongqing 已提交
1385
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1386 1387
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1388
        return;
W
wusongqing 已提交
1389 1390
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1391
});
W
wusongqing 已提交
1392 1393
```

V
Vaidegi B 已提交
1394

1395
### isDeviceActive
V
Vaidegi B 已提交
1396

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

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

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

W
wusongqing 已提交
1403
**Parameters**
1404

W
wusongqing 已提交
1405 1406 1407
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
1408

W
wusongqing 已提交
1409
**Return value**
1410

W
wusongqing 已提交
1411 1412 1413
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1414

W
wusongqing 已提交
1415
**Example**
W
wusongqing 已提交
1416 1417

```
W
wusongqing 已提交
1418
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1419
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1420
});
W
wusongqing 已提交
1421 1422
```

1423
### setMicrophoneMute
V
Vaidegi B 已提交
1424

W
wusongqing 已提交
1425
setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
V
Vaidegi B 已提交
1426

1427 1428
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
1431
**Parameters**
W
wusongqing 已提交
1432

W
wusongqing 已提交
1433 1434 1435 1436
| 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.                     |
W
wusongqing 已提交
1437

W
wusongqing 已提交
1438
**Example**
W
wusongqing 已提交
1439 1440 1441 1442 1443 1444 1445 1446

```
audioManager.setMicrophoneMute(true, (err) => {
    if (err) {
        console.error('Failed to mute the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the microphone is muted.');
1447
});
W
wusongqing 已提交
1448 1449
```

1450
### setMicrophoneMute
V
Vaidegi B 已提交
1451

W
wusongqing 已提交
1452
setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
V
Vaidegi B 已提交
1453

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

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

W
wusongqing 已提交
1458
**Parameters**
1459

W
wusongqing 已提交
1460 1461 1462
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1463

W
wusongqing 已提交
1464
**Return value**
W
wusongqing 已提交
1465

W
wusongqing 已提交
1466 1467 1468
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1469

W
wusongqing 已提交
1470
**Example**
W
wusongqing 已提交
1471 1472

```
1473
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1474
    console.log('Promise returned to indicate that the microphone is muted.');
1475
});
W
wusongqing 已提交
1476 1477
```

1478
### isMicrophoneMute
V
Vaidegi B 已提交
1479

W
wusongqing 已提交
1480
isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
W
wusongqing 已提交
1481

W
wusongqing 已提交
1482
Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
1483

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

W
wusongqing 已提交
1486
**Parameters**
W
wusongqing 已提交
1487

W
wusongqing 已提交
1488 1489 1490
| 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.|
W
wusongqing 已提交
1491

W
wusongqing 已提交
1492
**Example**
W
wusongqing 已提交
1493 1494 1495 1496 1497 1498 1499 1500

```
audioManager.isMicrophoneMute((err, value) => {
    if (err) {
        console.error('Failed to obtain the mute status of the microphone. ${err.message}');
        return;
    }
    console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value);
1501
});
W
wusongqing 已提交
1502 1503
```

1504
### isMicrophoneMute
V
Vaidegi B 已提交
1505

W
wusongqing 已提交
1506 1507 1508
isMicrophoneMute(): Promise&lt;boolean&gt;

Checks whether the microphone is muted. This API uses a promise to return the result.
W
wusongqing 已提交
1509

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

W
wusongqing 已提交
1512
**Return value**
1513

W
wusongqing 已提交
1514 1515 1516
| 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.|
W
wusongqing 已提交
1517

W
wusongqing 已提交
1518
**Example**
W
wusongqing 已提交
1519 1520 1521


```
1522
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1523
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1524
});
W
wusongqing 已提交
1525 1526
```

1527
### on('volumeChange')<sup>8+</sup>
W
wusongqing 已提交
1528

1529
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
Z
zengyawen 已提交
1530

W
wusongqing 已提交
1531
Subscribes to system volume change events.
V
Vaidegi B 已提交
1532

1533
This is a system API and cannot be called by third-party applications.
1534

W
wusongqing 已提交
1535
**System capability**: SystemCapability.Multimedia.Audio.Volume
V
Vaidegi B 已提交
1536

W
wusongqing 已提交
1537
**Parameters**
V
Vaidegi B 已提交
1538

W
wusongqing 已提交
1539 1540 1541 1542
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                 | Yes  | Type of event to subscribe to. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
V
Vaidegi B 已提交
1543

W
wusongqing 已提交
1544
**Example**
V
Vaidegi B 已提交
1545 1546 1547 1548 1549 1550

```
audioManager.on('volumeChange', (volumeEvent) => {
    console.log('VolumeType of stream: ' + volumeEvent.volumeType);
    console.log('Volume level: ' + volumeEvent.volume);
    console.log('Whether to updateUI: ' + volumeEvent.updateUi);
1551
});
V
Vaidegi B 已提交
1552 1553
```

1554
### on('ringerModeChange')<sup>8+</sup>
V
Vaidegi B 已提交
1555

1556
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
V
Vaidegi B 已提交
1557

W
wusongqing 已提交
1558
Subscribes to ringer mode change events.
1559

1560
This is a system API and cannot be called by third-party applications.
V
Vaidegi B 已提交
1561

W
wusongqing 已提交
1562
**System capability**: SystemCapability.Multimedia.Audio.Communication
V
Vaidegi B 已提交
1563

W
wusongqing 已提交
1564
**Parameters**
V
Vaidegi B 已提交
1565

W
wusongqing 已提交
1566 1567 1568 1569
| Name  | Type                                     | Mandatory| Description                                                        |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                    | Yes  | Type of event to subscribe to. 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 updated ringer mode.                                                  |
V
Vaidegi B 已提交
1570

W
wusongqing 已提交
1571
**Example**
V
Vaidegi B 已提交
1572 1573 1574 1575

```
audioManager.on('ringerModeChange', (ringerMode) => {
    console.log('Updated ringermode: ' + ringerMode);
1576
});
V
Vaidegi B 已提交
1577 1578
```

1579
### on('deviceChange')
1580

1581
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1582

W
wusongqing 已提交
1583
Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
1584

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

W
wusongqing 已提交
1587
**Parameters**
1588

W
wusongqing 已提交
1589 1590 1591 1592
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type     | string                                               | Yes  | Type of event to subscribe to. 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.                        |
1593

W
wusongqing 已提交
1594
**Example**
1595 1596 1597 1598 1599 1600 1601

```
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);
1602
});
1603 1604
```

1605 1606 1607 1608
### off('deviceChange')

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

W
wusongqing 已提交
1609
Unsubscribes from device change events.
1610

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

W
wusongqing 已提交
1613
**Parameters**
1614

W
wusongqing 已提交
1615 1616 1617 1618
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type     | string                                              | Yes  | Type of event to unsubscribe from. 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.                        |
1619

W
wusongqing 已提交
1620
**Example**
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631

```
audioManager.off('deviceChange', (deviceChanged) => {
    console.log("Should be no callback.");
});
```

### on('interrupt')

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

W
wusongqing 已提交
1632
Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
1633

W
wusongqing 已提交
1634
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1635

W
wusongqing 已提交
1636
**Parameters**
1637

W
wusongqing 已提交
1638 1639 1640 1641 1642
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | Yes  | Type of event to subscribe to. 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](#interruptaction)> | Yes  | Callback invoked for the audio interruption event.                                      |
1643

W
wusongqing 已提交
1644
**Example**
1645 1646 1647 1648 1649 1650 1651

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
W
wusongqing 已提交
1652
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
    if (InterruptAction.actionType === 0) {
        console.log("An event to gain the audio focus starts.");
        console.log("Focus gain event:" + JSON.stringify(InterruptAction));
    }
    if (InterruptAction.actionType === 1) {
        console.log("An audio interruption event starts.");
        console.log("Audio interruption event:" + JSON.stringify(InterruptAction));
    }
});
```

### off('interrupt')

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

W
wusongqing 已提交
1668
Unsubscribes from audio interruption events.
1669

W
wusongqing 已提交
1670
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1671

W
wusongqing 已提交
1672
**Parameters**
1673

W
wusongqing 已提交
1674 1675 1676 1677 1678
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type      | string                                        | Yes  | Type of event to unsubscribe from. 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](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1679

W
wusongqing 已提交
1680
**Example**
1681 1682 1683 1684 1685 1686 1687

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
W
wusongqing 已提交
1688
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1689 1690 1691 1692 1693 1694 1695 1696
    if (InterruptAction.actionType === 0) {
        console.log("An event to release the audio focus starts.");
        console.log("Focus release event:" + JSON.stringify(InterruptAction));
    }
});
```

### setAudioScene<sup>8+</sup>
1697

1698
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1699

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

1702
This is a system API and cannot be called by third-party applications.
1703

W
wusongqing 已提交
1704
**System capability**: SystemCapability.Multimedia.Audio.Communication
1705

W
wusongqing 已提交
1706
**Parameters**
1707

W
wusongqing 已提交
1708 1709 1710 1711
| 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.|
1712

W
wusongqing 已提交
1713
**Example**
1714 1715 1716 1717 1718 1719 1720 1721

```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
   if (err) {
       console.error('Failed to set the audio scene mode.​ ${err.message}');
       return;
    }
    console.log('Callback invoked to indicate a successful setting of the audio scene mode.');
1722
});
1723 1724
```

1725
### setAudioScene<sup>8+</sup>
1726

1727
setAudioScene\(scene: AudioScene\): Promise<void\>
1728

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

1731
This is a system API and cannot be called by third-party applications.
1732

W
wusongqing 已提交
1733
**System capability**: SystemCapability.Multimedia.Audio.Communication
1734

W
wusongqing 已提交
1735
**Parameters**
1736

W
wusongqing 已提交
1737 1738 1739
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1740

W
wusongqing 已提交
1741
**Return value**
1742

W
wusongqing 已提交
1743 1744 1745
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
1746

W
wusongqing 已提交
1747
**Example**
1748 1749

```
W
wusongqing 已提交
1750
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1751 1752 1753 1754 1755 1756
    console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => {
    console.log('Failed to set the audio scene mode');
});
```

1757
### getAudioScene<sup>8+</sup>
1758

1759
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1760

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

W
wusongqing 已提交
1763
**System capability**: SystemCapability.Multimedia.Audio.Communication
1764

W
wusongqing 已提交
1765
**Parameters**
1766

W
wusongqing 已提交
1767 1768 1769
| Name  | Type                                               | Mandatory| Description                        |
| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes  | Callback used to return the audio scene.|
1770

W
wusongqing 已提交
1771
**Example**
1772 1773 1774 1775 1776 1777 1778 1779

```
audioManager.getAudioScene((err, value) => {
   if (err) {
       console.error('Failed to obtain the audio scene mode.​ ${err.message}');
       return;
   }
   console.log('Callback invoked to indicate that the audio scene mode is obtained.' + value);
1780
});
1781 1782 1783
```


1784
### getAudioScene<sup>8+</sup>
1785

1786
getAudioScene\(\): Promise<AudioScene\>
1787

W
wusongqing 已提交
1788
Obtains the audio scene. This API uses a promise to return the result.
1789

W
wusongqing 已提交
1790
**System capability**: SystemCapability.Multimedia.Audio.Communication
1791

W
wusongqing 已提交
1792
**Return value**
1793

W
wusongqing 已提交
1794 1795 1796
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1797

W
wusongqing 已提交
1798
**Example**
1799 1800 1801 1802 1803 1804

```
audioManager.getAudioScene().then((value) => {
    console.log('Promise returned to indicate that the audio scene mode is obtained.' + value);
}).catch ((err) => {
    console.log('Failed to obtain the audio scene mode');
1805
});
1806 1807
```

1808
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1809

1810
Describes an audio device.
1811

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

W
wusongqing 已提交
1814 1815 1816 1817
| Name      | Type                   | Readable| Writable| Description      |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes  | No  | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes  | No  | Device type.|
V
Vaidegi B 已提交
1818

1819
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1820

1821
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
V
Vaidegi B 已提交
1822

W
wusongqing 已提交
1823
**Example**
V
Vaidegi B 已提交
1824

1825 1826
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1827

1828 1829 1830
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1831 1832 1833

}

1834 1835 1836 1837 1838 1839
var deviceRoleValue = null;
var deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
    console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
    value.forEach(displayDeviceProp);
V
Vaidegi B 已提交
1840
    if (deviceTypeValue != null && deviceRoleValue != null){
1841
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1842 1843
    }
    else{
1844 1845
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1846
});
V
Vaidegi B 已提交
1847 1848
```

W
wusongqing 已提交
1849
## AudioRenderer<sup>8+</sup>
V
Vaidegi B 已提交
1850

W
wusongqing 已提交
1851
Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
V
Vaidegi B 已提交
1852

W
wusongqing 已提交
1853
### Attributes
V
Vaidegi B 已提交
1854

W
wusongqing 已提交
1855
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1856

W
wusongqing 已提交
1857 1858 1859
| Name | Type                    | Readable| Writable| Description              |
| ----- | -------------------------- | ---- | ---- | ------------------ |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes  | No  | Audio renderer state.|
V
Vaidegi B 已提交
1860

W
wusongqing 已提交
1861
**Example**
V
Vaidegi B 已提交
1862 1863

```
W
wusongqing 已提交
1864
var state = audioRenderer.state;
V
Vaidegi B 已提交
1865 1866
```

1867
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1868

1869
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
V
Vaidegi B 已提交
1870

W
wusongqing 已提交
1871
Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1872

W
wusongqing 已提交
1873
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1874

W
wusongqing 已提交
1875
**Parameters**
V
Vaidegi B 已提交
1876

W
wusongqing 已提交
1877 1878 1879
| Name  | Type                                                    | Mandatory| Description                  |
| :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes  | Callback used to return the renderer information.|
V
Vaidegi B 已提交
1880

W
wusongqing 已提交
1881
**Example**
V
Vaidegi B 已提交
1882 1883

```
1884
audioRenderer.getRendererInfo((err, rendererInfo) => {
1885 1886 1887 1888
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1889
});
V
Vaidegi B 已提交
1890 1891
```

1892
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1893

1894
getRendererInfo(): Promise<AudioRendererInfo\>
1895

W
wusongqing 已提交
1896
Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
1897

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

W
wusongqing 已提交
1900
**Return value**
V
Vaidegi B 已提交
1901

W
wusongqing 已提交
1902 1903 1904
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
V
Vaidegi B 已提交
1905

W
wusongqing 已提交
1906
**Example**
V
Vaidegi B 已提交
1907 1908

```
W
wusongqing 已提交
1909
var resultFlag = true;
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919
audioRenderer.getRendererInfo().then((rendererInfo) => {
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
}).catch((err) => {
    console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
    resultFlag = false;
});
```
V
Vaidegi B 已提交
1920

1921
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1922

1923
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1924

W
wusongqing 已提交
1925
Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1926

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

W
wusongqing 已提交
1929
**Parameters**
V
Vaidegi B 已提交
1930

W
wusongqing 已提交
1931 1932 1933
| Name  | Type                                                | Mandatory| Description                |
| :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
V
Vaidegi B 已提交
1934

W
wusongqing 已提交
1935
**Example**
V
Vaidegi B 已提交
1936 1937

```
1938
audioRenderer.getStreamInfo((err, streamInfo) => {
1939 1940
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1941 1942 1943
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1944
});
V
Vaidegi B 已提交
1945 1946
```

1947
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1948

1949
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1950

W
wusongqing 已提交
1951
Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
1952

W
wusongqing 已提交
1953
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1954

W
wusongqing 已提交
1955
**Return value**
V
Vaidegi B 已提交
1956

W
wusongqing 已提交
1957 1958 1959
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
1960

W
wusongqing 已提交
1961
**Example**
V
Vaidegi B 已提交
1962 1963

```
1964 1965 1966 1967 1968 1969 1970 1971 1972
audioRenderer.getStreamInfo().then((streamInfo) => {
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
1973 1974
```

1975
### start<sup>8+</sup>
V
Vaidegi B 已提交
1976

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

1979
Starts the renderer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
1980

W
wusongqing 已提交
1981
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1982

W
wusongqing 已提交
1983
**Parameters**
V
Vaidegi B 已提交
1984

W
wusongqing 已提交
1985 1986 1987
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
1988

W
wusongqing 已提交
1989
**Example**
V
Vaidegi B 已提交
1990 1991

```
1992
audioRenderer.start((err) => {
1993 1994
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
1995
    } else {
1996
        console.info('Renderer start success.');
V
Vaidegi B 已提交
1997
    }
1998
});
V
Vaidegi B 已提交
1999 2000
```

2001
### start<sup>8+</sup>
V
Vaidegi B 已提交
2002

2003
start(): Promise<void\>
V
Vaidegi B 已提交
2004

2005
Starts the renderer. This API uses a promise to return the result.
V
Vaidegi B 已提交
2006

W
wusongqing 已提交
2007
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2008

W
wusongqing 已提交
2009
**Return value**
V
Vaidegi B 已提交
2010

W
wusongqing 已提交
2011 2012 2013
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2014

W
wusongqing 已提交
2015
**Example**
V
Vaidegi B 已提交
2016 2017

```
2018 2019 2020 2021 2022
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2023 2024
```

2025
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2026

2027
pause(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2028

2029
Pauses rendering. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2030

W
wusongqing 已提交
2031
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2032

W
wusongqing 已提交
2033
**Parameters**
V
Vaidegi B 已提交
2034

W
wusongqing 已提交
2035 2036 2037
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2038

W
wusongqing 已提交
2039
**Example**
V
Vaidegi B 已提交
2040 2041

```
2042
audioRenderer.pause((err) => {
2043 2044
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2045
    } else {
2046
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2047
    }
2048
});
V
Vaidegi B 已提交
2049 2050
```

2051
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2052

2053
pause(): Promise\<void>
V
Vaidegi B 已提交
2054

2055
Pauses rendering. This API uses a promise to return the result.
2056

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

W
wusongqing 已提交
2059
**Return value**
V
Vaidegi B 已提交
2060

W
wusongqing 已提交
2061 2062 2063
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2064

W
wusongqing 已提交
2065
**Example**
V
Vaidegi B 已提交
2066 2067

```
2068 2069 2070 2071 2072
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2073 2074
```

2075
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2076

2077
drain(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2078

2079
Drains the playback buffer. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2080

W
wusongqing 已提交
2081
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2082

W
wusongqing 已提交
2083
**Parameters**
V
Vaidegi B 已提交
2084

W
wusongqing 已提交
2085 2086 2087
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2088

W
wusongqing 已提交
2089
**Example**
V
Vaidegi B 已提交
2090 2091

```
2092
audioRenderer.drain((err) => {
2093 2094
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2095
    } else {
2096
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2097
    }
2098
});
V
Vaidegi B 已提交
2099 2100
```

2101
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2102

2103
drain(): Promise\<void>
V
Vaidegi B 已提交
2104

2105
Drains the playback buffer. This API uses a promise to return the result.
2106

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

W
wusongqing 已提交
2109
**Return value**
V
Vaidegi B 已提交
2110

W
wusongqing 已提交
2111 2112 2113
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2114

W
wusongqing 已提交
2115
**Example**
V
Vaidegi B 已提交
2116 2117

```
2118 2119 2120 2121 2122
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2123 2124
```

2125
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2126

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

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

W
wusongqing 已提交
2131
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2132

W
wusongqing 已提交
2133
**Parameters**
V
Vaidegi B 已提交
2134

W
wusongqing 已提交
2135 2136 2137
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2138

W
wusongqing 已提交
2139
**Example**
V
Vaidegi B 已提交
2140 2141

```
2142
audioRenderer.stop((err) => {
2143 2144
    if (err) {
        console.error('Renderer stop failed');
V
Vaidegi B 已提交
2145
    } else {
2146
        console.log('Renderer stopped.');
V
Vaidegi B 已提交
2147
    }
2148
});
V
Vaidegi B 已提交
2149 2150
```

2151
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2152

2153
stop(): Promise\<void>
V
Vaidegi B 已提交
2154

2155
Stops rendering. This API uses a promise to return the result.
V
Vaidegi B 已提交
2156

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

W
wusongqing 已提交
2159
**Return value**
V
Vaidegi B 已提交
2160

W
wusongqing 已提交
2161 2162 2163
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2164

W
wusongqing 已提交
2165
**Example**
V
Vaidegi B 已提交
2166 2167

```
2168 2169 2170 2171 2172
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2173 2174
```

2175
### release<sup>8+</sup>
V
Vaidegi B 已提交
2176

2177
release(callback: AsyncCallback\<void>): void
V
Vaidegi B 已提交
2178

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

W
wusongqing 已提交
2181
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2182

W
wusongqing 已提交
2183
**Parameters**
V
Vaidegi B 已提交
2184

W
wusongqing 已提交
2185 2186 2187
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2188

W
wusongqing 已提交
2189
**Example**
V
Vaidegi B 已提交
2190 2191

```
2192
audioRenderer.release((err) => {
2193 2194
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2195
    } else {
2196
        console.log('Renderer released.');
V
Vaidegi B 已提交
2197
    }
2198
});
V
Vaidegi B 已提交
2199 2200
```

2201
### release<sup>8+</sup>
V
Vaidegi B 已提交
2202

2203
release(): Promise\<void>
V
Vaidegi B 已提交
2204

2205
Releases the renderer. This API uses a promise to return the result.
V
Vaidegi B 已提交
2206

W
wusongqing 已提交
2207
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2208

W
wusongqing 已提交
2209
**Return value**
V
Vaidegi B 已提交
2210

W
wusongqing 已提交
2211 2212 2213
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2214

W
wusongqing 已提交
2215
**Example**
V
Vaidegi B 已提交
2216 2217

```
2218 2219 2220 2221 2222
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2223 2224
```

2225
### write<sup>8+</sup>
V
Vaidegi B 已提交
2226

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

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

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

W
wusongqing 已提交
2233
**Parameters**
V
Vaidegi B 已提交
2234

W
wusongqing 已提交
2235 2236 2237 2238
| Name  | Type                  | Mandatory| Description                                               |
| -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer   | ArrayBuffer            | Yes  | Buffer to be written.                               |
| callback | AsyncCallback\<number> | Yes  | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
V
Vaidegi B 已提交
2239

W
wusongqing 已提交
2240
**Example**
V
Vaidegi B 已提交
2241 2242

```
2243 2244 2245
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

V
Vaidegi B 已提交
2246 2247 2248
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2249
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2250
    if (writtenbytes < 0) {
2251
        console.error('write failed.');
V
Vaidegi B 已提交
2252 2253 2254
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2255
});
V
Vaidegi B 已提交
2256 2257
```

2258
### write<sup>8+</sup>
V
Vaidegi B 已提交
2259

2260
write(buffer: ArrayBuffer): Promise\<number>
V
Vaidegi B 已提交
2261

2262
Writes the buffer. This API uses a promise to return the result.
2263

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

W
wusongqing 已提交
2266
**Return value**
V
Vaidegi B 已提交
2267

W
wusongqing 已提交
2268 2269 2270
| Type            | Description                                                        |
| ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
V
Vaidegi B 已提交
2271

W
wusongqing 已提交
2272
**Example**
V
Vaidegi B 已提交
2273 2274

```
2275 2276 2277 2278
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2279 2280 2281
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2282 2283 2284 2285 2286 2287 2288 2289 2290
audioRenderer.write(buf).then((writtenbytes) => {
    if (writtenbytes < 0) {
        console.error('write failed.');
    } else {
        console.log('Actual written bytes: ' + writtenbytes);
    }
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2291 2292
```

2293
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2294

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

W
wusongqing 已提交
2297
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 已提交
2298

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

W
wusongqing 已提交
2301
**Parameters**
V
Vaidegi B 已提交
2302

W
wusongqing 已提交
2303 2304 2305
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
2306

W
wusongqing 已提交
2307
**Example**
V
Vaidegi B 已提交
2308 2309

```
2310
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2311
    console.log('Current timestamp: ' + timestamp);
2312
});
V
Vaidegi B 已提交
2313 2314
```

2315
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2316

2317
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2318

W
wusongqing 已提交
2319
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
V
Vaidegi B 已提交
2320

W
wusongqing 已提交
2321
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2322

W
wusongqing 已提交
2323
**Return value**
V
Vaidegi B 已提交
2324

W
wusongqing 已提交
2325 2326 2327
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
2328

W
wusongqing 已提交
2329
**Example**
V
Vaidegi B 已提交
2330 2331

```
2332 2333 2334 2335 2336
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2337 2338
```

2339
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2340

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

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

W
wusongqing 已提交
2345
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2346

W
wusongqing 已提交
2347
**Parameters**
V
Vaidegi B 已提交
2348

W
wusongqing 已提交
2349 2350 2351
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
2352

W
wusongqing 已提交
2353
**Example**
V
Vaidegi B 已提交
2354 2355

```
W
wusongqing 已提交
2356
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
V
Vaidegi B 已提交
2357 2358 2359
    if (err) {
        console.error('getBufferSize error');
    }
2360
});
V
Vaidegi B 已提交
2361 2362
```

2363
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2364

2365
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2366

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

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

W
wusongqing 已提交
2371
**Return value**
V
Vaidegi B 已提交
2372

W
wusongqing 已提交
2373 2374 2375
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
2376

W
wusongqing 已提交
2377
**Example**
V
Vaidegi B 已提交
2378 2379

```
W
wusongqing 已提交
2380 2381 2382 2383
var bufferSize;
await audioRenderer.getBufferSize().then(async function (data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
    bufferSize=data;
2384
}).catch((err) => {
W
wusongqing 已提交
2385
    console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
2386
});
V
Vaidegi B 已提交
2387 2388
```

2389
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2390

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

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

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

W
wusongqing 已提交
2397
**Parameters**
2398

W
wusongqing 已提交
2399 2400 2401 2402
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2403

W
wusongqing 已提交
2404
**Example**
V
Vaidegi B 已提交
2405 2406

```
2407
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2408
    if (err) {
2409
        console.error('Failed to set params');
V
Vaidegi B 已提交
2410 2411 2412
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2413
});
V
Vaidegi B 已提交
2414 2415
```

2416
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2417

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

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

W
wusongqing 已提交
2422
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2423

W
wusongqing 已提交
2424
**Parameters**
V
Vaidegi B 已提交
2425

W
wusongqing 已提交
2426 2427 2428
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
V
Vaidegi B 已提交
2429

W
wusongqing 已提交
2430
**Return value**
V
Vaidegi B 已提交
2431

W
wusongqing 已提交
2432 2433 2434
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2435

W
wusongqing 已提交
2436
**Example**
V
Vaidegi B 已提交
2437 2438

```
2439 2440 2441 2442 2443
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2444 2445
```

2446
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2447

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

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

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

W
wusongqing 已提交
2454
**Parameters**
2455

W
wusongqing 已提交
2456 2457 2458
| Name  | Type                                                   | Mandatory| Description              |
| -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes  | Callback used to return the audio render rate.|
V
Vaidegi B 已提交
2459

W
wusongqing 已提交
2460
**Example**
V
Vaidegi B 已提交
2461 2462

```
2463
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2464
    console.log('getRenderRate: ' + renderrate);
2465
});
V
Vaidegi B 已提交
2466 2467
```

2468
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2469

2470
getRenderRate(): Promise\<AudioRendererRate>
2471

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

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

W
wusongqing 已提交
2476
**Return value**
V
Vaidegi B 已提交
2477

W
wusongqing 已提交
2478 2479 2480
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
2481

W
wusongqing 已提交
2482
**Example**
V
Vaidegi B 已提交
2483 2484

```
2485 2486 2487 2488 2489
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2490
```
W
wusongqing 已提交
2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531
### setInterruptMode<sup>9+</sup>

setInterruptMode(interruptMode: InterruptMode): Promise&lt;void&gt;

Sets the audio interruption mode for the application. This API uses a promise to return the result.

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

**Parameters**

| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| interruptMode | [InterruptMode](#InterruptMode) | Yes  | Audio interruption mode.                                            |

**Return value**

| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned.|

**Example**

```
audioManager.setInterruptMode(audio.InterruptType.SHARE_MODE).then(() => {
    console.log('Promise returned to indicate a successful volume setting.');
});
```
### setInterruptMode<sup>9+</sup>

setInterruptMode(interruptMode: InterruptMode, callback: Callback\<void>): void

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

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

**Parameters**

| Name| Type| Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
|interruptMode | [InterruptMode](#InterruptMode) | Yes  | Audio interruption mode.|
|callback | Callback\<void>  | Yes |Callback used to return the result.|
V
Vaidegi B 已提交
2532

W
wusongqing 已提交
2533 2534 2535 2536 2537 2538 2539
**Example**

```
audioManager.setInterruptMode(audio.InterruptType.SHARE_MODE,()=>{
    console.log('Callback returned to indicate a successful volume setting.');
});
```
2540
### on('interrupt')<sup>9+</sup>
V
Vaidegi B 已提交
2541

2542
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
V
Vaidegi B 已提交
2543

W
wusongqing 已提交
2544
Subscribes to audio interruption events. This API uses a callback to get interrupt events.
2545

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

W
wusongqing 已提交
2548
**Parameters**
V
Vaidegi B 已提交
2549

W
wusongqing 已提交
2550 2551 2552 2553
| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                       | Yes  | Type of event to subscribe to. The value **interrupt** 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.                                    |
V
Vaidegi B 已提交
2554

W
wusongqing 已提交
2555
**Example**
V
Vaidegi B 已提交
2556 2557

```
W
wusongqing 已提交
2558 2559 2560
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
V
Vaidegi B 已提交
2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572
    if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
        switch (interruptEvent.hintType) {
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Force paused. Stop writing');
                isPlay = false;
                break;
            case audio.InterruptHint.INTERRUPT_HINT_STOP:
                console.log('Force stopped. Stop writing');
                isPlay = false;
                break;
        }
    } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
W
wusongqing 已提交
2573
        switch (interruptEvent.hintType) {
V
Vaidegi B 已提交
2574 2575
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
W
wusongqing 已提交
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
                await audioRenderer.start().then(async function () {
                    console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
                    started = true;
                }).catch((err) => {
                    console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
                    started = false;
                });
                if (started) {
                    isPlay = true;
                    console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
                } else {
                    console.error('AudioInterruptMusic Renderer start failed');
                }
V
Vaidegi B 已提交
2589 2590 2591
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
W
wusongqing 已提交
2592 2593 2594 2595 2596 2597 2598 2599
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
V
Vaidegi B 已提交
2600 2601 2602
                break;
        }
    }
2603
});
V
Vaidegi B 已提交
2604 2605
```

2606
### on('markReach')<sup>8+</sup>
2607

2608
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
2609

W
wusongqing 已提交
2610
Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
2611

W
wusongqing 已提交
2612
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2613

W
wusongqing 已提交
2614
**Parameters**
2615

W
wusongqing 已提交
2616 2617 2618 2619 2620
| Name  | Type                    | Mandatory| Description                                     |
| :------- | :----------------------- | :--- | :---------------------------------------- |
| type     | string                   | Yes  | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
| frame    | number                   | Yes  | Number of frames to trigger the event. The value must be greater than **0**.        |
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.                   |
2621

W
wusongqing 已提交
2622
**Example**
2623 2624 2625 2626 2627 2628 2629 2630 2631 2632

```
audioRenderer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```


2633
### off('markReach') <sup>8+</sup>
2634

2635
off(type: 'markReach'): void
2636 2637 2638

Unsubscribes from mark reached events.

W
wusongqing 已提交
2639
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2640

W
wusongqing 已提交
2641
**Parameters**
2642

W
wusongqing 已提交
2643 2644 2645
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **markReach**.|
2646

W
wusongqing 已提交
2647
**Example**
2648 2649 2650 2651 2652

```
audioRenderer.off('markReach');
```

2653
### on('periodReach') <sup>8+</sup>
2654

2655
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
2656

W
wusongqing 已提交
2657
Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
2658

W
wusongqing 已提交
2659
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2660

W
wusongqing 已提交
2661
**Parameters**
2662

W
wusongqing 已提交
2663 2664 2665 2666 2667
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | Yes  | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
| frame    | number                   | Yes  | Period during which frame rendering is listened. The value must be greater than **0**.          |
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.                     |
2668

W
wusongqing 已提交
2669
**Example**
2670 2671 2672 2673 2674 2675 2676 2677 2678

```
audioRenderer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

2679
### off('periodReach') <sup>8+</sup>
2680

2681
off(type: 'periodReach'): void
2682 2683 2684

Unsubscribes from period reached events.

W
wusongqing 已提交
2685
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2686

W
wusongqing 已提交
2687
**Parameters**
2688

W
wusongqing 已提交
2689 2690 2691
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
2692

W
wusongqing 已提交
2693
**Example**
2694 2695 2696 2697

```
audioRenderer.off('periodReach')
```
V
Vaidegi B 已提交
2698

2699
### on('stateChange') <sup>8+</sup>
V
Vaidegi B 已提交
2700

2701
on(type: 'stateChange', callback: Callback<AudioState\>): void
V
Vaidegi B 已提交
2702

2703
Subscribes to state change events.
V
Vaidegi B 已提交
2704

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

W
wusongqing 已提交
2707
**Parameters**
2708

W
wusongqing 已提交
2709 2710 2711 2712
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | Yes  | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
2713

W
wusongqing 已提交
2714
**Example**
2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725

```
audioRenderer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio renderer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio renderer state is: STATE_RUNNING");
    }
});
```
V
Vaidegi B 已提交
2726

2727
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2728

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

W
wusongqing 已提交
2731
### Attributes
V
Vaidegi B 已提交
2732

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

W
wusongqing 已提交
2735 2736 2737
| Name | Type                    | Readable| Writable| Description            |
| :---- | :------------------------- | :--- | :--- | :--------------- |
| state<sup>8+</sup>  | [AudioState](#audiostate8) | Yes| No  | Audio capturer state.|
V
Vaidegi B 已提交
2738

W
wusongqing 已提交
2739
**Example**
V
Vaidegi B 已提交
2740 2741

```
2742
var state = audioCapturer.state;
V
Vaidegi B 已提交
2743 2744
```

2745
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2746

2747
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
V
Vaidegi B 已提交
2748

W
wusongqing 已提交
2749
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2750

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

W
wusongqing 已提交
2753
**Parameters**
V
Vaidegi B 已提交
2754

W
wusongqing 已提交
2755 2756 2757
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
V
Vaidegi B 已提交
2758

W
wusongqing 已提交
2759
**Example**
V
Vaidegi B 已提交
2760 2761

```
2762
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2763
    if (err) {
2764
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2765
    } else {
2766 2767 2768
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2769
    }
2770
});
V
Vaidegi B 已提交
2771 2772 2773
```


2774
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2775

2776
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2777

W
wusongqing 已提交
2778
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2779

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

W
wusongqing 已提交
2782
**Return value**
V
Vaidegi B 已提交
2783

W
wusongqing 已提交
2784 2785 2786
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
V
Vaidegi B 已提交
2787

W
wusongqing 已提交
2788
**Example**
V
Vaidegi B 已提交
2789 2790

```
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801
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.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
2802
});
2803
```
V
Vaidegi B 已提交
2804

2805
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2806

2807
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
V
Vaidegi B 已提交
2808

W
wusongqing 已提交
2809
Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2810

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

W
wusongqing 已提交
2813
**Parameters**
V
Vaidegi B 已提交
2814

W
wusongqing 已提交
2815 2816 2817
| Name  | Type                                                | Mandatory| Description                            |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes  | Callback used to return the stream information.|
V
Vaidegi B 已提交
2818

W
wusongqing 已提交
2819
**Example**
V
Vaidegi B 已提交
2820 2821

```
2822
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2823
    if (err) {
2824
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2825
    } else {
2826 2827 2828 2829 2830
        console.log('Capturer GetStreamInfo:');
        console.log('Capturer sampling rate:' + streamInfo.samplingRate);
        console.log('Capturer channel:' + streamInfo.channels);
        console.log('Capturer format:' + streamInfo.sampleFormat);
        console.log('Capturer encoding type:' + streamInfo.encodingType);
V
Vaidegi B 已提交
2831
    }
2832
});
V
Vaidegi B 已提交
2833 2834
```

2835
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2836

2837
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2838

W
wusongqing 已提交
2839
Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2840

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

W
wusongqing 已提交
2843
**Return value**
V
Vaidegi B 已提交
2844

W
wusongqing 已提交
2845 2846 2847
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2848

W
wusongqing 已提交
2849
**Example**
V
Vaidegi B 已提交
2850 2851

```
2852 2853 2854 2855 2856 2857 2858 2859
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.log('getStreamInfo :ERROR: ' + err.message);
2860
});
V
Vaidegi B 已提交
2861 2862
```

2863
### start<sup>8+</sup>
V
Vaidegi B 已提交
2864

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

2867
Starts capturing. This API uses an asynchronous callback to return the result.
2868

W
wusongqing 已提交
2869
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2870

W
wusongqing 已提交
2871
**Parameters**
2872

W
wusongqing 已提交
2873 2874 2875
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2876

W
wusongqing 已提交
2877
**Example**
2878 2879

```
2880
audioCapturer.start((err) => {
2881 2882 2883 2884 2885
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2886
});
2887 2888 2889
```


2890
### start<sup>8+</sup>
2891

2892
start(): Promise<void\>
2893

2894
Starts capturing. This API uses a promise to return the result.
2895

W
wusongqing 已提交
2896
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2897

W
wusongqing 已提交
2898
**Return value**
2899

W
wusongqing 已提交
2900 2901 2902
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2903

W
wusongqing 已提交
2904
**Example**
2905 2906 2907

```
audioCapturer.start().then(() => {
2908 2909 2910 2911 2912 2913 2914 2915 2916 2917
    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)) {
        stateFlag = true;
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
    stateFlag=false;
2918 2919 2920
});
```

2921
### stop<sup>8+</sup>
2922

2923
stop(callback: AsyncCallback<void\>): void
2924

2925
Stops capturing. This API uses an asynchronous callback to return the result.
2926

W
wusongqing 已提交
2927
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2928

W
wusongqing 已提交
2929
**Parameters**
2930

W
wusongqing 已提交
2931 2932 2933
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2934

W
wusongqing 已提交
2935
**Example**
2936 2937

```
2938
audioCapturer.stop((err) => {
2939 2940 2941 2942 2943
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
2944
});
2945 2946 2947
```


2948
### stop<sup>8+</sup>
2949

2950
stop(): Promise<void\>
2951

2952
Stops capturing. This API uses a promise to return the result.
2953

W
wusongqing 已提交
2954
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2955

W
wusongqing 已提交
2956
**Return value**
2957

W
wusongqing 已提交
2958 2959 2960
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2961

W
wusongqing 已提交
2962
**Example**
2963 2964 2965

```
audioCapturer.stop().then(() => {
2966 2967
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
W
wusongqing 已提交
2968
    if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
2969 2970 2971 2972 2973 2974
        stateFlag=true;
        console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false;
2975 2976 2977
});
```

2978
### release<sup>8+</sup>
2979

2980
release(callback: AsyncCallback<void\>): void
2981

W
wusongqing 已提交
2982
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
2983

W
wusongqing 已提交
2984
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2985

W
wusongqing 已提交
2986
**Parameters**
2987

W
wusongqing 已提交
2988 2989 2990
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
2991

W
wusongqing 已提交
2992
**Example**
2993 2994

```
2995
audioCapturer.release((err) => {
2996 2997 2998 2999 3000
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
3001
});
3002 3003 3004
```


3005
### release<sup>8+</sup>
3006

3007
release(): Promise<void\>
3008

W
wusongqing 已提交
3009
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
3010

W
wusongqing 已提交
3011
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3012

W
wusongqing 已提交
3013
**Return value**
3014

W
wusongqing 已提交
3015 3016 3017
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3018

W
wusongqing 已提交
3019
**Example**
3020 3021 3022

```
audioCapturer.release().then(() => {
3023 3024 3025 3026 3027 3028 3029 3030
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    stateFlag=true;
    console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
    stateFlag=false
3031 3032 3033 3034
});
```


3035
### read<sup>8+</sup>
3036

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

W
wusongqing 已提交
3039
Reads the buffer. This API uses an asynchronous callback to return the result.
3040

W
wusongqing 已提交
3041
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3042

W
wusongqing 已提交
3043
**Parameters**
3044

W
wusongqing 已提交
3045 3046 3047 3048 3049
| 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.|
3050

W
wusongqing 已提交
3051
**Example**
3052 3053 3054 3055 3056 3057 3058 3059 3060 3061

```
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
};
```


3062
### read<sup>8+</sup>
3063

3064
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
3065

W
wusongqing 已提交
3066
Reads the buffer. This API uses a promise to return the result.
3067

W
wusongqing 已提交
3068
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3069

W
wusongqing 已提交
3070
**Parameters**
3071

W
wusongqing 已提交
3072 3073 3074 3075
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3076

W
wusongqing 已提交
3077
**Return value**
3078

W
wusongqing 已提交
3079 3080 3081
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3082

W
wusongqing 已提交
3083
**Example**
3084 3085

```
3086 3087 3088 3089
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3090 3091 3092 3093
});
```


3094
### getAudioTime<sup>8+</sup>
3095

3096
getAudioTime(callback: AsyncCallback<number\>): void
3097

W
wusongqing 已提交
3098
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
3099

W
wusongqing 已提交
3100
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3101

W
wusongqing 已提交
3102
**Parameters**
3103

W
wusongqing 已提交
3104 3105 3106
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3107

W
wusongqing 已提交
3108
**Example**
3109 3110

```
3111
audioCapturer.getAudioTime((err, timestamp) => {
3112
    console.log('Current timestamp: ' + timestamp);
3113
});
3114 3115 3116
```


3117
### getAudioTime<sup>8+</sup>
3118

3119
getAudioTime(): Promise<number\>
3120

W
wusongqing 已提交
3121
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
3122

W
wusongqing 已提交
3123
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3124

W
wusongqing 已提交
3125
**Return value**
3126

W
wusongqing 已提交
3127 3128 3129
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3130

W
wusongqing 已提交
3131
**Example**
3132 3133 3134

```
audioCapturer.getAudioTime().then((audioTime) => {
3135 3136 3137
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3138 3139 3140 3141
});
```


3142
### getBufferSize<sup>8+</sup>
3143

3144
getBufferSize(callback: AsyncCallback<number\>): void
3145

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

W
wusongqing 已提交
3148
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3149

W
wusongqing 已提交
3150
**Parameters**
3151

W
wusongqing 已提交
3152 3153 3154
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3155

W
wusongqing 已提交
3156
**Example**
3157 3158

```
3159
audioCapturer.getBufferSize((err, bufferSize) => {
3160 3161
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3162 3163 3164 3165 3166
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3167 3168 3169 3170
    }
});
```

W
wusongqing 已提交
3171

3172
### getBufferSize<sup>8+</sup>
3173

3174
getBufferSize(): Promise<number\>
3175

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

W
wusongqing 已提交
3178
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3179

W
wusongqing 已提交
3180
**Return value**
3181

W
wusongqing 已提交
3182 3183 3184
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3185

W
wusongqing 已提交
3186
**Example**
3187 3188

```
W
wusongqing 已提交
3189 3190 3191 3192 3193 3194
await audioCapturer.getBufferSize().then(async function (bufferSize) {
    console.info('AudioFrameworkRecordLog: getBufferSize :SUCCESS '+ bufferSize);
    var buffer = await audioCapturer.read(bufferSize, true);
    console.info('Buffer read is ' + buffer );
    }).catch((err) => {
    console.info('AudioFrameworkRecordLog: getBufferSize :ERROR : '+err.message);
3195 3196 3197
});
```

W
wusongqing 已提交
3198

3199
### on('markReach')<sup>8+</sup>
3200

3201
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
3202

W
wusongqing 已提交
3203
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
3204

W
wusongqing 已提交
3205
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3206

W
wusongqing 已提交
3207
**Parameters**
3208

W
wusongqing 已提交
3209 3210 3211 3212 3213
| Name  | Type                   | Mandatory| Description                                      |
| :------- | :---------------------- | :--- | :----------------------------------------- |
| type     | string                  | Yes  | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame    | number                  | Yes  | Number of frames to trigger the event. The value must be greater than **0**.          |
| callback | position: number) => {} | Yes  | Callback invoked when the event is triggered.|
3214

W
wusongqing 已提交
3215
**Example**
3216 3217 3218 3219 3220 3221 3222 3223 3224

```
audioCapturer.on('markReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

3225
### off('markReach')<sup>8+</sup>
3226

3227
off(type: 'markReach'): void
3228

W
wusongqing 已提交
3229
Unsubscribes from mark reached events.
3230

W
wusongqing 已提交
3231
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3232

W
wusongqing 已提交
3233
**Parameters**
3234

W
wusongqing 已提交
3235 3236 3237
| Name| Type  | Mandatory| Description                                         |
| :----- | :----- | :--- | :-------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
3238

W
wusongqing 已提交
3239
**Example**
3240 3241 3242 3243 3244

```
audioCapturer.off('markReach');
```

3245
### on('periodReach')<sup>8+</sup>
3246

3247
on(type: "periodReach", frame: number, callback: (position: number) => {}): void
3248

W
wusongqing 已提交
3249
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3250

W
wusongqing 已提交
3251
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3252

W
wusongqing 已提交
3253
**Parameters**
3254

W
wusongqing 已提交
3255 3256 3257
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
| type     | string                   | Yes  | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
W
wusongqing 已提交
3258
| frame    | number                   | Yes  | Period during which frame capturing is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3259
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3260

W
wusongqing 已提交
3261
**Example**
3262 3263 3264 3265 3266 3267 3268 3269 3270

```
audioCapturer.on('periodReach', 1000, (position) => {
    if (position == "1000") {
        console.log('ON Triggered successfully');
    }
});
```

3271
### off('periodReach')<sup>8+</sup>
3272

3273
off(type: 'periodReach'): void
3274 3275 3276

Unsubscribes from period reached events.

W
wusongqing 已提交
3277
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3278

W
wusongqing 已提交
3279
**Parameters**
3280

W
wusongqing 已提交
3281 3282 3283
| Name| Type  | Mandatory| Description                                           |
| :----- | :----- | :--- | :---------------------------------------------- |
| type   | string | Yes  | Type of event to unsubscribe from. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
3284

W
wusongqing 已提交
3285
**Example**
3286 3287 3288 3289 3290 3291 3292 3293

```
audioCapturer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

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

3295
Subscribes to state change events.
3296

W
wusongqing 已提交
3297
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3298

W
wusongqing 已提交
3299
**Parameters**
3300

W
wusongqing 已提交
3301 3302 3303 3304
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
| type     | string                     | Yes  | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
3305

W
wusongqing 已提交
3306
**Example**
3307 3308

```
3309 3310 3311 3312 3313 3314 3315 3316
audioCapturer.on('stateChange', (state) => {
    if (state == 1) {
        console.log("audio capturer state is: STATE_PREPARED");
    }
    if (state == 2) {
        console.log("audio capturer state is: STATE_RUNNING");
    }
});
3317
```