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

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

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

W
wusongqing 已提交
7 8 9
- [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
10

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

15
## Modules to Import
W
wusongqing 已提交
16 17 18 19 20

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

W
wusongqing 已提交
21

22
## audio.getAudioManager
V
Vaidegi B 已提交
23

24
getAudioManager(): AudioManager
25

26
Obtains an **AudioManager** instance.
W
wusongqing 已提交
27

W
wusongqing 已提交
28
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
29

W
wusongqing 已提交
30 31 32 33
**Return value**
| Type                         | Description        |
| ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | **AudioManager** instance.|
W
wusongqing 已提交
34

W
wusongqing 已提交
35
**Example**
W
wusongqing 已提交
36 37 38 39
```
var audioManager = audio.getAudioManager();
```

40
## audio.createAudioRenderer<sup>8+</sup>
41

42
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
43

W
wusongqing 已提交
44 45 46
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.

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

W
wusongqing 已提交
48
**Parameters**
49

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

W
wusongqing 已提交
55
**Example**
56 57

```
58
import audio from '@ohos.multimedia.audio';
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
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) {
79
        console.error(`AudioRenderer Created : Error: ${err.message}`);
80 81
    }
    else {
82 83
        console.info('AudioRenderer Created : Success : SUCCESS');
        let audioRenderer = data;
84 85 86
    }
});
```
W
wusongqing 已提交
87

88
## audio.createAudioRenderer<sup>8+</sup>
89

W
wusongqing 已提交
90 91 92
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>

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

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

W
wusongqing 已提交
96
**Parameters**
97

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

W
wusongqing 已提交
102
**Return value**
V
Vaidegi B 已提交
103

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

W
wusongqing 已提交
108
**Example**
V
Vaidegi B 已提交
109 110

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

113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
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
}

131 132 133 134 135 136 137
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 已提交
138 139
```

140
## audio.createAudioCapturer<sup>8+</sup>
141

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

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

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

W
wusongqing 已提交
148
**Parameters**
V
Vaidegi B 已提交
149

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

**Example**
156 157

```
158
import audio from '@ohos.multimedia.audio';
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
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');
182
        let audioCapturer = data;
183 184 185 186
    }
});
```

187
## audio.createAudioCapturer<sup>8+</sup>
188

189
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
190

W
wusongqing 已提交
191 192 193
Obtains an **AudioCapturer** instance. This API uses a promise to return the result.

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

W
wusongqing 已提交
195
**Parameters**
196

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

W
wusongqing 已提交
201
**Return value**
V
Vaidegi B 已提交
202

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

W
wusongqing 已提交
207
**Example**
V
Vaidegi B 已提交
208 209

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

212 213 214 215 216 217 218 219 220 221 222 223 224
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 = {
225 226
    streamInfo: audioStreamInfo,
    capturerInfo: audioCapturerInfo
227
}
V
Vaidegi B 已提交
228

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

238
## AudioVolumeType
W
wusongqing 已提交
239

W
wusongqing 已提交
240
Enumerates the audio stream types.
W
wusongqing 已提交
241

W
wusongqing 已提交
242 243 244 245 246 247 248 249
**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 已提交
250

V
Vaidegi B 已提交
251

W
wusongqing 已提交
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      |
| ---------------------------- | ------ | ---------- |
260
| SHARE_MODE      | 0      | Shared mode.|
W
wusongqing 已提交
261 262
| INDEPENDENT_MODE| 1      | Independent mode.    |

263
## DeviceFlag
W
wusongqing 已提交
264

W
wusongqing 已提交
265
Enumerates the audio device flags.
W
wusongqing 已提交
266

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

W
wusongqing 已提交
269 270 271 272 273
| 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 已提交
274

275 276

## DeviceRole
W
wusongqing 已提交
277

W
wusongqing 已提交
278 279 280
Enumerates the audio device roles.

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

W
wusongqing 已提交
282 283 284 285
| Name         | Default Value| Description          |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
286

V
Vaidegi B 已提交
287

288
## DeviceType
W
wusongqing 已提交
289

W
wusongqing 已提交
290
Enumerates the audio device types.
W
wusongqing 已提交
291

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

W
wusongqing 已提交
294 295 296 297 298 299 300 301 302 303 304
| 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 已提交
305

W
wusongqing 已提交
306
## ActiveDeviceType
V
Vaidegi B 已提交
307

W
wusongqing 已提交
308 309
Enumerates the active device types.

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

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

## AudioRingMode
W
wusongqing 已提交
318

W
wusongqing 已提交
319
Enumerates the ringer modes.
W
wusongqing 已提交
320

W
wusongqing 已提交
321
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
322

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

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

W
wusongqing 已提交
331
Enumerate the audio sample formats.
V
Vaidegi B 已提交
332

W
wusongqing 已提交
333
**System capability**: SystemCapability.Multimedia.Audio.Core
334

W
wusongqing 已提交
335 336 337 338 339 340 341
| 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.|
342 343

## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
344 345 346

Enumerates the audio channels.

W
wusongqing 已提交
347
**System capability**: SystemCapability.Multimedia.Audio.Core
348

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

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
355 356 357

Enumerates the audio sampling rates.

W
wusongqing 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
**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.|
373 374 375

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

V
Vaidegi B 已提交
376 377
Enumerates the audio encoding types.

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

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

385 386
## ContentType

W
wusongqing 已提交
387
Enumerates the audio content types.
388

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

W
wusongqing 已提交
391 392 393 394 395 396 397 398
| 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 已提交
399

400 401
## StreamUsage

W
wusongqing 已提交
402
Enumerates the audio stream usage.
V
Vaidegi B 已提交
403

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

W
wusongqing 已提交
406 407 408 409 410 411
| 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 已提交
412

413 414
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
415 416
Enumerates the audio states.

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

W
wusongqing 已提交
419 420 421 422 423 424 425 426 427
| 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 已提交
428

429 430
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
431 432
Enumerates the audio renderer rates.

W
wusongqing 已提交
433
**System capability**: SystemCapability.Multimedia.Audio.Renderer
434

W
wusongqing 已提交
435 436 437 438 439
| 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 已提交
440

441
## InterruptType
V
Vaidegi B 已提交
442

W
wusongqing 已提交
443
Enumerates the audio interruption types.
V
Vaidegi B 已提交
444

W
wusongqing 已提交
445
**System capability**: SystemCapability.Multimedia.Audio.Renderer
446

W
wusongqing 已提交
447 448 449 450
| Name                | Default Value| Description                  |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|
451 452

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

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

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

W
wusongqing 已提交
458 459 460 461
| 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.|
462 463

## InterruptHint
V
Vaidegi B 已提交
464

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

W
wusongqing 已提交
467
**System capability**: SystemCapability.Multimedia.Audio.Renderer
468

W
wusongqing 已提交
469 470 471 472 473 474 475 476
| 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.                              |
477 478 479

## InterruptActionType

W
wusongqing 已提交
480
Enumerates the returned event types for audio interruption events.
481

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

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

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

491
Describes audio stream information.
V
Vaidegi B 已提交
492

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

W
wusongqing 已提交
495 496 497 498 499 500
| 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.    |
501 502

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
503 504 505

Describes audio renderer information.

W
wusongqing 已提交
506
**System capability**: SystemCapability.Multimedia.Audio.Core
507

W
wusongqing 已提交
508 509 510 511 512
| 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 已提交
513

514
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
515

W
wusongqing 已提交
516
Describes audio renderer configurations.
517

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

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

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

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

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

W
wusongqing 已提交
531 532 533 534 535
| 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 已提交
536

W
wusongqing 已提交
537
## AudioInterrupt
G
Geevarghese V K 已提交
538

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

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

W
wusongqing 已提交
543 544 545 546 547
| 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 已提交
548

W
wusongqing 已提交
549
## InterruptAction
550

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

W
wusongqing 已提交
553
**System capability**: SystemCapability.Multimedia.Audio.Renderer
554

W
wusongqing 已提交
555 556 557 558
| 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 已提交
559
| hint       | [InterruptHint](#interrupthint)              | No  | Hint provided along with the audio interruption event.                                              |
W
wusongqing 已提交
560
| 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 已提交
561

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

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

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

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

W
wusongqing 已提交
570 571 572 573 574
| 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.                                    |
575

W
wusongqing 已提交
576
## DeviceChangeAction
577

W
wusongqing 已提交
578
Describes the device connection status and device information.
579

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

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

W
wusongqing 已提交
587
## DeviceChangeType
588

W
wusongqing 已提交
589
Enumerates the device connection statuses.
V
Vaidegi B 已提交
590

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

W
wusongqing 已提交
593 594 595 596
| Name      | Default Value| Description          |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
597

W
wusongqing 已提交
598
## AudioCapturerOptions<sup>8+</sup>
599

W
wusongqing 已提交
600
Describes audio capturer configurations.
601

W
wusongqing 已提交
602
**System capability**: SystemCapability.Multimedia.Audio.Capturer
603

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

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

W
wusongqing 已提交
611
Describes audio capturer information.
612

W
wusongqing 已提交
613
**System capability**: SystemCapability.Multimedia.Audio.Core
614

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

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

W
wusongqing 已提交
622
Enumerates the audio source types.
623

W
wusongqing 已提交
624
**System capability**: SystemCapability.Multimedia.Audio.Core
625

W
wusongqing 已提交
626 627 628 629 630
| 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.|
631 632

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

W
wusongqing 已提交
634
Enumerates the audio scenes.
635

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

W
wusongqing 已提交
638 639 640 641 642 643
| 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 已提交
644

645
## AudioManager
W
wusongqing 已提交
646

W
wusongqing 已提交
647
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 已提交
648

649 650
### setVolume

W
wusongqing 已提交
651
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
652 653 654

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

655 656
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

W
wusongqing 已提交
659
**Parameters**
660

W
wusongqing 已提交
661 662 663 664
| 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 已提交
665
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
666

W
wusongqing 已提交
667
**Example**
W
wusongqing 已提交
668 669

```
670 671 672 673 674 675
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.');
676
});
W
wusongqing 已提交
677
```
W
wusongqing 已提交
678

679
### setVolume
W
wusongqing 已提交
680

W
wusongqing 已提交
681
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
682 683 684

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

685 686
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

W
wusongqing 已提交
689
**Parameters**
690

W
wusongqing 已提交
691 692 693 694
| 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**.|
695

W
wusongqing 已提交
696
**Return value**
697

W
wusongqing 已提交
698 699 700
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
701

W
wusongqing 已提交
702
**Example**
W
wusongqing 已提交
703 704

```
705
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
W
wusongqing 已提交
706
    console.log('Promise returned to indicate a successful volume setting.');
707 708 709 710
});
```

### getVolume
W
wusongqing 已提交
711

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

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

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

W
wusongqing 已提交
718
**Parameters**
719

W
wusongqing 已提交
720 721 722 723
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the volume.|
724

W
wusongqing 已提交
725
**Example**
W
wusongqing 已提交
726 727 728 729

```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
730 731
       console.error('Failed to obtain the volume. ${err.message}');
       return;
W
wusongqing 已提交
732 733
   }
   console.log('Callback invoked to indicate that the volume is obtained.');
734
});
W
wusongqing 已提交
735 736
```

737
### getVolume
V
Vaidegi B 已提交
738

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

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

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

W
wusongqing 已提交
745
**Parameters**
W
wusongqing 已提交
746

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

W
wusongqing 已提交
751
**Return value**
752

W
wusongqing 已提交
753 754 755
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the volume.|
W
wusongqing 已提交
756

W
wusongqing 已提交
757
**Example**
W
wusongqing 已提交
758 759

```
760
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
761
    console.log('Promise returned to indicate that the volume is obtained.' + value);
762 763 764 765 766
});
```

### getMinVolume

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

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

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

W
wusongqing 已提交
773
**Parameters**
W
wusongqing 已提交
774

W
wusongqing 已提交
775 776 777 778
| Name    | Type                               | Mandatory| Description              |
| ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.      |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the minimum volume.|
779

W
wusongqing 已提交
780
**Example**
W
wusongqing 已提交
781 782 783 784 785

```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the minimum volume. ${err.message}');
786
        return;
W
wusongqing 已提交
787 788
    }
    console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
789
});
W
wusongqing 已提交
790 791
```

792
### getMinVolume
V
Vaidegi B 已提交
793

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

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

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

W
wusongqing 已提交
800
**Parameters**
801

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

W
wusongqing 已提交
806
**Return value**
W
wusongqing 已提交
807

W
wusongqing 已提交
808 809 810
| Type                 | Description                     |
| --------------------- | ------------------------- |
| Promise&lt;number&gt; | Promise used to return the minimum volume.|
W
wusongqing 已提交
811

W
wusongqing 已提交
812
**Example**
813 814 815 816 817 818 819 820 821

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

### getMaxVolume

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

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

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

W
wusongqing 已提交
828
**Parameters**
829

W
wusongqing 已提交
830 831 832 833
| Name    | Type                               | Mandatory| Description                  |
| ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.          |
| callback   | AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the maximum volume.|
834

W
wusongqing 已提交
835
**Example**
W
wusongqing 已提交
836 837 838 839 840 841 842 843

```
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);
844
});
W
wusongqing 已提交
845 846
```

847
### getMaxVolume
V
Vaidegi B 已提交
848

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

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

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

W
wusongqing 已提交
855
**Parameters**
W
wusongqing 已提交
856

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

W
wusongqing 已提交
861
**Return value**
862

W
wusongqing 已提交
863 864 865
| Type                 | Description                         |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise used to return the maximum volume.|
W
wusongqing 已提交
866

W
wusongqing 已提交
867
**Example**
W
wusongqing 已提交
868 869

```
870
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
W
wusongqing 已提交
871
    console.log('Promised returned to indicate that the maximum volume is obtained.');
872
});
W
wusongqing 已提交
873 874
```

875
### mute
V
Vaidegi B 已提交
876

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

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

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

W
wusongqing 已提交
883
**Parameters**
W
wusongqing 已提交
884

W
wusongqing 已提交
885 886 887 888 889
| 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.               |
890

W
wusongqing 已提交
891
**Example**
W
wusongqing 已提交
892 893 894 895 896

```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
    if (err) {
        console.error('Failed to mute the stream. ${err.message}');
897
        return;
W
wusongqing 已提交
898 899
    }
    console.log('Callback invoked to indicate that the stream is muted.');
900
});
W
wusongqing 已提交
901 902
```

903
### mute
V
Vaidegi B 已提交
904

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

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

W
wusongqing 已提交
911
**Parameters**
912

W
wusongqing 已提交
913 914 915 916
| 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.|
917

W
wusongqing 已提交
918
**Return value**
W
wusongqing 已提交
919

W
wusongqing 已提交
920 921 922
| Type               | Description                         |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
923

W
wusongqing 已提交
924
**Example**
925

W
wusongqing 已提交
926 927

```
928
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
W
wusongqing 已提交
929
    console.log('Promise returned to indicate that the stream is muted.');
930
});
W
wusongqing 已提交
931 932
```

V
Vaidegi B 已提交
933

934
### isMute
V
Vaidegi B 已提交
935

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

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

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

W
wusongqing 已提交
942
**Parameters**
W
wusongqing 已提交
943

W
wusongqing 已提交
944 945 946 947
| 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.|
948

W
wusongqing 已提交
949
**Example**
W
wusongqing 已提交
950 951 952 953

```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
   if (err) {
954 955
       console.error('Failed to obtain the mute status. ${err.message}');
       return;
W
wusongqing 已提交
956 957
   }
   console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
958
});
W
wusongqing 已提交
959 960 961
```


962
### isMute
V
Vaidegi B 已提交
963

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

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

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

W
wusongqing 已提交
970
**Parameters**
W
wusongqing 已提交
971

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

W
wusongqing 已提交
976
**Return value**
977

W
wusongqing 已提交
978 979 980
| 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.|
981

W
wusongqing 已提交
982
**Example**
W
wusongqing 已提交
983 984

```
985
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
986
    console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
987
});
W
wusongqing 已提交
988 989
```

990
### isActive
V
Vaidegi B 已提交
991

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

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

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

W
wusongqing 已提交
998
**Parameters**
W
wusongqing 已提交
999

W
wusongqing 已提交
1000 1001 1002 1003
| 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.|
1004

W
wusongqing 已提交
1005
**Example**
W
wusongqing 已提交
1006 1007 1008 1009 1010

```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
    if (err) {
        console.error('Failed to obtain the active status of the stream. ${err.message}');
1011
        return;
W
wusongqing 已提交
1012 1013
    }
    console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
1014
});
W
wusongqing 已提交
1015 1016
```

1017
### isActive
V
Vaidegi B 已提交
1018

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

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

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

W
wusongqing 已提交
1025
**Parameters**
1026

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

W
wusongqing 已提交
1031
**Return value**
1032

W
wusongqing 已提交
1033 1034 1035
| 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.|
1036

W
wusongqing 已提交
1037
**Example**
W
wusongqing 已提交
1038 1039

```
1040
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
W
wusongqing 已提交
1041
    console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
1042
});
W
wusongqing 已提交
1043 1044
```

1045
### setRingerMode
V
Vaidegi B 已提交
1046

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

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

1051 1052
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

W
wusongqing 已提交
1053
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1054

W
wusongqing 已提交
1055
**Parameters**
W
wusongqing 已提交
1056

W
wusongqing 已提交
1057 1058 1059 1060
| Name  | Type                           | Mandatory| Description                    |
| -------- | ------------------------------- | ---- | ------------------------ |
| mode     | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.          |
| callback | AsyncCallback&lt;void&gt;       | Yes  | Callback used to return the result.|
1061

W
wusongqing 已提交
1062
**Example**
W
wusongqing 已提交
1063 1064 1065 1066 1067 1068 1069 1070

```
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.');
1071
});
W
wusongqing 已提交
1072 1073
```

1074
### setRingerMode
V
Vaidegi B 已提交
1075

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

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

1080 1081
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

W
wusongqing 已提交
1082
**System capability**: SystemCapability.Multimedia.Audio.Communication
1083

W
wusongqing 已提交
1084
**Parameters**
W
wusongqing 已提交
1085

W
wusongqing 已提交
1086 1087 1088
| Name| Type                           | Mandatory| Description          |
| ------ | ------------------------------- | ---- | -------------- |
| mode   | [AudioRingMode](#audioringmode) | Yes  | Ringer mode.|
1089

W
wusongqing 已提交
1090
**Return value**
1091

W
wusongqing 已提交
1092 1093 1094
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1095

W
wusongqing 已提交
1096
**Example**
W
wusongqing 已提交
1097 1098

```
1099
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
W
wusongqing 已提交
1100
    console.log('Promise returned to indicate a successful setting of the ringer mode.');
1101
});
W
wusongqing 已提交
1102 1103
```

V
Vaidegi B 已提交
1104

1105
### getRingerMode
V
Vaidegi B 已提交
1106

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

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

W
wusongqing 已提交
1111
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1112

W
wusongqing 已提交
1113
**Parameters**
W
wusongqing 已提交
1114

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

W
wusongqing 已提交
1119
**Example**
W
wusongqing 已提交
1120 1121 1122 1123

```
audioManager.getRingerMode((err, value) => {
   if (err) {
1124 1125
       console.error('Failed to obtain the ringer mode.​ ${err.message}');
       return;
W
wusongqing 已提交
1126 1127
   }
   console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
1128
});
W
wusongqing 已提交
1129 1130
```

V
Vaidegi B 已提交
1131

1132
### getRingerMode
V
Vaidegi B 已提交
1133

W
wusongqing 已提交
1134
getRingerMode(): Promise&lt;AudioRingMode&gt;
W
wusongqing 已提交
1135

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

W
wusongqing 已提交
1138
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1139

W
wusongqing 已提交
1140
**Return value**
W
wusongqing 已提交
1141

W
wusongqing 已提交
1142 1143 1144
| Type                                          | Description                           |
| ---------------------------------------------- | ------------------------------- |
| Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
W
wusongqing 已提交
1145

W
wusongqing 已提交
1146
**Example**
W
wusongqing 已提交
1147 1148

```
1149
audioManager.getRingerMode().then((value) => {
W
wusongqing 已提交
1150
    console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
1151
});
W
wusongqing 已提交
1152 1153
```

1154
### setAudioParameter
V
Vaidegi B 已提交
1155

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

1158 1159
Sets an audio parameter. This API uses an asynchronous callback to return the result.

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

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

W
wusongqing 已提交
1164
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1165

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

W
wusongqing 已提交
1168 1169 1170 1171 1172
| 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 已提交
1173

W
wusongqing 已提交
1174
**Example**
W
wusongqing 已提交
1175 1176

```
1177
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
W
wusongqing 已提交
1178 1179
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
1180
        return;
W
wusongqing 已提交
1181 1182
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
1183
});
W
wusongqing 已提交
1184 1185
```

1186
### setAudioParameter
V
Vaidegi B 已提交
1187

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

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

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

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

W
wusongqing 已提交
1196
**System capability**: SystemCapability.Multimedia.Audio.Core
1197

W
wusongqing 已提交
1198
**Parameters**
W
wusongqing 已提交
1199

W
wusongqing 已提交
1200 1201 1202 1203
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
1204

W
wusongqing 已提交
1205
**Return value**
1206

W
wusongqing 已提交
1207 1208 1209
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1210

W
wusongqing 已提交
1211
**Example**
W
wusongqing 已提交
1212 1213

```
1214
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
W
wusongqing 已提交
1215
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1216
});
W
wusongqing 已提交
1217 1218
```

1219
### getAudioParameter
V
Vaidegi B 已提交
1220

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

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

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

W
wusongqing 已提交
1227
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1228

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

W
wusongqing 已提交
1231 1232 1233 1234
| 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 已提交
1235

W
wusongqing 已提交
1236
**Example**
W
wusongqing 已提交
1237 1238

```
1239
audioManager.getAudioParameter('key_example', (err, value) => {
W
wusongqing 已提交
1240 1241
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1242
        return;
W
wusongqing 已提交
1243 1244
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1245
});
W
wusongqing 已提交
1246 1247
```

1248
### getAudioParameter
V
Vaidegi B 已提交
1249

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

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

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

W
wusongqing 已提交
1256
**System capability**: SystemCapability.Multimedia.Audio.Core
1257

W
wusongqing 已提交
1258
**Parameters**
1259

W
wusongqing 已提交
1260 1261 1262
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1263

W
wusongqing 已提交
1264
**Return value**
W
wusongqing 已提交
1265

W
wusongqing 已提交
1266 1267 1268
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1269

W
wusongqing 已提交
1270
**Example**
W
wusongqing 已提交
1271 1272

```
1273
audioManager.getAudioParameter('key_example').then((value) => {
W
wusongqing 已提交
1274
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1275
});
W
wusongqing 已提交
1276 1277
```

1278 1279
### getDevices

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

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

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

W
wusongqing 已提交
1286
**Parameters**
W
wusongqing 已提交
1287

W
wusongqing 已提交
1288 1289 1290 1291
| 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 已提交
1292

W
wusongqing 已提交
1293
**Example**
W
wusongqing 已提交
1294
```
1295
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1296
   if (err) {
1297 1298
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1299 1300
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1301
});
W
wusongqing 已提交
1302 1303
```

1304
### getDevices
V
Vaidegi B 已提交
1305

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

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

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

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

W
wusongqing 已提交
1314 1315 1316
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
W
wusongqing 已提交
1317

W
wusongqing 已提交
1318
**Return value**
1319

W
wusongqing 已提交
1320 1321 1322
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
W
wusongqing 已提交
1323

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

```
1327
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1328
    console.log('Promise returned to indicate that the device list is obtained.');
1329
});
W
wusongqing 已提交
1330 1331
```

1332
### setDeviceActive
V
Vaidegi B 已提交
1333

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

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

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

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

W
wusongqing 已提交
1342 1343 1344 1345 1346
| 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.|
1347

W
wusongqing 已提交
1348
**Example**
W
wusongqing 已提交
1349 1350

```
W
wusongqing 已提交
1351
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1352 1353
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1354
        return;
W
wusongqing 已提交
1355 1356
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1357
});
W
wusongqing 已提交
1358 1359
```

1360
### setDeviceActive
V
Vaidegi B 已提交
1361

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

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

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

W
wusongqing 已提交
1368
**Parameters**
1369

W
wusongqing 已提交
1370 1371 1372 1373
| 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 已提交
1374

W
wusongqing 已提交
1375
**Return value**
1376

W
wusongqing 已提交
1377 1378 1379
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1380

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

W
wusongqing 已提交
1383 1384

```
W
wusongqing 已提交
1385
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1386
    console.log('Promise returned to indicate that the device is set to the active status.');
1387
});
W
wusongqing 已提交
1388 1389
```

1390
### isDeviceActive
V
Vaidegi B 已提交
1391

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

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

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

W
wusongqing 已提交
1398
**Parameters**
W
wusongqing 已提交
1399

W
wusongqing 已提交
1400 1401 1402 1403
| 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.|
1404

W
wusongqing 已提交
1405
**Example**
W
wusongqing 已提交
1406 1407

```
W
wusongqing 已提交
1408
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1409 1410
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1411
        return;
W
wusongqing 已提交
1412 1413
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1414
});
W
wusongqing 已提交
1415 1416
```

V
Vaidegi B 已提交
1417

1418
### isDeviceActive
V
Vaidegi B 已提交
1419

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

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

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

W
wusongqing 已提交
1426
**Parameters**
1427

W
wusongqing 已提交
1428 1429 1430
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
1431

W
wusongqing 已提交
1432
**Return value**
1433

W
wusongqing 已提交
1434 1435 1436
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1437

W
wusongqing 已提交
1438
**Example**
W
wusongqing 已提交
1439 1440

```
W
wusongqing 已提交
1441
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1442
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1443
});
W
wusongqing 已提交
1444 1445
```

1446
### setMicrophoneMute
V
Vaidegi B 已提交
1447

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

1450 1451
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

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

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

W
wusongqing 已提交
1456
**Parameters**
W
wusongqing 已提交
1457

W
wusongqing 已提交
1458 1459 1460 1461
| 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 已提交
1462

W
wusongqing 已提交
1463
**Example**
W
wusongqing 已提交
1464 1465 1466 1467 1468 1469 1470 1471

```
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.');
1472
});
W
wusongqing 已提交
1473 1474
```

1475
### setMicrophoneMute
V
Vaidegi B 已提交
1476

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

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

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

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

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

W
wusongqing 已提交
1487 1488 1489
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1490

W
wusongqing 已提交
1491
**Return value**
W
wusongqing 已提交
1492

W
wusongqing 已提交
1493 1494 1495
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1496

W
wusongqing 已提交
1497
**Example**
W
wusongqing 已提交
1498 1499

```
1500
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1501
    console.log('Promise returned to indicate that the microphone is muted.');
1502
});
W
wusongqing 已提交
1503 1504
```

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

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

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

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

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

W
wusongqing 已提交
1515
**Parameters**
W
wusongqing 已提交
1516

W
wusongqing 已提交
1517 1518 1519
| 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 已提交
1520

W
wusongqing 已提交
1521
**Example**
W
wusongqing 已提交
1522 1523 1524 1525 1526 1527 1528 1529

```
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);
1530
});
W
wusongqing 已提交
1531 1532
```

1533
### isMicrophoneMute
V
Vaidegi B 已提交
1534

W
wusongqing 已提交
1535 1536 1537
isMicrophoneMute(): Promise&lt;boolean&gt;

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

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

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

W
wusongqing 已提交
1543
**Return value**
1544

W
wusongqing 已提交
1545 1546 1547
| 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 已提交
1548

W
wusongqing 已提交
1549
**Example**
W
wusongqing 已提交
1550 1551 1552


```
1553
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1554
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1555
});
W
wusongqing 已提交
1556 1557
```

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

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

W
wusongqing 已提交
1562
Subscribes to system volume change events.
V
Vaidegi B 已提交
1563

1564
This is a system API and cannot be called by third-party applications.
1565

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

W
wusongqing 已提交
1568
**Parameters**
V
Vaidegi B 已提交
1569

W
wusongqing 已提交
1570 1571
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
1572
| type     | string                                 | Yes  | Event type. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
W
wusongqing 已提交
1573
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
V
Vaidegi B 已提交
1574

W
wusongqing 已提交
1575
**Example**
V
Vaidegi B 已提交
1576 1577 1578 1579 1580 1581

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

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

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

W
wusongqing 已提交
1589
Subscribes to ringer mode change events.
1590

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

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

W
wusongqing 已提交
1595
**Parameters**
V
Vaidegi B 已提交
1596

W
wusongqing 已提交
1597 1598
| Name  | Type                                     | Mandatory| Description                                                        |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
1599
| type     | string                                    | Yes  | Event type. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
W
wusongqing 已提交
1600
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the updated ringer mode.                                                  |
V
Vaidegi B 已提交
1601

W
wusongqing 已提交
1602
**Example**
V
Vaidegi B 已提交
1603 1604 1605 1606

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

1610
### on('deviceChange')
1611

1612
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1613

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

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

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

W
wusongqing 已提交
1620 1621
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
1622
| type     | string                                               | Yes  | Event type. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
W
wusongqing 已提交
1623
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes  | Callback used to return the device update details.                        |
1624

W
wusongqing 已提交
1625
**Example**
1626 1627 1628 1629 1630 1631 1632

```
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);
1633
});
1634 1635
```

1636 1637 1638 1639
### off('deviceChange')

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

W
wusongqing 已提交
1640
Unsubscribes from device change events.
1641

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

W
wusongqing 已提交
1644
**Parameters**
1645

W
wusongqing 已提交
1646 1647
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
1648
| type     | string                                              | Yes  | Event type. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
W
wusongqing 已提交
1649
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | No  | Callback used to return the device update details.                        |
1650

W
wusongqing 已提交
1651
**Example**
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662

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

### on('interrupt')

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

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

W
wusongqing 已提交
1665
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1666

W
wusongqing 已提交
1667
**Parameters**
1668

W
wusongqing 已提交
1669 1670
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
1671
| type      | string                                        | Yes  | Event type. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
W
wusongqing 已提交
1672 1673
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | Yes  | Callback invoked for the audio interruption event.                                      |
1674

W
wusongqing 已提交
1675
**Example**
1676 1677 1678 1679 1680 1681 1682

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
W
wusongqing 已提交
1683
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
    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 已提交
1699
Unsubscribes from audio interruption events.
1700

W
wusongqing 已提交
1701
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1702

W
wusongqing 已提交
1703
**Parameters**
1704

W
wusongqing 已提交
1705 1706
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
1707
| type      | string                                        | Yes  | Event type. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
W
wusongqing 已提交
1708 1709
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1710

W
wusongqing 已提交
1711
**Example**
1712 1713 1714 1715 1716 1717 1718

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
W
wusongqing 已提交
1719
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1720 1721 1722 1723 1724 1725 1726 1727
    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>
1728

1729
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1730

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

1733
This is a system API and cannot be called by third-party applications.
1734

W
wusongqing 已提交
1735
**System capability**: SystemCapability.Multimedia.Audio.Communication
1736

W
wusongqing 已提交
1737
**Parameters**
1738

W
wusongqing 已提交
1739 1740 1741 1742
| 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.|
1743

W
wusongqing 已提交
1744
**Example**
1745 1746 1747 1748 1749 1750 1751 1752

```
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.');
1753
});
1754 1755
```

1756
### setAudioScene<sup>8+</sup>
1757

1758
setAudioScene\(scene: AudioScene\): Promise<void\>
1759

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

1762
This is a system API and cannot be called by third-party applications.
1763

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

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

W
wusongqing 已提交
1768 1769 1770
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1771

W
wusongqing 已提交
1772
**Return value**
1773

W
wusongqing 已提交
1774 1775 1776
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
1777

W
wusongqing 已提交
1778
**Example**
1779 1780

```
W
wusongqing 已提交
1781
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1782 1783 1784 1785 1786 1787
    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');
});
```

1788
### getAudioScene<sup>8+</sup>
1789

1790
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1791

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

W
wusongqing 已提交
1794
**System capability**: SystemCapability.Multimedia.Audio.Communication
1795

W
wusongqing 已提交
1796
**Parameters**
1797

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

W
wusongqing 已提交
1802
**Example**
1803 1804 1805 1806 1807 1808 1809 1810

```
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);
1811
});
1812 1813 1814
```


1815
### getAudioScene<sup>8+</sup>
1816

1817
getAudioScene\(\): Promise<AudioScene\>
1818

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

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

W
wusongqing 已提交
1823
**Return value**
1824

W
wusongqing 已提交
1825 1826 1827
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1828

W
wusongqing 已提交
1829
**Example**
1830 1831 1832 1833 1834 1835

```
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');
1836
});
1837 1838
```

1839
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1840

1841
Describes an audio device.
1842

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

W
wusongqing 已提交
1845 1846 1847 1848
| Name      | Type                   | Readable| Writable| Description      |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes  | No  | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes  | No  | Device type.|
V
Vaidegi B 已提交
1849

1850
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1851

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

W
wusongqing 已提交
1854
**Example**
V
Vaidegi B 已提交
1855

1856 1857
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1858

1859 1860 1861
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1862 1863 1864

}

1865 1866 1867 1868 1869 1870
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 已提交
1871
    if (deviceTypeValue != null && deviceRoleValue != null){
1872
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1873 1874
    }
    else{
1875 1876
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1877
});
V
Vaidegi B 已提交
1878 1879
```

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

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

W
wusongqing 已提交
1884
### Attributes
V
Vaidegi B 已提交
1885

W
wusongqing 已提交
1886
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1887

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

W
wusongqing 已提交
1892
**Example**
V
Vaidegi B 已提交
1893 1894

```
W
wusongqing 已提交
1895
var state = audioRenderer.state;
V
Vaidegi B 已提交
1896 1897
```

1898
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1899

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

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

W
wusongqing 已提交
1904
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1905

W
wusongqing 已提交
1906
**Parameters**
V
Vaidegi B 已提交
1907

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

W
wusongqing 已提交
1912
**Example**
V
Vaidegi B 已提交
1913 1914

```
1915
audioRenderer.getRendererInfo((err, rendererInfo) => {
1916 1917 1918 1919
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1920
});
V
Vaidegi B 已提交
1921 1922
```

1923
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1924

1925
getRendererInfo(): Promise<AudioRendererInfo\>
1926

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

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

W
wusongqing 已提交
1931
**Return value**
V
Vaidegi B 已提交
1932

W
wusongqing 已提交
1933 1934 1935
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
V
Vaidegi B 已提交
1936

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

```
W
wusongqing 已提交
1940
var resultFlag = true;
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950
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 已提交
1951

1952
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1953

1954
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1955

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

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

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

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

W
wusongqing 已提交
1966
**Example**
V
Vaidegi B 已提交
1967 1968

```
1969
audioRenderer.getStreamInfo((err, streamInfo) => {
1970 1971
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1972 1973 1974
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1975
});
V
Vaidegi B 已提交
1976 1977
```

1978
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1979

1980
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1981

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

W
wusongqing 已提交
1984
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1985

W
wusongqing 已提交
1986
**Return value**
V
Vaidegi B 已提交
1987

W
wusongqing 已提交
1988 1989 1990
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
1991

W
wusongqing 已提交
1992
**Example**
V
Vaidegi B 已提交
1993 1994

```
1995 1996 1997 1998 1999 2000 2001 2002 2003
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 已提交
2004 2005
```

2006
### start<sup>8+</sup>
V
Vaidegi B 已提交
2007

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

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

W
wusongqing 已提交
2012
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2013

W
wusongqing 已提交
2014
**Parameters**
V
Vaidegi B 已提交
2015

W
wusongqing 已提交
2016 2017 2018
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2019

W
wusongqing 已提交
2020
**Example**
V
Vaidegi B 已提交
2021 2022

```
2023
audioRenderer.start((err) => {
2024 2025
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
2026
    } else {
2027
        console.info('Renderer start success.');
V
Vaidegi B 已提交
2028
    }
2029
});
V
Vaidegi B 已提交
2030 2031
```

2032
### start<sup>8+</sup>
V
Vaidegi B 已提交
2033

2034
start(): Promise<void\>
V
Vaidegi B 已提交
2035

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

W
wusongqing 已提交
2038
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2039

W
wusongqing 已提交
2040
**Return value**
V
Vaidegi B 已提交
2041

W
wusongqing 已提交
2042 2043 2044
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2045

W
wusongqing 已提交
2046
**Example**
V
Vaidegi B 已提交
2047 2048

```
2049 2050 2051 2052 2053
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2054 2055
```

2056
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2057

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

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

W
wusongqing 已提交
2062
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2063

W
wusongqing 已提交
2064
**Parameters**
V
Vaidegi B 已提交
2065

W
wusongqing 已提交
2066 2067 2068
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2069

W
wusongqing 已提交
2070
**Example**
V
Vaidegi B 已提交
2071 2072

```
2073
audioRenderer.pause((err) => {
2074 2075
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2076
    } else {
2077
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2078
    }
2079
});
V
Vaidegi B 已提交
2080 2081
```

2082
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2083

2084
pause(): Promise\<void>
V
Vaidegi B 已提交
2085

2086
Pauses rendering. This API uses a promise to return the result.
2087

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

W
wusongqing 已提交
2090
**Return value**
V
Vaidegi B 已提交
2091

W
wusongqing 已提交
2092 2093 2094
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2095

W
wusongqing 已提交
2096
**Example**
V
Vaidegi B 已提交
2097 2098

```
2099 2100 2101 2102 2103
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2104 2105
```

2106
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2107

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

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

W
wusongqing 已提交
2112
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2113

W
wusongqing 已提交
2114
**Parameters**
V
Vaidegi B 已提交
2115

W
wusongqing 已提交
2116 2117 2118
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2119

W
wusongqing 已提交
2120
**Example**
V
Vaidegi B 已提交
2121 2122

```
2123
audioRenderer.drain((err) => {
2124 2125
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2126
    } else {
2127
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2128
    }
2129
});
V
Vaidegi B 已提交
2130 2131
```

2132
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2133

2134
drain(): Promise\<void>
V
Vaidegi B 已提交
2135

2136
Drains the playback buffer. This API uses a promise to return the result.
2137

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

W
wusongqing 已提交
2140
**Return value**
V
Vaidegi B 已提交
2141

W
wusongqing 已提交
2142 2143 2144
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2145

W
wusongqing 已提交
2146
**Example**
V
Vaidegi B 已提交
2147 2148

```
2149 2150 2151 2152 2153
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2154 2155
```

2156
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2157

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

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

W
wusongqing 已提交
2162
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2163

W
wusongqing 已提交
2164
**Parameters**
V
Vaidegi B 已提交
2165

W
wusongqing 已提交
2166 2167 2168
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2169

W
wusongqing 已提交
2170
**Example**
V
Vaidegi B 已提交
2171 2172

```
2173
audioRenderer.stop((err) => {
2174 2175
    if (err) {
        console.error('Renderer stop failed');
V
Vaidegi B 已提交
2176
    } else {
2177
        console.log('Renderer stopped.');
V
Vaidegi B 已提交
2178
    }
2179
});
V
Vaidegi B 已提交
2180 2181
```

2182
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2183

2184
stop(): Promise\<void>
V
Vaidegi B 已提交
2185

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

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

W
wusongqing 已提交
2190
**Return value**
V
Vaidegi B 已提交
2191

W
wusongqing 已提交
2192 2193 2194
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2195

W
wusongqing 已提交
2196
**Example**
V
Vaidegi B 已提交
2197 2198

```
2199 2200 2201 2202 2203
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2204 2205
```

2206
### release<sup>8+</sup>
V
Vaidegi B 已提交
2207

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

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

W
wusongqing 已提交
2212
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2213

W
wusongqing 已提交
2214
**Parameters**
V
Vaidegi B 已提交
2215

W
wusongqing 已提交
2216 2217 2218
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2219

W
wusongqing 已提交
2220
**Example**
V
Vaidegi B 已提交
2221 2222

```
2223
audioRenderer.release((err) => {
2224 2225
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2226
    } else {
2227
        console.log('Renderer released.');
V
Vaidegi B 已提交
2228
    }
2229
});
V
Vaidegi B 已提交
2230 2231
```

2232
### release<sup>8+</sup>
V
Vaidegi B 已提交
2233

2234
release(): Promise\<void>
V
Vaidegi B 已提交
2235

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

W
wusongqing 已提交
2238
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2239

W
wusongqing 已提交
2240
**Return value**
V
Vaidegi B 已提交
2241

W
wusongqing 已提交
2242 2243 2244
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2245

W
wusongqing 已提交
2246
**Example**
V
Vaidegi B 已提交
2247 2248

```
2249 2250 2251 2252 2253
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2254 2255
```

2256
### write<sup>8+</sup>
V
Vaidegi B 已提交
2257

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

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

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

W
wusongqing 已提交
2264
**Parameters**
V
Vaidegi B 已提交
2265

W
wusongqing 已提交
2266 2267 2268 2269
| 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 已提交
2270

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

```
2274 2275
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
2276
import featureAbility from '@ohos.ability.featureAbility'
2277

R
rahul 已提交
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312
var audioStreamInfo = {
    samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
    channels: audio.AudioChannel.CHANNEL_2,
    sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
    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
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data)=> {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
    }).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
    });
var bufferSize;
audioRenderer.getBufferSize().then((data)=> {
    console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
    bufferSize = data;
    }).catch((err) => {
    console.info.('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
    });
console.info('Buffer size:'+bufferSize);
var context = featureAbility.getContext();
var path = await context.getCacheDir();
var filePath = path+"/StarWars10s-2C-48000-4SW.wav"
V
Vaidegi B 已提交
2313 2314 2315
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2316
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2317
    if (writtenbytes < 0) {
2318
        console.error('write failed.');
V
Vaidegi B 已提交
2319 2320 2321
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2322
});
V
Vaidegi B 已提交
2323 2324
```

2325
### write<sup>8+</sup>
V
Vaidegi B 已提交
2326

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

2329
Writes the buffer. This API uses a promise to return the result.
2330

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

W
wusongqing 已提交
2333
**Return value**
V
Vaidegi B 已提交
2334

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

W
wusongqing 已提交
2339
**Example**
V
Vaidegi B 已提交
2340 2341

```
2342 2343
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357
import featureAbility from '@ohos.ability.featureAbility'

var audioStreamInfo = {
    samplingRate:audio.AudioSamplingRate.SAMPLE_RATE_48000,
    channels:audio.AudioChannel.CHANNEL_2,
    sampleFormat.audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
    encodingType.audio.AudioEncodingType.ENCODING_TYPE_RAW
}

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

R
rahul 已提交
2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379
var audioRendererOptions = {
    streamInfo: audioStreamInfo,
    rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
    }).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
    });
var bufferSize;
audioRenderer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
    bufferSize = data;
    }).catch((err) => {
    console.info('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
    });
console.info('BufferSize: ' + bufferSize);
var context = featureAbility.getContext();
var path = await context.getCacheDir();
2380
var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2381 2382 2383
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2384 2385 2386 2387 2388 2389 2390 2391 2392
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 已提交
2393 2394
```

2395
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2396

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

W
wusongqing 已提交
2399
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 已提交
2400

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

W
wusongqing 已提交
2403
**Parameters**
V
Vaidegi B 已提交
2404

W
wusongqing 已提交
2405 2406 2407
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
2408

W
wusongqing 已提交
2409
**Example**
V
Vaidegi B 已提交
2410 2411

```
2412
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2413
    console.log('Current timestamp: ' + timestamp);
2414
});
V
Vaidegi B 已提交
2415 2416
```

2417
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2418

2419
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2420

W
wusongqing 已提交
2421
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 已提交
2422

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

W
wusongqing 已提交
2425
**Return value**
V
Vaidegi B 已提交
2426

W
wusongqing 已提交
2427 2428 2429
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
2430

W
wusongqing 已提交
2431
**Example**
V
Vaidegi B 已提交
2432 2433

```
2434 2435 2436 2437 2438
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2439 2440
```

2441
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2442

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

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

W
wusongqing 已提交
2447
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2448

W
wusongqing 已提交
2449
**Parameters**
V
Vaidegi B 已提交
2450

W
wusongqing 已提交
2451 2452 2453
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
2454

W
wusongqing 已提交
2455
**Example**
V
Vaidegi B 已提交
2456 2457

```
W
wusongqing 已提交
2458
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
V
Vaidegi B 已提交
2459 2460 2461
    if (err) {
        console.error('getBufferSize error');
    }
2462
});
V
Vaidegi B 已提交
2463 2464
```

2465
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2466

2467
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2468

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

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

W
wusongqing 已提交
2473
**Return value**
V
Vaidegi B 已提交
2474

W
wusongqing 已提交
2475 2476 2477
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
2478

W
wusongqing 已提交
2479
**Example**
V
Vaidegi B 已提交
2480 2481

```
R
rahul 已提交
2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

var audioStreamInfo = {
    samplingRate:audio.AudioSamplingRate.SAMPLE_RATE_48000,
    channels:audio.AudioChannel.CHANNEL_2,
    sampleFormat.audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
    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
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
    audioRenderer = data;
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
    }).catch((err) => {
    console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
    });
W
wusongqing 已提交
2509
var bufferSize;
R
rahul 已提交
2510 2511
audioRenderer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
W
wusongqing 已提交
2512
    bufferSize=data;
2513
}).catch((err) => {
R
rahul 已提交
2514
    console.info('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
2515
});
V
Vaidegi B 已提交
2516 2517
```

2518
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2519

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

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

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

W
wusongqing 已提交
2526
**Parameters**
2527

W
wusongqing 已提交
2528 2529 2530 2531
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2532

W
wusongqing 已提交
2533
**Example**
V
Vaidegi B 已提交
2534 2535

```
2536
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2537
    if (err) {
2538
        console.error('Failed to set params');
V
Vaidegi B 已提交
2539 2540 2541
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2542
});
V
Vaidegi B 已提交
2543 2544
```

2545
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2546

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

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

W
wusongqing 已提交
2551
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2552

W
wusongqing 已提交
2553
**Parameters**
V
Vaidegi B 已提交
2554

W
wusongqing 已提交
2555 2556 2557
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
V
Vaidegi B 已提交
2558

W
wusongqing 已提交
2559
**Return value**
V
Vaidegi B 已提交
2560

W
wusongqing 已提交
2561 2562 2563
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2564

W
wusongqing 已提交
2565
**Example**
V
Vaidegi B 已提交
2566 2567

```
2568 2569 2570 2571 2572
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2573 2574
```

2575
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2576

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

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

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

W
wusongqing 已提交
2583
**Parameters**
2584

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

W
wusongqing 已提交
2589
**Example**
V
Vaidegi B 已提交
2590 2591

```
2592
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2593
    console.log('getRenderRate: ' + renderrate);
2594
});
V
Vaidegi B 已提交
2595 2596
```

2597
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2598

2599
getRenderRate(): Promise\<AudioRendererRate>
2600

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

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

W
wusongqing 已提交
2605
**Return value**
V
Vaidegi B 已提交
2606

W
wusongqing 已提交
2607 2608 2609
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
2610

W
wusongqing 已提交
2611
**Example**
V
Vaidegi B 已提交
2612 2613

```
2614 2615 2616 2617 2618
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2619
```
W
wusongqing 已提交
2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642
### 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**

```
R
rahul 已提交
2643 2644
const audioManager = audio.getAudioManager();
audioManager.setInterruptMode(audio.InterruptMode.SHARE_MODE).then(() => {
W
wusongqing 已提交
2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
    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 已提交
2662

W
wusongqing 已提交
2663 2664 2665
**Example**

```
R
rahul 已提交
2666 2667
const audioManager = audio.getAudioManager();
audioManager.setInterruptMode(audio.InterruptMode.SHARE_MODE,()=>{
W
wusongqing 已提交
2668 2669 2670
    console.log('Callback returned to indicate a successful volume setting.');
});
```
2671
### on('interrupt')<sup>9+</sup>
V
Vaidegi B 已提交
2672

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

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

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

W
wusongqing 已提交
2679
**Parameters**
V
Vaidegi B 已提交
2680

W
wusongqing 已提交
2681 2682
| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
2683
| type     | string                                       | Yes  | Event type. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.|
W
wusongqing 已提交
2684
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes  | Callback used to return the audio interruption event.                                    |
V
Vaidegi B 已提交
2685

W
wusongqing 已提交
2686
**Example**
V
Vaidegi B 已提交
2687 2688

```
W
wusongqing 已提交
2689 2690 2691
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
V
Vaidegi B 已提交
2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703
    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 已提交
2704
        switch (interruptEvent.hintType) {
V
Vaidegi B 已提交
2705 2706
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
W
wusongqing 已提交
2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719
                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 已提交
2720 2721 2722
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
W
wusongqing 已提交
2723 2724 2725 2726 2727 2728 2729 2730
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
V
Vaidegi B 已提交
2731 2732 2733
                break;
        }
    }
2734
});
V
Vaidegi B 已提交
2735 2736
```

2737
### on('markReach')<sup>8+</sup>
2738

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

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

W
wusongqing 已提交
2743
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2744

W
wusongqing 已提交
2745
**Parameters**
2746

W
wusongqing 已提交
2747 2748
| Name  | Type                    | Mandatory| Description                                     |
| :------- | :----------------------- | :--- | :---------------------------------------- |
2749
| type     | string                   | Yes  | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
W
wusongqing 已提交
2750 2751
| 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.                   |
2752

W
wusongqing 已提交
2753
**Example**
2754 2755 2756

```
audioRenderer.on('markReach', 1000, (position) => {
R
rahul 已提交
2757
    if (position == 1000) {
2758 2759 2760 2761 2762 2763
        console.log('ON Triggered successfully');
    }
});
```


2764
### off('markReach') <sup>8+</sup>
2765

2766
off(type: 'markReach'): void
2767 2768 2769

Unsubscribes from mark reached events.

W
wusongqing 已提交
2770
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2771

W
wusongqing 已提交
2772
**Parameters**
2773

W
wusongqing 已提交
2774 2775
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
2776
| type   | string | Yes  | Event type. The value is fixed at **markReach**.|
2777

W
wusongqing 已提交
2778
**Example**
2779 2780 2781 2782 2783

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

2784
### on('periodReach') <sup>8+</sup>
2785

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

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

W
wusongqing 已提交
2790
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2791

W
wusongqing 已提交
2792
**Parameters**
2793

W
wusongqing 已提交
2794 2795
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
2796
| type     | string                   | Yes  | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
W
wusongqing 已提交
2797 2798
| 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.                     |
2799

W
wusongqing 已提交
2800
**Example**
2801 2802 2803

```
audioRenderer.on('periodReach', 1000, (position) => {
R
rahul 已提交
2804
    if (position == 1000) {
2805 2806 2807 2808 2809
        console.log('ON Triggered successfully');
    }
});
```

2810
### off('periodReach') <sup>8+</sup>
2811

2812
off(type: 'periodReach'): void
2813 2814 2815

Unsubscribes from period reached events.

W
wusongqing 已提交
2816
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2817

W
wusongqing 已提交
2818
**Parameters**
2819

W
wusongqing 已提交
2820 2821
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
2822
| type   | string | Yes  | Event type. The value is fixed at **periodReach**.|
2823

W
wusongqing 已提交
2824
**Example**
2825 2826 2827 2828

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

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

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

2834
Subscribes to state change events.
V
Vaidegi B 已提交
2835

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

W
wusongqing 已提交
2838
**Parameters**
2839

W
wusongqing 已提交
2840 2841
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
2842
| type     | string                     | Yes  | Event type. The value **stateChange** means the state change event.|
W
wusongqing 已提交
2843
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
2844

W
wusongqing 已提交
2845
**Example**
2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856

```
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 已提交
2857

2858
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2859

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

W
wusongqing 已提交
2862
### Attributes
V
Vaidegi B 已提交
2863

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

W
wusongqing 已提交
2866 2867 2868
| Name | Type                    | Readable| Writable| Description            |
| :---- | :------------------------- | :--- | :--- | :--------------- |
| state<sup>8+</sup>  | [AudioState](#audiostate8) | Yes| No  | Audio capturer state.|
V
Vaidegi B 已提交
2869

W
wusongqing 已提交
2870
**Example**
V
Vaidegi B 已提交
2871 2872

```
2873
var state = audioCapturer.state;
V
Vaidegi B 已提交
2874 2875
```

2876
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2877

2878
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
V
Vaidegi B 已提交
2879

W
wusongqing 已提交
2880
Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
V
Vaidegi B 已提交
2881

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

W
wusongqing 已提交
2884
**Parameters**
V
Vaidegi B 已提交
2885

W
wusongqing 已提交
2886 2887 2888
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
V
Vaidegi B 已提交
2889

W
wusongqing 已提交
2890
**Example**
V
Vaidegi B 已提交
2891 2892

```
2893
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2894
    if (err) {
2895
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2896
    } else {
2897 2898 2899
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2900
    }
2901
});
V
Vaidegi B 已提交
2902 2903 2904
```


2905
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2906

2907
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2908

W
wusongqing 已提交
2909
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2910

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

W
wusongqing 已提交
2913
**Return value**
V
Vaidegi B 已提交
2914

W
wusongqing 已提交
2915 2916 2917
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
V
Vaidegi B 已提交
2918

W
wusongqing 已提交
2919
**Example**
V
Vaidegi B 已提交
2920 2921

```
2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932
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);
2933
});
2934
```
V
Vaidegi B 已提交
2935

2936
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2937

2938
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
V
Vaidegi B 已提交
2939

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

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

W
wusongqing 已提交
2944
**Parameters**
V
Vaidegi B 已提交
2945

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

W
wusongqing 已提交
2950
**Example**
V
Vaidegi B 已提交
2951 2952

```
2953
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2954
    if (err) {
2955
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2956
    } else {
2957 2958 2959 2960 2961
        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 已提交
2962
    }
2963
});
V
Vaidegi B 已提交
2964 2965
```

2966
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2967

2968
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2969

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

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

W
wusongqing 已提交
2974
**Return value**
V
Vaidegi B 已提交
2975

W
wusongqing 已提交
2976 2977 2978
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2979

W
wusongqing 已提交
2980
**Example**
V
Vaidegi B 已提交
2981 2982

```
2983 2984 2985 2986 2987 2988 2989 2990
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);
2991
});
V
Vaidegi B 已提交
2992 2993
```

2994
### start<sup>8+</sup>
V
Vaidegi B 已提交
2995

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

2998
Starts capturing. This API uses an asynchronous callback to return the result.
2999

W
wusongqing 已提交
3000
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3001

W
wusongqing 已提交
3002
**Parameters**
3003

W
wusongqing 已提交
3004 3005 3006
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
3007

W
wusongqing 已提交
3008
**Example**
3009 3010

```
3011
audioCapturer.start((err) => {
3012 3013 3014 3015 3016
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
3017
});
3018 3019 3020
```


3021
### start<sup>8+</sup>
3022

3023
start(): Promise<void\>
3024

3025
Starts capturing. This API uses a promise to return the result.
3026

W
wusongqing 已提交
3027
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3028

W
wusongqing 已提交
3029
**Return value**
3030

W
wusongqing 已提交
3031 3032 3033
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3034

W
wusongqing 已提交
3035
**Example**
3036 3037

```
R
rahul 已提交
3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';

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 audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
    audioCapturer = data;
    console.info('AudioFrameworkRecLog: AudioCapturer Created: SUCCESS');
    }).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created: ERROR: '+err.message);
    });
3060
audioCapturer.start().then(() => {
3061
    console.info('AudioFrameworkRecLog: ---------START---------');
R
rahul 已提交
3062 3063 3064
    console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer: STATE: '+audioCapturer.state);
    console.info('AudioFrameworkRecLog: Capturer started: SUCCESS ');
3065
    if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
R
rahul 已提交
3066
        console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
3067 3068 3069 3070
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
    stateFlag=false;
3071 3072 3073
});
```

3074
### stop<sup>8+</sup>
3075

3076
stop(callback: AsyncCallback<void\>): void
3077

3078
Stops capturing. This API uses an asynchronous callback to return the result.
3079

W
wusongqing 已提交
3080
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3081

W
wusongqing 已提交
3082
**Parameters**
3083

W
wusongqing 已提交
3084 3085 3086
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
3087

W
wusongqing 已提交
3088
**Example**
3089 3090

```
3091
audioCapturer.stop((err) => {
3092 3093 3094 3095 3096
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
3097
});
3098 3099 3100
```


3101
### stop<sup>8+</sup>
3102

3103
stop(): Promise<void\>
3104

3105
Stops capturing. This API uses a promise to return the result.
3106

W
wusongqing 已提交
3107
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3108

W
wusongqing 已提交
3109
**Return value**
3110

W
wusongqing 已提交
3111 3112 3113
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3114

W
wusongqing 已提交
3115
**Example**
3116 3117 3118

```
audioCapturer.stop().then(() => {
R
rahul 已提交
3119 3120
    console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
W
wusongqing 已提交
3121
    if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
R
rahul 已提交
3122
        console.info('AudioFrameworkRecLog: State is Stopped': ');
3123 3124
    }
}).catch((err) => {
R
rahul 已提交
3125
    console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
3126 3127 3128
});
```

3129
### release<sup>8+</sup>
3130

3131
release(callback: AsyncCallback<void\>): void
3132

W
wusongqing 已提交
3133
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
3134

W
wusongqing 已提交
3135
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3136

W
wusongqing 已提交
3137
**Parameters**
3138

W
wusongqing 已提交
3139 3140 3141
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
3142

W
wusongqing 已提交
3143
**Example**
3144 3145

```
3146
audioCapturer.release((err) => {
3147 3148 3149 3150 3151
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
3152
});
3153 3154 3155
```


3156
### release<sup>8+</sup>
3157

3158
release(): Promise<void\>
3159

W
wusongqing 已提交
3160
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
3161

W
wusongqing 已提交
3162
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3163

W
wusongqing 已提交
3164
**Return value**
3165

W
wusongqing 已提交
3166 3167 3168
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3169

W
wusongqing 已提交
3170
**Example**
3171 3172 3173

```
audioCapturer.release().then(() => {
3174 3175 3176 3177 3178
    console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
    console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
}).catch((err) => {
R
rahul 已提交
3179
    console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
3180 3181 3182 3183
});
```


3184
### read<sup>8+</sup>
3185

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

W
wusongqing 已提交
3188
Reads the buffer. This API uses an asynchronous callback to return the result.
3189

W
wusongqing 已提交
3190
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3191

W
wusongqing 已提交
3192
**Parameters**
3193

W
wusongqing 已提交
3194 3195 3196 3197 3198
| 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.|
3199

W
wusongqing 已提交
3200
**Example**
3201 3202

```
R
rahul 已提交
3203 3204 3205 3206 3207 3208 3209
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRecLog: getBufferSize: SUCCESS '+data);
    bufferSize = data;
    }).catch((err) => {
    console.info('AudioFrameworkRecLog: getBufferSize: EROOR: '+err.message);
    });
3210 3211 3212 3213
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
J
jiao_yanlin 已提交
3214
});
3215 3216 3217
```


3218
### read<sup>8+</sup>
3219

3220
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
3221

W
wusongqing 已提交
3222
Reads the buffer. This API uses a promise to return the result.
3223

W
wusongqing 已提交
3224
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3225

W
wusongqing 已提交
3226
**Parameters**
3227

W
wusongqing 已提交
3228 3229 3230 3231
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3232

W
wusongqing 已提交
3233
**Return value**
3234

W
wusongqing 已提交
3235 3236 3237
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3238

W
wusongqing 已提交
3239
**Example**
3240 3241

```
R
rahul 已提交
3242 3243 3244 3245 3246 3247 3248 3249
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRecLog: getBufferSize: SUCCESS '+data);
    bufferSize = data;
    }).catch((err) => {
    console.info('AudioFrameworkRecLog: getBufferSize: ERROR '+err.message);
    });
console.info('Buffer size: ' + bufferSize);
3250 3251 3252 3253
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3254 3255 3256 3257
});
```


3258
### getAudioTime<sup>8+</sup>
3259

3260
getAudioTime(callback: AsyncCallback<number\>): void
3261

W
wusongqing 已提交
3262
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
3263

W
wusongqing 已提交
3264
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3265

W
wusongqing 已提交
3266
**Parameters**
3267

W
wusongqing 已提交
3268 3269 3270
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3271

W
wusongqing 已提交
3272
**Example**
3273 3274

```
3275
audioCapturer.getAudioTime((err, timestamp) => {
3276
    console.log('Current timestamp: ' + timestamp);
3277
});
3278 3279 3280
```


3281
### getAudioTime<sup>8+</sup>
3282

3283
getAudioTime(): Promise<number\>
3284

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

W
wusongqing 已提交
3287
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3288

W
wusongqing 已提交
3289
**Return value**
3290

W
wusongqing 已提交
3291 3292 3293
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3294

W
wusongqing 已提交
3295
**Example**
3296 3297 3298

```
audioCapturer.getAudioTime().then((audioTime) => {
3299 3300 3301
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3302 3303 3304 3305
});
```


3306
### getBufferSize<sup>8+</sup>
3307

3308
getBufferSize(callback: AsyncCallback<number\>): void
3309

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

W
wusongqing 已提交
3312
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3313

W
wusongqing 已提交
3314
**Parameters**
3315

W
wusongqing 已提交
3316 3317 3318
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3319

W
wusongqing 已提交
3320
**Example**
3321 3322

```
3323
audioCapturer.getBufferSize((err, bufferSize) => {
3324 3325
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3326 3327 3328 3329 3330
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3331 3332 3333 3334
    }
});
```

W
wusongqing 已提交
3335

3336
### getBufferSize<sup>8+</sup>
3337

3338
getBufferSize(): Promise<number\>
3339

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

W
wusongqing 已提交
3342
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3343

W
wusongqing 已提交
3344
**Return value**
3345

W
wusongqing 已提交
3346 3347 3348
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3349

W
wusongqing 已提交
3350
**Example**
3351 3352

```
R
rahul 已提交
3353 3354 3355 3356 3357 3358
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRecLog: getBufferSize :SUCCESS '+ data);
    bufferSize = data;
}).catch((err) => {
    console.info('AudioFrameworkRecLog: getBufferSize :ERROR : '+ err.message);
3359 3360 3361
});
```

W
wusongqing 已提交
3362

3363
### on('markReach')<sup>8+</sup>
3364

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

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

W
wusongqing 已提交
3369
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3370

W
wusongqing 已提交
3371
**Parameters**
3372

W
wusongqing 已提交
3373 3374
| Name  | Type                   | Mandatory| Description                                      |
| :------- | :---------------------- | :--- | :----------------------------------------- |
3375
| type     | string                  | Yes  | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
W
wusongqing 已提交
3376 3377
| 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.|
3378

W
wusongqing 已提交
3379
**Example**
3380 3381 3382

```
audioCapturer.on('markReach', 1000, (position) => {
R
rahul 已提交
3383
    if (position == 1000) {
3384 3385 3386 3387 3388
        console.log('ON Triggered successfully');
    }
});
```

3389
### off('markReach')<sup>8+</sup>
3390

3391
off(type: 'markReach'): void
3392

W
wusongqing 已提交
3393
Unsubscribes from mark reached events.
3394

W
wusongqing 已提交
3395
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3396

W
wusongqing 已提交
3397
**Parameters**
3398

W
wusongqing 已提交
3399 3400
| Name| Type  | Mandatory| Description                                         |
| :----- | :----- | :--- | :-------------------------------------------- |
3401
| type   | string | Yes  | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
3402

W
wusongqing 已提交
3403
**Example**
3404 3405 3406 3407 3408

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

3409
### on('periodReach')<sup>8+</sup>
3410

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

W
wusongqing 已提交
3413
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3414

W
wusongqing 已提交
3415
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3416

W
wusongqing 已提交
3417
**Parameters**
3418

W
wusongqing 已提交
3419 3420
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
3421
| type     | string                   | Yes  | Event type. 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 已提交
3422
| frame    | number                   | Yes  | Period during which frame capturing is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3423
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3424

W
wusongqing 已提交
3425
**Example**
3426 3427 3428

```
audioCapturer.on('periodReach', 1000, (position) => {
R
rahul 已提交
3429
    if (position == 1000) {
3430 3431 3432 3433 3434
        console.log('ON Triggered successfully');
    }
});
```

3435
### off('periodReach')<sup>8+</sup>
3436

3437
off(type: 'periodReach'): void
3438 3439 3440

Unsubscribes from period reached events.

W
wusongqing 已提交
3441
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3442

W
wusongqing 已提交
3443
**Parameters**
3444

W
wusongqing 已提交
3445 3446
| Name| Type  | Mandatory| Description                                           |
| :----- | :----- | :--- | :---------------------------------------------- |
3447
| type   | string | Yes  | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
3448

W
wusongqing 已提交
3449
**Example**
3450 3451 3452 3453 3454 3455 3456 3457

```
audioCapturer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

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

3459
Subscribes to state change events.
3460

W
wusongqing 已提交
3461
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3462

W
wusongqing 已提交
3463
**Parameters**
3464

W
wusongqing 已提交
3465 3466
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
3467
| type     | string                     | Yes  | Event type. The value **stateChange** means the state change event.|
W
wusongqing 已提交
3468
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
3469

W
wusongqing 已提交
3470
**Example**
3471 3472

```
3473 3474 3475 3476 3477 3478 3479 3480
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");
    }
});
3481
```