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

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

W
wusongqing 已提交
11 12 13 14 15 16
>  **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.
>
>  API version 9 is a canary release for trial use. The APIs of this version may be unstable.

17
## Modules to Import
W
wusongqing 已提交
18 19 20 21 22

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

W
wusongqing 已提交
23

24
## audio.getAudioManager
V
Vaidegi B 已提交
25

26
getAudioManager(): AudioManager
27

28
Obtains an **AudioManager** instance.
W
wusongqing 已提交
29

W
wusongqing 已提交
30
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
31

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

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

42
## audio.createAudioRenderer<sup>8+</sup>
43

44
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
45

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

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

W
wusongqing 已提交
50
**Parameters**
51

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

W
wusongqing 已提交
57
**Example**
58 59

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

90
## audio.createAudioRenderer<sup>8+</sup>
91

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

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

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

W
wusongqing 已提交
98
**Parameters**
99

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

W
wusongqing 已提交
104
**Return value**
V
Vaidegi B 已提交
105

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

W
wusongqing 已提交
110
**Example**
V
Vaidegi B 已提交
111 112

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

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

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

142
## audio.createAudioCapturer<sup>8+</sup>
143

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

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

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

W
wusongqing 已提交
150
**Parameters**
V
Vaidegi B 已提交
151

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

**Example**
158 159

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

189
## audio.createAudioCapturer<sup>8+</sup>
190

191
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
192

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

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

W
wusongqing 已提交
197
**Parameters**
198

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

W
wusongqing 已提交
203
**Return value**
V
Vaidegi B 已提交
204

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

W
wusongqing 已提交
209
**Example**
V
Vaidegi B 已提交
210 211

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

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

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

240
## AudioVolumeType
W
wusongqing 已提交
241

W
wusongqing 已提交
242
Enumerates the audio stream types.
W
wusongqing 已提交
243

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

V
Vaidegi B 已提交
253

254
## DeviceFlag
W
wusongqing 已提交
255

W
wusongqing 已提交
256
Enumerates the audio device flags.
W
wusongqing 已提交
257

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

W
wusongqing 已提交
260 261 262 263 264
| 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 已提交
265

266 267

## DeviceRole
W
wusongqing 已提交
268

W
wusongqing 已提交
269 270 271
Enumerates the audio device roles.

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

W
wusongqing 已提交
273 274 275 276
| Name         | Default Value| Description          |
| ------------- | ------ | -------------- |
| INPUT_DEVICE  | 1      | Input role.|
| OUTPUT_DEVICE | 2      | Output role.|
Z
zengyawen 已提交
277

V
Vaidegi B 已提交
278

279
## DeviceType
W
wusongqing 已提交
280

W
wusongqing 已提交
281
Enumerates the audio device types.
W
wusongqing 已提交
282

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

W
wusongqing 已提交
285 286 287 288 289 290 291 292 293 294 295
| 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 已提交
296

W
wusongqing 已提交
297
## ActiveDeviceType
V
Vaidegi B 已提交
298

W
wusongqing 已提交
299 300
Enumerates the active device types.

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

W
wusongqing 已提交
303 304 305 306
| Name         | Default Value| Description                                                |
| ------------- | ------ | ---------------------------------------------------- |
| SPEAKER       | 2      | Speaker.                                            |
| BLUETOOTH_SCO | 7      | Bluetooth device using the SCO links.|
W
wusongqing 已提交
307 308

## AudioRingMode
W
wusongqing 已提交
309

W
wusongqing 已提交
310
Enumerates the ringer modes.
W
wusongqing 已提交
311

W
wusongqing 已提交
312
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
313

W
wusongqing 已提交
314 315 316 317 318
| Name               | Default Value| Description      |
| ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT  | 0      | Silent mode.|
| RINGER_MODE_VIBRATE | 1      | Vibration mode.|
| RINGER_MODE_NORMAL  | 2      | Normal mode.|
319 320

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

W
wusongqing 已提交
322
Enumerate the audio sample formats.
V
Vaidegi B 已提交
323

W
wusongqing 已提交
324
**System capability**: SystemCapability.Multimedia.Audio.Core
325

W
wusongqing 已提交
326 327 328 329 330 331 332
| 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.|
333 334

## AudioChannel<sup>8+</sup>
V
Vaidegi B 已提交
335 336 337

Enumerates the audio channels.

W
wusongqing 已提交
338
**System capability**: SystemCapability.Multimedia.Audio.Core
339

W
wusongqing 已提交
340 341 342 343
| Name     | Default Value  | Description    |
| --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Dual-channel.|
344 345

## AudioSamplingRate<sup>8+</sup>
V
Vaidegi B 已提交
346 347 348

Enumerates the audio sampling rates.

W
wusongqing 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
**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.|
364 365 366

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

V
Vaidegi B 已提交
367 368
Enumerates the audio encoding types.

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

W
wusongqing 已提交
371 372 373 374
| Name                 | Default Value| Description     |
| --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1     | Invalid.   |
| ENCODING_TYPE_RAW     | 0      | PCM encoding.|
V
Vaidegi B 已提交
375

376 377
## ContentType

W
wusongqing 已提交
378
Enumerates the audio content types.
379

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

W
wusongqing 已提交
382 383 384 385 386 387 388 389
| 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 已提交
390

391 392
## StreamUsage

W
wusongqing 已提交
393
Enumerates the audio stream usage.
394

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

W
wusongqing 已提交
397 398 399 400 401 402
| 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 已提交
403

404 405
## AudioState<sup>8+</sup>

V
Vaidegi B 已提交
406 407
Enumerates the audio states.

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

W
wusongqing 已提交
410 411 412 413 414 415 416 417 418
| 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 已提交
419

420 421
## AudioRendererRate<sup>8+</sup>

V
Vaidegi B 已提交
422 423
Enumerates the audio renderer rates.

W
wusongqing 已提交
424
**System capability**: SystemCapability.Multimedia.Audio.Renderer
425

W
wusongqing 已提交
426 427 428 429 430
| 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 已提交
431

432
## InterruptType
V
Vaidegi B 已提交
433

W
wusongqing 已提交
434 435 436 437 438 439 440 441 442 443
Enumerates the audio interruption types.

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

| Name                | Default Value| Description                  |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1      | Audio interruption started.|
| INTERRUPT_TYPE_END   | 2      | Audio interruption ended.|

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

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

W
wusongqing 已提交
447 448 449 450 451 452
**System capability**: SystemCapability.Multimedia.Audio.Renderer

| 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.|
453 454

## InterruptHint
V
Vaidegi B 已提交
455

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

W
wusongqing 已提交
458
**System capability**: SystemCapability.Multimedia.Audio.Renderer
459

W
wusongqing 已提交
460 461 462 463 464 465 466 467
| 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.                              |
468 469 470

## InterruptActionType

W
wusongqing 已提交
471
Enumerates the returned event types for audio interruption events.
472

W
wusongqing 已提交
473
**System capability**: SystemCapability.Multimedia.Audio.Renderer
474

W
wusongqing 已提交
475 476 477 478
| Name          | Default Value| Description              |
| -------------- | ------ | ------------------ |
| TYPE_ACTIVATED | 0      | Focus gain event.|
| TYPE_INTERRUPT | 1      | Audio interruption event.|
479 480

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

482
Describes audio stream information.
V
Vaidegi B 已提交
483

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

W
wusongqing 已提交
486 487 488 489 490 491
| 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.    |
492 493

## AudioRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
494 495 496

Describes audio renderer information.

W
wusongqing 已提交
497
**System capability**: SystemCapability.Multimedia.Audio.Core
498

W
wusongqing 已提交
499 500 501 502 503
| 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 已提交
504

505
## AudioRendererOptions<sup>8+</sup>
V
Vaidegi B 已提交
506

W
wusongqing 已提交
507
Describes audio renderer configurations.
G
Geevarghese V K 已提交
508

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

W
wusongqing 已提交
511 512 513 514
| Name        | Type                                    | Mandatory| Description            |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)     | Yes  | Audio stream information.|
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes  | Audio renderer information.|
G
Geevarghese V K 已提交
515

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

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

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

W
wusongqing 已提交
522 523 524 525 526
| 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 已提交
527

528
## AudioInterrupt
529

W
wusongqing 已提交
530
Describes input parameters of audio interruption events.
V
Vaidegi B 已提交
531

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

W
wusongqing 已提交
534
| Name           | Type                       | Mandatory| Description                                                        |
535
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
536 537 538
| 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.|
539 540 541

## InterruptAction

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

W
wusongqing 已提交
544
**System capability**: SystemCapability.Multimedia.Audio.Renderer
545

W
wusongqing 已提交
546 547 548 549
| 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 已提交
550
| hint       | [InterruptHint](#interrupthint)              | No  | Hint provided along with the audio interruption event.                                              |
W
wusongqing 已提交
551
| 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.|
552 553

## VolumeEvent<sup>8+</sup>
V
Vaidegi B 已提交
554

W
wusongqing 已提交
555
Describes the event received by the application when the volume is changed.
556

W
wusongqing 已提交
557
This is a system API and cannot be called by third-party applications.
V
Vaidegi B 已提交
558

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

W
wusongqing 已提交
561 562 563 564 565
| 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.                                    |
V
Vaidegi B 已提交
566

567
## DeviceChangeAction
568

W
wusongqing 已提交
569
Describes the device connection status and device information.
570

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

W
wusongqing 已提交
573 574
| Name             | Type                                             | Mandatory| Description              |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
W
wusongqing 已提交
575 576
| type              | [DeviceChangeType](#devicechangetype)             | Yes  | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes  | Device information.        |
577 578

## DeviceChangeType
579

W
wusongqing 已提交
580
Enumerates the device connection statuses.
581

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

W
wusongqing 已提交
584 585 586 587
| Name      | Default Value| Description          |
| :--------- | :----- | :------------- |
| CONNECT    | 0      | Connected.    |
| DISCONNECT | 1      | Disconnected.|
588

W
wusongqing 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
## AudioCapturerOptions<sup>8+</sup>

Describes audio capturer configurations.

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

| Name        | Type                                   | Mandatory| Description            |
| ------------ | --------------------------------------- | ---- | ---------------- |
| streamInfo   | [AudioStreamInfo](#audiostreaminfo8)    | Yes  | Audio stream information.|
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes  | Audio capturer information.|

## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>

Describes audio capturer information.

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

W
wusongqing 已提交
606 607 608 609
| Name         | Type                     | Mandatory| Description            |
| :------------ | :------------------------ | :--- | :--------------- |
| source        | [SourceType](#sourcetype) | Yes  | Audio source type.      |
| capturerFlags | number                    | Yes  | Audio capturer flags.|
610

W
wusongqing 已提交
611 612 613
## SourceType<sup>8+</sup><a name="sourcetype"></a>

Enumerates the audio source types.
614

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

W
wusongqing 已提交
617 618 619 620 621
| 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.|
622 623

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

W
wusongqing 已提交
625
Enumerates the audio scenes.
626

W
wusongqing 已提交
627
**System capability**: SystemCapability.Multimedia.Audio.Communication
628

W
wusongqing 已提交
629 630 631 632 633 634
| 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 已提交
635

636
## AudioManager
W
wusongqing 已提交
637

W
wusongqing 已提交
638
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 已提交
639

640 641
### setVolume

W
wusongqing 已提交
642
setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
643 644 645

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

W
wusongqing 已提交
646 647
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

W
wusongqing 已提交
650
**Parameters**
651

W
wusongqing 已提交
652 653 654 655 656
| Name    | Type                               | Mandatory| Description                                                    |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes  | Audio stream type.                                            |
| volume     | number                              | Yes  | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback   | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result.                                  |
657

W
wusongqing 已提交
658
**Example**
W
wusongqing 已提交
659 660

```
661 662 663 664 665 666
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.');
667
});
W
wusongqing 已提交
668
```
W
wusongqing 已提交
669

670
### setVolume
W
wusongqing 已提交
671

W
wusongqing 已提交
672
setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
673 674 675

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

W
wusongqing 已提交
676 677
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

W
wusongqing 已提交
680
**Parameters**
681

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

W
wusongqing 已提交
687
**Return value**
688

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

W
wusongqing 已提交
693
**Example**
W
wusongqing 已提交
694 695

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

### getVolume
W
wusongqing 已提交
702

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

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

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

W
wusongqing 已提交
709
**Parameters**
710

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

W
wusongqing 已提交
716
**Example**
W
wusongqing 已提交
717 718 719 720

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

728
### getVolume
V
Vaidegi B 已提交
729

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

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

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

W
wusongqing 已提交
736
**Parameters**
W
wusongqing 已提交
737

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

W
wusongqing 已提交
742
**Return value**
743

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

W
wusongqing 已提交
748
**Example**
W
wusongqing 已提交
749 750

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

### getMinVolume

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

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

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

W
wusongqing 已提交
764
**Parameters**
W
wusongqing 已提交
765

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

W
wusongqing 已提交
771
**Example**
W
wusongqing 已提交
772 773 774 775 776

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

783
### getMinVolume
V
Vaidegi B 已提交
784

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

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

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

W
wusongqing 已提交
791
**Parameters**
792

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

W
wusongqing 已提交
797
**Return value**
W
wusongqing 已提交
798

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

W
wusongqing 已提交
803
**Example**
804 805 806 807 808 809 810 811 812

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

### getMaxVolume

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

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

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

W
wusongqing 已提交
819
**Parameters**
820

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

W
wusongqing 已提交
826
**Example**
W
wusongqing 已提交
827 828 829 830 831 832 833 834

```
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);
835
});
W
wusongqing 已提交
836 837
```

838
### getMaxVolume
V
Vaidegi B 已提交
839

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

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

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

W
wusongqing 已提交
846
**Parameters**
W
wusongqing 已提交
847

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

W
wusongqing 已提交
852
**Return value**
853

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

W
wusongqing 已提交
858
**Example**
W
wusongqing 已提交
859 860

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

866
### mute
V
Vaidegi B 已提交
867

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

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

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

W
wusongqing 已提交
874
**Parameters**
W
wusongqing 已提交
875

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

W
wusongqing 已提交
882
**Example**
W
wusongqing 已提交
883 884 885 886 887

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

894
### mute
V
Vaidegi B 已提交
895

W
wusongqing 已提交
896 897 898
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 已提交
899

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

W
wusongqing 已提交
902
**Parameters**
903

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

W
wusongqing 已提交
909
**Return value**
W
wusongqing 已提交
910

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

W
wusongqing 已提交
915
**Example**
916

W
wusongqing 已提交
917 918

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

V
Vaidegi B 已提交
924

925
### isMute
V
Vaidegi B 已提交
926

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

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

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

W
wusongqing 已提交
933
**Parameters**
W
wusongqing 已提交
934

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

W
wusongqing 已提交
940
**Example**
W
wusongqing 已提交
941 942 943 944

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


953
### isMute
V
Vaidegi B 已提交
954

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

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

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

W
wusongqing 已提交
961
**Parameters**
W
wusongqing 已提交
962

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

W
wusongqing 已提交
967
**Return value**
968

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

W
wusongqing 已提交
973
**Example**
W
wusongqing 已提交
974 975

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

981
### isActive
V
Vaidegi B 已提交
982

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

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

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

W
wusongqing 已提交
989
**Parameters**
W
wusongqing 已提交
990

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

W
wusongqing 已提交
996
**Example**
W
wusongqing 已提交
997 998 999 1000 1001

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

1008
### isActive
V
Vaidegi B 已提交
1009

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

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

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

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

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

W
wusongqing 已提交
1022
**Return value**
1023

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

W
wusongqing 已提交
1028
**Example**
W
wusongqing 已提交
1029 1030

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

1036
### setRingerMode
V
Vaidegi B 已提交
1037

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

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

W
wusongqing 已提交
1042 1043
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

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

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

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

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

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

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

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

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

W
wusongqing 已提交
1071 1072
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY

W
wusongqing 已提交
1073
**System capability**: SystemCapability.Multimedia.Audio.Communication
1074

W
wusongqing 已提交
1075
**Parameters**
W
wusongqing 已提交
1076

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

W
wusongqing 已提交
1081
**Return value**
1082

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

W
wusongqing 已提交
1087
**Example**
W
wusongqing 已提交
1088 1089

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

V
Vaidegi B 已提交
1095

1096
### getRingerMode
V
Vaidegi B 已提交
1097

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

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

W
wusongqing 已提交
1102
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1103

W
wusongqing 已提交
1104
**Parameters**
W
wusongqing 已提交
1105

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

W
wusongqing 已提交
1110
**Example**
W
wusongqing 已提交
1111 1112 1113 1114

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

V
Vaidegi B 已提交
1122

1123
### getRingerMode
V
Vaidegi B 已提交
1124

W
wusongqing 已提交
1125
getRingerMode(): Promise&lt;AudioRingMode&gt;
W
wusongqing 已提交
1126

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

W
wusongqing 已提交
1129
**System capability**: SystemCapability.Multimedia.Audio.Communication
W
wusongqing 已提交
1130

W
wusongqing 已提交
1131
**Return value**
W
wusongqing 已提交
1132

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

W
wusongqing 已提交
1137
**Example**
W
wusongqing 已提交
1138 1139

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

1145
### setAudioParameter
V
Vaidegi B 已提交
1146

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

1149 1150
Sets an audio parameter. This API uses an asynchronous callback to return the result.

1151 1152
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 已提交
1153 1154
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

W
wusongqing 已提交
1155
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1156

W
wusongqing 已提交
1157
**Parameters**
W
wusongqing 已提交
1158

W
wusongqing 已提交
1159 1160 1161 1162 1163
| 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 已提交
1164

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

```
1168
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
W
wusongqing 已提交
1169 1170
    if (err) {
        console.error('Failed to set the audio parameter. ${err.message}');
1171
        return;
W
wusongqing 已提交
1172 1173
    }
    console.log('Callback invoked to indicate a successful setting of the audio parameter.');
1174
});
W
wusongqing 已提交
1175 1176
```

1177
### setAudioParameter
V
Vaidegi B 已提交
1178

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

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

1183 1184
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 已提交
1185 1186
**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS

W
wusongqing 已提交
1187
**System capability**: SystemCapability.Multimedia.Audio.Core
1188

W
wusongqing 已提交
1189
**Parameters**
W
wusongqing 已提交
1190

W
wusongqing 已提交
1191 1192 1193 1194
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter to set.|
| value  | string | Yes  | Value of the audio parameter to set.|
1195

W
wusongqing 已提交
1196
**Return value**
1197

W
wusongqing 已提交
1198 1199 1200
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1201

W
wusongqing 已提交
1202
**Example**
W
wusongqing 已提交
1203 1204

```
1205
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
W
wusongqing 已提交
1206
    console.log('Promise returned to indicate a successful setting of the audio parameter.');
1207
});
W
wusongqing 已提交
1208 1209
```

1210
### getAudioParameter
V
Vaidegi B 已提交
1211

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

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

1216 1217
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 已提交
1218
**System capability**: SystemCapability.Multimedia.Audio.Core
W
wusongqing 已提交
1219

W
wusongqing 已提交
1220
**Parameters**
W
wusongqing 已提交
1221

W
wusongqing 已提交
1222 1223 1224 1225
| 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 已提交
1226

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

```
1230
audioManager.getAudioParameter('key_example', (err, value) => {
W
wusongqing 已提交
1231 1232
    if (err) {
        console.error('Failed to obtain the value of the audio parameter. ${err.message}');
1233
        return;
W
wusongqing 已提交
1234 1235
    }
    console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
1236
});
W
wusongqing 已提交
1237 1238
```

1239
### getAudioParameter
V
Vaidegi B 已提交
1240

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

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

1245 1246
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 已提交
1247
**System capability**: SystemCapability.Multimedia.Audio.Core
1248

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

W
wusongqing 已提交
1251 1252 1253
| Name| Type  | Mandatory| Description                  |
| ------ | ------ | ---- | ---------------------- |
| key    | string | Yes  | Key of the audio parameter whose value is to be obtained.|
1254

W
wusongqing 已提交
1255
**Return value**
W
wusongqing 已提交
1256

W
wusongqing 已提交
1257 1258 1259
| Type                 | Description                               |
| --------------------- | ----------------------------------- |
| Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
1260

W
wusongqing 已提交
1261
**Example**
W
wusongqing 已提交
1262 1263

```
1264
audioManager.getAudioParameter('key_example').then((value) => {
W
wusongqing 已提交
1265
    console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
1266
});
W
wusongqing 已提交
1267 1268
```

1269 1270
### getDevices

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

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

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

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

W
wusongqing 已提交
1279 1280 1281 1282
| 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 已提交
1283

W
wusongqing 已提交
1284
**Example**
W
wusongqing 已提交
1285
```
1286
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
W
wusongqing 已提交
1287
   if (err) {
1288 1289
       console.error('Failed to obtain the device list. ${err.message}');
       return;
W
wusongqing 已提交
1290 1291
   }
   console.log('Callback invoked to indicate that the device list is obtained.');
1292
});
W
wusongqing 已提交
1293 1294
```

1295
### getDevices
V
Vaidegi B 已提交
1296

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

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

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

W
wusongqing 已提交
1303
**Parameters**
W
wusongqing 已提交
1304

W
wusongqing 已提交
1305 1306 1307
| Name    | Type                     | Mandatory| Description            |
| ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes  | Audio device flag.|
W
wusongqing 已提交
1308

W
wusongqing 已提交
1309
**Return value**
1310

W
wusongqing 已提交
1311 1312 1313
| Type                                                        | Description                     |
| ------------------------------------------------------------ | ------------------------- |
| Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
W
wusongqing 已提交
1314

W
wusongqing 已提交
1315
**Example**
W
wusongqing 已提交
1316 1317

```
1318
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
W
wusongqing 已提交
1319
    console.log('Promise returned to indicate that the device list is obtained.');
1320
});
W
wusongqing 已提交
1321 1322
```

1323
### setDeviceActive
V
Vaidegi B 已提交
1324

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

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

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

W
wusongqing 已提交
1331
**Parameters**
W
wusongqing 已提交
1332

W
wusongqing 已提交
1333 1334 1335 1336 1337
| 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.|
1338

W
wusongqing 已提交
1339
**Example**
W
wusongqing 已提交
1340 1341

```
J
jiao_yanlin 已提交
1342
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
W
wusongqing 已提交
1343 1344
    if (err) {
        console.error('Failed to set the active status of the device. ${err.message}');
1345
        return;
W
wusongqing 已提交
1346 1347
    }
    console.log('Callback invoked to indicate that the device is set to the active status.');
1348
});
W
wusongqing 已提交
1349 1350
```

1351
### setDeviceActive
V
Vaidegi B 已提交
1352

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

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

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

W
wusongqing 已提交
1359
**Parameters**
1360

W
wusongqing 已提交
1361 1362 1363 1364
| 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 已提交
1365

W
wusongqing 已提交
1366
**Return value**
1367

W
wusongqing 已提交
1368 1369 1370
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
1371

W
wusongqing 已提交
1372
**Example**
1373

W
wusongqing 已提交
1374 1375

```
J
jiao_yanlin 已提交
1376
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
W
wusongqing 已提交
1377
    console.log('Promise returned to indicate that the device is set to the active status.');
1378
});
W
wusongqing 已提交
1379 1380
```

1381
### isDeviceActive
V
Vaidegi B 已提交
1382

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

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

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

W
wusongqing 已提交
1389
**Parameters**
W
wusongqing 已提交
1390

W
wusongqing 已提交
1391 1392 1393 1394
| 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.|
1395

W
wusongqing 已提交
1396
**Example**
W
wusongqing 已提交
1397 1398

```
J
jiao_yanlin 已提交
1399
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
W
wusongqing 已提交
1400 1401
    if (err) {
        console.error('Failed to obtain the active status of the device. ${err.message}');
1402
        return;
W
wusongqing 已提交
1403 1404
    }
    console.log('Callback invoked to indicate that the active status of the device is obtained.');
1405
});
W
wusongqing 已提交
1406 1407
```

V
Vaidegi B 已提交
1408

1409
### isDeviceActive
V
Vaidegi B 已提交
1410

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

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

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

W
wusongqing 已提交
1417
**Parameters**
1418

W
wusongqing 已提交
1419 1420 1421
| Name    | Type                                 | Mandatory| Description              |
| ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes  | Audio device type.|
1422

W
wusongqing 已提交
1423
**Return value**
1424

W
wusongqing 已提交
1425 1426 1427
| Type                   | Description                     |
| ---------------------- | ------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
1428

W
wusongqing 已提交
1429
**Example**
W
wusongqing 已提交
1430 1431

```
J
jiao_yanlin 已提交
1432
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
W
wusongqing 已提交
1433
    console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
1434
});
W
wusongqing 已提交
1435 1436
```

1437
### setMicrophoneMute
V
Vaidegi B 已提交
1438

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

1441 1442
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.

W
wusongqing 已提交
1443 1444
**Required permissions**: ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1447
**Parameters**
W
wusongqing 已提交
1448

W
wusongqing 已提交
1449 1450 1451 1452
| 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 已提交
1453

W
wusongqing 已提交
1454
**Example**
W
wusongqing 已提交
1455 1456 1457 1458 1459 1460 1461 1462

```
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.');
1463
});
W
wusongqing 已提交
1464 1465
```

1466
### setMicrophoneMute
V
Vaidegi B 已提交
1467

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

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

W
wusongqing 已提交
1472 1473
**Required permissions:** ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1476
**Parameters**
1477

W
wusongqing 已提交
1478 1479 1480
| Name| Type   | Mandatory| Description                                         |
| ------ | ------- | ---- | --------------------------------------------- |
| mute   | boolean | Yes  | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
1481

W
wusongqing 已提交
1482
**Return value**
W
wusongqing 已提交
1483

W
wusongqing 已提交
1484 1485 1486
| Type               | Description                           |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
W
wusongqing 已提交
1487

W
wusongqing 已提交
1488
**Example**
W
wusongqing 已提交
1489 1490

```
1491
audioManager.setMicrophoneMute(true).then(() => {
W
wusongqing 已提交
1492
    console.log('Promise returned to indicate that the microphone is muted.');
1493
});
W
wusongqing 已提交
1494 1495
```

1496
### isMicrophoneMute
V
Vaidegi B 已提交
1497

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

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

W
wusongqing 已提交
1502 1503
**Required permissions**: ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1506
**Parameters**
W
wusongqing 已提交
1507

W
wusongqing 已提交
1508 1509 1510
| 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 已提交
1511

W
wusongqing 已提交
1512
**Example**
W
wusongqing 已提交
1513 1514 1515 1516 1517 1518 1519 1520

```
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);
1521
});
W
wusongqing 已提交
1522 1523
```

1524
### isMicrophoneMute
V
Vaidegi B 已提交
1525

W
wusongqing 已提交
1526 1527 1528
isMicrophoneMute(): Promise&lt;boolean&gt;

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

W
wusongqing 已提交
1530 1531
**Required permissions**: ohos.permission.MICROPHONE

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

W
wusongqing 已提交
1534
**Return value**
1535

W
wusongqing 已提交
1536 1537 1538
| 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 已提交
1539

W
wusongqing 已提交
1540
**Example**
W
wusongqing 已提交
1541 1542 1543


```
1544
audioManager.isMicrophoneMute().then((value) => {
W
wusongqing 已提交
1545
    console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
1546
});
W
wusongqing 已提交
1547 1548
```

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

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

W
wusongqing 已提交
1553
Subscribes to system volume change events.
V
Vaidegi B 已提交
1554

1555
This is a system API and cannot be called by third-party applications.
1556

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

W
wusongqing 已提交
1559
**Parameters**
V
Vaidegi B 已提交
1560

W
wusongqing 已提交
1561 1562
| Name  | Type                                  | Mandatory| Description                                                        |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1563
| 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 已提交
1564
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes  | Callback used to return the system volume change event.                                                  |
V
Vaidegi B 已提交
1565

W
wusongqing 已提交
1566
**Example**
V
Vaidegi B 已提交
1567 1568 1569 1570 1571 1572

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

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

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

W
wusongqing 已提交
1580
Subscribes to ringer mode change events.
1581

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

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

W
wusongqing 已提交
1586
**Parameters**
V
Vaidegi B 已提交
1587

W
wusongqing 已提交
1588 1589
| Name  | Type                                     | Mandatory| Description                                                        |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1590
| 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 已提交
1591
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes  | Callback used to return the updated ringer mode.                                                  |
V
Vaidegi B 已提交
1592

W
wusongqing 已提交
1593
**Example**
V
Vaidegi B 已提交
1594 1595 1596 1597

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

1601
### on('deviceChange')
1602

1603
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
1604

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

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

W
wusongqing 已提交
1609
**Parameters**
1610

W
wusongqing 已提交
1611 1612
| Name  | Type                                                | Mandatory| Description                                      |
| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
W
wusongqing 已提交
1613
| 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 已提交
1614
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes  | Callback used to return the device update details.                        |
1615

W
wusongqing 已提交
1616
**Example**
1617 1618 1619 1620 1621 1622 1623

```
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);
1624
});
1625 1626
```

1627 1628 1629 1630
### off('deviceChange')

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

W
wusongqing 已提交
1631
Unsubscribes from device change events.
1632

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

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

W
wusongqing 已提交
1637 1638
| Name  | Type                                               | Mandatory| Description                                      |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
W
wusongqing 已提交
1639
| 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 已提交
1640
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)> | No  | Callback used to return the device update details.                        |
1641

W
wusongqing 已提交
1642
**Example**
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653

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

### on('interrupt')

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

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

W
wusongqing 已提交
1656
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1657

W
wusongqing 已提交
1658
**Parameters**
1659

W
wusongqing 已提交
1660 1661
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1662
| 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 已提交
1663 1664
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | Yes  | Callback invoked for the audio interruption event.                                      |
1665

W
wusongqing 已提交
1666
**Example**
1667 1668 1669 1670 1671 1672 1673

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
J
jiao_yanlin 已提交
1674
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689
    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 已提交
1690
Unsubscribes from audio interruption events.
1691

W
wusongqing 已提交
1692
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1693

W
wusongqing 已提交
1694
**Parameters**
1695

W
wusongqing 已提交
1696 1697
| Name   | Type                                         | Mandatory| Description                                                        |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
1698
| 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 已提交
1699 1700
| interrupt | AudioInterrupt                                | Yes  | Audio interruption event type.                                    |
| callback  | Callback<[InterruptAction](#interruptaction)> | No  | Callback invoked for the audio interruption event.                                      |
1701

W
wusongqing 已提交
1702
**Example**
1703 1704 1705 1706 1707 1708 1709

```
var interAudioInterrupt = {
    streamUsage:2,
    contentType:0,
    pauseWhenDucked:true
};
J
jiao_yanlin 已提交
1710
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
1711 1712 1713 1714 1715 1716 1717 1718
    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>
1719

1720
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
1721

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

1724
This is a system API and cannot be called by third-party applications.
1725

W
wusongqing 已提交
1726
**System capability**: SystemCapability.Multimedia.Audio.Communication
1727

W
wusongqing 已提交
1728
**Parameters**
1729

W
wusongqing 已提交
1730 1731 1732 1733
| 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.|
1734

W
wusongqing 已提交
1735
**Example**
1736 1737 1738 1739 1740 1741 1742 1743

```
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.');
1744
});
1745 1746
```

1747
### setAudioScene<sup>8+</sup>
1748

1749
setAudioScene\(scene: AudioScene\): Promise<void\>
1750

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

1753
This is a system API and cannot be called by third-party applications.
1754

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

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

W
wusongqing 已提交
1759 1760 1761
| Name| Type                                | Mandatory| Description          |
| :----- | :----------------------------------- | :--- | :------------- |
| scene  | <a href="#audioscene">AudioScene</a> | Yes  | Audio scene to set.|
1762

W
wusongqing 已提交
1763
**Return value**
1764

W
wusongqing 已提交
1765 1766 1767
| Type          | Description                |
| :------------- | :------------------- |
| Promise<void\> | Promise used to return the result.|
1768

W
wusongqing 已提交
1769
**Example**
1770 1771

```
J
jiao_yanlin 已提交
1772
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
1773 1774 1775 1776 1777 1778
    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');
});
```

1779
### getAudioScene<sup>8+</sup>
1780

1781
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
1782

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

W
wusongqing 已提交
1785
**System capability**: SystemCapability.Multimedia.Audio.Communication
1786

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

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

W
wusongqing 已提交
1793
**Example**
1794 1795 1796 1797 1798 1799 1800 1801

```
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);
1802
});
1803 1804 1805
```


1806
### getAudioScene<sup>8+</sup>
1807

1808
getAudioScene\(\): Promise<AudioScene\>
1809

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

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

W
wusongqing 已提交
1814
**Return value**
1815

W
wusongqing 已提交
1816 1817 1818
| Type                                         | Description                        |
| :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
1819

W
wusongqing 已提交
1820
**Example**
1821 1822 1823 1824 1825 1826

```
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');
1827
});
1828 1829
```

1830
## AudioDeviceDescriptor
V
Vaidegi B 已提交
1831

1832
Describes an audio device.
1833

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

W
wusongqing 已提交
1836 1837 1838 1839
| Name      | Type                   | Readable| Writable| Description      |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes  | No  | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes  | No  | Device type.|
V
Vaidegi B 已提交
1840

1841
## AudioDeviceDescriptors
V
Vaidegi B 已提交
1842

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

W
wusongqing 已提交
1845
**Example**
V
Vaidegi B 已提交
1846

1847 1848
```
import audio from '@ohos.multimedia.audio';
V
Vaidegi B 已提交
1849

1850 1851 1852
function displayDeviceProp(value) {
    deviceRoleValue = value.deviceRole;
    deviceTypeValue = value.deviceType;
V
Vaidegi B 已提交
1853 1854 1855

}

1856 1857 1858 1859 1860 1861
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 已提交
1862
    if (deviceTypeValue != null && deviceRoleValue != null){
1863
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  PASS');
V
Vaidegi B 已提交
1864 1865
    }
    else{
1866 1867
        console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG :  FAIL');
    }
1868
});
V
Vaidegi B 已提交
1869
```
W
wusongqing 已提交
1870

1871 1872
## AudioRenderer<sup>8+</sup>

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

W
wusongqing 已提交
1875
### Attributes
V
Vaidegi B 已提交
1876

W
wusongqing 已提交
1877
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1878

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

W
wusongqing 已提交
1883
**Example**
V
Vaidegi B 已提交
1884 1885

```
W
wusongqing 已提交
1886
var state = audioRenderer.state;
V
Vaidegi B 已提交
1887 1888
```

1889
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1890

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

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

W
wusongqing 已提交
1895
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1896

W
wusongqing 已提交
1897
**Parameters**
V
Vaidegi B 已提交
1898

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

W
wusongqing 已提交
1903
**Example**
V
Vaidegi B 已提交
1904 1905

```
1906
audioRenderer.getRendererInfo((err, rendererInfo) => {
1907 1908 1909 1910
    console.log('Renderer GetRendererInfo:');
    console.log('Renderer content:' + rendererInfo.content);
    console.log('Renderer usage:' + rendererInfo.usage);
    console.log('Renderer flags:' + rendererInfo.rendererFlags);
1911
});
V
Vaidegi B 已提交
1912 1913
```

1914
### getRendererInfo<sup>8+</sup>
V
Vaidegi B 已提交
1915

1916
getRendererInfo(): Promise<AudioRendererInfo\>
1917

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

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

W
wusongqing 已提交
1922
**Return value**
V
Vaidegi B 已提交
1923

W
wusongqing 已提交
1924 1925 1926
| Type                                              | Description                           |
| -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
V
Vaidegi B 已提交
1927

W
wusongqing 已提交
1928
**Example**
V
Vaidegi B 已提交
1929 1930

```
J
jiao_yanlin 已提交
1931
var resultFlag = true;
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
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 已提交
1942

1943
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1944

1945
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
1946

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

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

W
wusongqing 已提交
1951
**Parameters**
V
Vaidegi B 已提交
1952

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

W
wusongqing 已提交
1957
**Example**
V
Vaidegi B 已提交
1958 1959

```
1960
audioRenderer.getStreamInfo((err, streamInfo) => {
1961 1962
    console.log('Renderer GetStreamInfo:');
    console.log('Renderer sampling rate:' + streamInfo.samplingRate);
1963 1964 1965
    console.log('Renderer channel:' + streamInfo.channels);
    console.log('Renderer format:' + streamInfo.sampleFormat);
    console.log('Renderer encoding type:' + streamInfo.encodingType);
1966
});
V
Vaidegi B 已提交
1967 1968
```

1969
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
1970

1971
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
1972

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

W
wusongqing 已提交
1975
**System capability**: SystemCapability.Multimedia.Audio.Renderer
1976

W
wusongqing 已提交
1977
**Return value**
V
Vaidegi B 已提交
1978

W
wusongqing 已提交
1979 1980 1981
| Type                                          | Description                  |
| :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
1982

W
wusongqing 已提交
1983
**Example**
V
Vaidegi B 已提交
1984 1985

```
1986 1987 1988 1989 1990 1991 1992 1993 1994
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 已提交
1995 1996
```

1997
### start<sup>8+</sup>
V
Vaidegi B 已提交
1998

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

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

W
wusongqing 已提交
2003
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2004

W
wusongqing 已提交
2005
**Parameters**
V
Vaidegi B 已提交
2006

W
wusongqing 已提交
2007 2008 2009
| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2010

W
wusongqing 已提交
2011
**Example**
V
Vaidegi B 已提交
2012 2013

```
2014
audioRenderer.start((err) => {
2015 2016
    if (err) {
        console.error('Renderer start failed.');
V
Vaidegi B 已提交
2017
    } else {
2018
        console.info('Renderer start success.');
V
Vaidegi B 已提交
2019
    }
2020
});
V
Vaidegi B 已提交
2021 2022
```

2023
### start<sup>8+</sup>
V
Vaidegi B 已提交
2024

2025
start(): Promise<void\>
V
Vaidegi B 已提交
2026

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

W
wusongqing 已提交
2029
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2030

W
wusongqing 已提交
2031
**Return value**
V
Vaidegi B 已提交
2032

W
wusongqing 已提交
2033 2034 2035
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2036

W
wusongqing 已提交
2037
**Example**
V
Vaidegi B 已提交
2038 2039

```
2040 2041 2042 2043 2044
audioRenderer.start().then(() => {
    console.log('Renderer started');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2045 2046
```

2047
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2048

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

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

W
wusongqing 已提交
2053
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2054

W
wusongqing 已提交
2055
**Parameters**
V
Vaidegi B 已提交
2056

W
wusongqing 已提交
2057 2058 2059
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2060

W
wusongqing 已提交
2061
**Example**
V
Vaidegi B 已提交
2062 2063

```
2064
audioRenderer.pause((err) => {
2065 2066
    if (err) {
        console.error('Renderer pause failed');
V
Vaidegi B 已提交
2067
    } else {
2068
        console.log('Renderer paused.');
V
Vaidegi B 已提交
2069
    }
2070
});
V
Vaidegi B 已提交
2071 2072
```

2073
### pause<sup>8+</sup>
V
Vaidegi B 已提交
2074

2075
pause(): Promise\<void>
V
Vaidegi B 已提交
2076

2077
Pauses rendering. This API uses a promise to return the result.
2078

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

W
wusongqing 已提交
2081
**Return value**
V
Vaidegi B 已提交
2082

W
wusongqing 已提交
2083 2084 2085
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2086

W
wusongqing 已提交
2087
**Example**
V
Vaidegi B 已提交
2088 2089

```
2090 2091 2092 2093 2094
audioRenderer.pause().then(() => {
    console.log('Renderer paused');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2095 2096
```

2097
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2098

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

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

W
wusongqing 已提交
2103
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2104

W
wusongqing 已提交
2105
**Parameters**
V
Vaidegi B 已提交
2106

W
wusongqing 已提交
2107 2108 2109
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2110

W
wusongqing 已提交
2111
**Example**
V
Vaidegi B 已提交
2112 2113

```
2114
audioRenderer.drain((err) => {
2115 2116
    if (err) {
        console.error('Renderer drain failed');
V
Vaidegi B 已提交
2117
    } else {
2118
        console.log('Renderer drained.');
V
Vaidegi B 已提交
2119
    }
2120
});
V
Vaidegi B 已提交
2121 2122
```

2123
### drain<sup>8+</sup>
V
Vaidegi B 已提交
2124

2125
drain(): Promise\<void>
V
Vaidegi B 已提交
2126

2127
Drains the playback buffer. This API uses a promise to return the result.
2128

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

W
wusongqing 已提交
2131
**Return value**
V
Vaidegi B 已提交
2132

W
wusongqing 已提交
2133 2134 2135
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2136

W
wusongqing 已提交
2137
**Example**
V
Vaidegi B 已提交
2138 2139

```
2140 2141 2142 2143 2144
audioRenderer.drain().then(() => {
    console.log('Renderer drained successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2145 2146
```

2147
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2148

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

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

W
wusongqing 已提交
2153
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2154

W
wusongqing 已提交
2155
**Parameters**
V
Vaidegi B 已提交
2156

W
wusongqing 已提交
2157 2158 2159
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2160

W
wusongqing 已提交
2161
**Example**
V
Vaidegi B 已提交
2162 2163

```
2164
audioRenderer.stop((err) => {
2165 2166
    if (err) {
        console.error('Renderer stop failed');
V
Vaidegi B 已提交
2167
    } else {
2168
        console.log('Renderer stopped.');
V
Vaidegi B 已提交
2169
    }
2170
});
V
Vaidegi B 已提交
2171 2172
```

2173
### stop<sup>8+</sup>
V
Vaidegi B 已提交
2174

2175
stop(): Promise\<void>
V
Vaidegi B 已提交
2176

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

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

W
wusongqing 已提交
2181
**Return value**
V
Vaidegi B 已提交
2182

W
wusongqing 已提交
2183 2184 2185
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2186

W
wusongqing 已提交
2187
**Example**
V
Vaidegi B 已提交
2188 2189

```
2190 2191 2192 2193 2194
audioRenderer.stop().then(() => {
    console.log('Renderer stopped successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2195 2196
```

2197
### release<sup>8+</sup>
V
Vaidegi B 已提交
2198

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

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

W
wusongqing 已提交
2203
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2204

W
wusongqing 已提交
2205
**Parameters**
V
Vaidegi B 已提交
2206

W
wusongqing 已提交
2207 2208 2209
| Name  | Type                | Mandatory| Description            |
| -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2210

W
wusongqing 已提交
2211
**Example**
V
Vaidegi B 已提交
2212 2213

```
2214
audioRenderer.release((err) => {
2215 2216
    if (err) {
        console.error('Renderer release failed');
V
Vaidegi B 已提交
2217
    } else {
2218
        console.log('Renderer released.');
V
Vaidegi B 已提交
2219
    }
2220
});
V
Vaidegi B 已提交
2221 2222
```

2223
### release<sup>8+</sup>
V
Vaidegi B 已提交
2224

2225
release(): Promise\<void>
V
Vaidegi B 已提交
2226

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

W
wusongqing 已提交
2229
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2230

W
wusongqing 已提交
2231
**Return value**
V
Vaidegi B 已提交
2232

W
wusongqing 已提交
2233 2234 2235
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2236

W
wusongqing 已提交
2237
**Example**
V
Vaidegi B 已提交
2238 2239

```
2240 2241 2242 2243 2244
audioRenderer.release().then(() => {
    console.log('Renderer released successfully');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2245 2246
```

2247
### write<sup>8+</sup>
V
Vaidegi B 已提交
2248

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

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

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

W
wusongqing 已提交
2255
**Parameters**
V
Vaidegi B 已提交
2256

W
wusongqing 已提交
2257 2258 2259 2260
| 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 已提交
2261

W
wusongqing 已提交
2262
**Example**
V
Vaidegi B 已提交
2263 2264

```
2265 2266
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
2267
import featureAbility from '@ohos.ability.featureAbility'
2268

R
rahul 已提交
2269 2270 2271 2272 2273 2274 2275 2276 2277 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
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 已提交
2304 2305 2306
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2307
audioRenderer.write(buf, (err, writtenbytes) => {
V
Vaidegi B 已提交
2308
    if (writtenbytes < 0) {
2309
        console.error('write failed.');
V
Vaidegi B 已提交
2310 2311 2312
    } else {
       console.log('Actual written bytes: ' + writtenbytes);
    }
2313
});
V
Vaidegi B 已提交
2314 2315
```

2316
### write<sup>8+</sup>
V
Vaidegi B 已提交
2317

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

2320
Writes the buffer. This API uses a promise to return the result.
2321

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

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

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

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

```
2333 2334
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
R
rahul 已提交
2335
import featureAbility from '@ohos.ability.featureAbility'
2336

R
rahul 已提交
2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370
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('BufferSize: ' + bufferSize);
var context = featureAbility.getContext();
var path = await context.getCacheDir();
2371
var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
V
Vaidegi B 已提交
2372 2373 2374
let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
2375 2376 2377 2378 2379 2380 2381 2382 2383
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 已提交
2384 2385
```

2386
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2387

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

W
wusongqing 已提交
2390
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 已提交
2391

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

W
wusongqing 已提交
2394
**Parameters**
V
Vaidegi B 已提交
2395

W
wusongqing 已提交
2396 2397 2398
| Name  | Type                  | Mandatory| Description            |
| -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the timestamp.|
V
Vaidegi B 已提交
2399

W
wusongqing 已提交
2400
**Example**
V
Vaidegi B 已提交
2401 2402

```
2403
audioRenderer.getAudioTime((err, timestamp) => {
V
Vaidegi B 已提交
2404
    console.log('Current timestamp: ' + timestamp);
2405
});
V
Vaidegi B 已提交
2406 2407
```

2408
### getAudioTime<sup>8+</sup>
V
Vaidegi B 已提交
2409

2410
getAudioTime(): Promise\<number>
V
Vaidegi B 已提交
2411

W
wusongqing 已提交
2412
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 已提交
2413

W
wusongqing 已提交
2414
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2415

W
wusongqing 已提交
2416
**Return value**
V
Vaidegi B 已提交
2417

W
wusongqing 已提交
2418 2419 2420
| Type            | Description                   |
| ---------------- | ----------------------- |
| Promise\<number> | Promise used to return the timestamp.|
V
Vaidegi B 已提交
2421

W
wusongqing 已提交
2422
**Example**
V
Vaidegi B 已提交
2423 2424

```
2425 2426 2427 2428 2429
audioRenderer.getAudioTime().then((timestamp) => {
    console.log('Current timestamp: ' + timestamp);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2430 2431
```

2432
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2433

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

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

W
wusongqing 已提交
2438
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2439

W
wusongqing 已提交
2440
**Parameters**
V
Vaidegi B 已提交
2441

W
wusongqing 已提交
2442 2443 2444
| Name  | Type                  | Mandatory| Description                |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<number> | Yes  | Callback used to return the buffer size.|
V
Vaidegi B 已提交
2445

W
wusongqing 已提交
2446
**Example**
V
Vaidegi B 已提交
2447 2448

```
J
jiao_yanlin 已提交
2449
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
V
Vaidegi B 已提交
2450 2451 2452
    if (err) {
        console.error('getBufferSize error');
    }
2453
});
V
Vaidegi B 已提交
2454 2455
```

2456
### getBufferSize<sup>8+</sup>
V
Vaidegi B 已提交
2457

2458
getBufferSize(): Promise\<number>
V
Vaidegi B 已提交
2459

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

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

W
wusongqing 已提交
2464
**Return value**
V
Vaidegi B 已提交
2465

W
wusongqing 已提交
2466 2467 2468
| Type            | Description                       |
| ---------------- | --------------------------- |
| Promise\<number> | Promise used to return the buffer size.|
V
Vaidegi B 已提交
2469

W
wusongqing 已提交
2470
**Example**
V
Vaidegi B 已提交
2471 2472

```
R
rahul 已提交
2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499
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);
    });
J
jiao_yanlin 已提交
2500
var bufferSize;
R
rahul 已提交
2501 2502
audioRenderer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
J
jiao_yanlin 已提交
2503
    bufferSize=data;
2504
}).catch((err) => {
R
rahul 已提交
2505
    console.info('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
2506
});
V
Vaidegi B 已提交
2507 2508
```

2509
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2510

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

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

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

W
wusongqing 已提交
2517
**Parameters**
2518

W
wusongqing 已提交
2519 2520 2521 2522
| Name  | Type                                    | Mandatory| Description                    |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| rate     | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.            |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result.|
V
Vaidegi B 已提交
2523

W
wusongqing 已提交
2524
**Example**
V
Vaidegi B 已提交
2525 2526

```
2527
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
V
Vaidegi B 已提交
2528
    if (err) {
2529
        console.error('Failed to set params');
V
Vaidegi B 已提交
2530 2531 2532
    } else {
        console.log('Callback invoked to indicate a successful render rate setting.');
    }
2533
});
V
Vaidegi B 已提交
2534 2535
```

2536
### setRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2537

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

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

W
wusongqing 已提交
2542
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2543

W
wusongqing 已提交
2544
**Parameters**
V
Vaidegi B 已提交
2545

W
wusongqing 已提交
2546 2547 2548
| Name| Type                                    | Mandatory| Description        |
| ------ | ---------------------------------------- | ---- | ------------ |
| rate   | [AudioRendererRate](#audiorendererrate8) | Yes  | Audio render rate.|
V
Vaidegi B 已提交
2549

W
wusongqing 已提交
2550
**Return value**
V
Vaidegi B 已提交
2551

W
wusongqing 已提交
2552 2553 2554
| Type          | Description                     |
| -------------- | ------------------------- |
| Promise\<void> | Promise used to return the result.|
V
Vaidegi B 已提交
2555

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

```
2559 2560 2561 2562 2563
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
    console.log('setRenderRate SUCCESS');
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2564 2565
```

2566
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2567

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

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

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

W
wusongqing 已提交
2574
**Parameters**
2575

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

W
wusongqing 已提交
2580
**Example**
V
Vaidegi B 已提交
2581 2582

```
2583
audioRenderer.getRenderRate((err, renderrate) => {
V
Vaidegi B 已提交
2584
    console.log('getRenderRate: ' + renderrate);
2585
});
V
Vaidegi B 已提交
2586 2587
```

2588
### getRenderRate<sup>8+</sup>
V
Vaidegi B 已提交
2589

2590
getRenderRate(): Promise\<AudioRendererRate>
2591

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

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

W
wusongqing 已提交
2596
**Return value**
V
Vaidegi B 已提交
2597

W
wusongqing 已提交
2598 2599 2600
| Type                                             | Description                     |
| ------------------------------------------------- | ------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
V
Vaidegi B 已提交
2601

W
wusongqing 已提交
2602
**Example**
V
Vaidegi B 已提交
2603 2604

```
2605 2606 2607 2608 2609
audioRenderer.getRenderRate().then((renderRate) => {
    console.log('getRenderRate: ' + renderRate);
}).catch((err) => {
    console.log('ERROR: '+err.message);
});
V
Vaidegi B 已提交
2610 2611
```

W
wusongqing 已提交
2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623
### on('interrupt')<sup>9+</sup>

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

Subscribes to audio interruption events. This API uses a callback to get interrupt events.

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

**Parameters**

| Name  | Type                                        | Mandatory| Description                                                        |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
W
wusongqing 已提交
2624
| type     | string                                       | Yes  | Event type. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.|
W
wusongqing 已提交
2625 2626 2627 2628 2629
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes  | Callback used to return the audio interruption event.                                    |

**Example**

```
J
jiao_yanlin 已提交
2630 2631 2632
var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
W
wusongqing 已提交
2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644
    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) {
J
jiao_yanlin 已提交
2645
        switch (interruptEvent.hintType) {
W
wusongqing 已提交
2646 2647
            case audio.InterruptHint.INTERRUPT_HINT_RESUME:
                console.log('Resume force paused renderer or ignore');
J
jiao_yanlin 已提交
2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660
                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');
                }
W
wusongqing 已提交
2661 2662 2663
                break;
            case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
                console.log('Choose to pause or ignore');
J
jiao_yanlin 已提交
2664 2665 2666 2667 2668 2669 2670 2671
                if (isPlay == true) {
                    isPlay == false;
                    console.info('AudioInterruptMusic: Media PAUSE : TRUE');
                }
                else {
                    isPlay = true;
                    console.info('AudioInterruptMusic: Media PLAY : TRUE');
                }
W
wusongqing 已提交
2672 2673 2674 2675 2676 2677
                break;
        }
    }
});
```

2678
### on('markReach')<sup>8+</sup>
2679

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

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

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

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

W
wusongqing 已提交
2688 2689
| Name  | Type                    | Mandatory| Description                                     |
| :------- | :----------------------- | :--- | :---------------------------------------- |
W
wusongqing 已提交
2690
| 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 已提交
2691 2692
| 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.                   |
2693

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

```
audioRenderer.on('markReach', 1000, (position) => {
R
rahul 已提交
2698
    if (position == 1000) {
2699 2700 2701 2702 2703 2704
        console.log('ON Triggered successfully');
    }
});
```


2705
### off('markReach') <sup>8+</sup>
2706

2707
off(type: 'markReach'): void
2708 2709 2710

Unsubscribes from mark reached events.

W
wusongqing 已提交
2711
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2712

W
wusongqing 已提交
2713
**Parameters**
2714

W
wusongqing 已提交
2715 2716
| Name| Type  | Mandatory| Description                                             |
| :----- | :----- | :--- | :------------------------------------------------ |
W
wusongqing 已提交
2717
| type   | string | Yes  | Event type. The value is fixed at **markReach**.|
2718

W
wusongqing 已提交
2719
**Example**
2720 2721 2722 2723 2724

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

2725
### on('periodReach') <sup>8+</sup>
2726

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

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

W
wusongqing 已提交
2731
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2732

W
wusongqing 已提交
2733
**Parameters**
2734

W
wusongqing 已提交
2735 2736
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
W
wusongqing 已提交
2737
| 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 已提交
2738 2739
| 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.                     |
2740

W
wusongqing 已提交
2741
**Example**
2742 2743 2744

```
audioRenderer.on('periodReach', 1000, (position) => {
R
rahul 已提交
2745
    if (position == 1000) {
2746 2747 2748 2749 2750
        console.log('ON Triggered successfully');
    }
});
```

2751
### off('periodReach') <sup>8+</sup>
2752

2753
off(type: 'periodReach'): void
2754 2755 2756

Unsubscribes from period reached events.

W
wusongqing 已提交
2757
**System capability**: SystemCapability.Multimedia.Audio.Renderer
2758

W
wusongqing 已提交
2759
**Parameters**
2760

W
wusongqing 已提交
2761 2762
| Name| Type  | Mandatory| Description                                               |
| :----- | :----- | :--- | :-------------------------------------------------- |
W
wusongqing 已提交
2763
| type   | string | Yes  | Event type. The value is fixed at **periodReach**.|
2764

W
wusongqing 已提交
2765
**Example**
2766 2767 2768 2769

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

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

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

2775
Subscribes to state change events.
V
Vaidegi B 已提交
2776

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

W
wusongqing 已提交
2779
**Parameters**
2780

W
wusongqing 已提交
2781 2782
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
W
wusongqing 已提交
2783
| type     | string                     | Yes  | Event type. The value **stateChange** means the state change event.|
W
wusongqing 已提交
2784
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
2785

W
wusongqing 已提交
2786
**Example**
2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797

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

2799
## AudioCapturer<sup>8+</sup>
V
Vaidegi B 已提交
2800

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

W
wusongqing 已提交
2803
### Attributes
V
Vaidegi B 已提交
2804

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

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

W
wusongqing 已提交
2811
**Example**
V
Vaidegi B 已提交
2812 2813

```
2814
var state = audioCapturer.state;
V
Vaidegi B 已提交
2815 2816
```

2817
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2818

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

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

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

W
wusongqing 已提交
2825
**Parameters**
V
Vaidegi B 已提交
2826

W
wusongqing 已提交
2827 2828 2829
| Name  | Type                             | Mandatory| Description                                |
| :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes  | Callback used to return the capturer information.|
V
Vaidegi B 已提交
2830

W
wusongqing 已提交
2831
**Example**
V
Vaidegi B 已提交
2832 2833

```
2834
audioCapturer.getCapturerInfo((err, capturerInfo) => {
V
Vaidegi B 已提交
2835
    if (err) {
2836
        console.error('Failed to get capture info');
V
Vaidegi B 已提交
2837
    } else {
2838 2839 2840
        console.log('Capturer getCapturerInfo:');
        console.log('Capturer source:' + capturerInfo.source);
        console.log('Capturer flags:' + capturerInfo.capturerFlags);
V
Vaidegi B 已提交
2841
    }
2842
});
V
Vaidegi B 已提交
2843 2844 2845
```


2846
### getCapturerInfo<sup>8+</sup>
V
Vaidegi B 已提交
2847

2848
getCapturerInfo(): Promise<AudioCapturerInfo\>
V
Vaidegi B 已提交
2849

W
wusongqing 已提交
2850
Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
V
Vaidegi B 已提交
2851

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

W
wusongqing 已提交
2854
**Return value**
V
Vaidegi B 已提交
2855

W
wusongqing 已提交
2856 2857 2858
| Type                                             | Description                               |
| :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
V
Vaidegi B 已提交
2859

W
wusongqing 已提交
2860
**Example**
V
Vaidegi B 已提交
2861 2862

```
2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873
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);
2874
});
2875
```
V
Vaidegi B 已提交
2876

2877
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2878

2879
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
V
Vaidegi B 已提交
2880

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

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

W
wusongqing 已提交
2885
**Parameters**
V
Vaidegi B 已提交
2886

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

W
wusongqing 已提交
2891
**Example**
V
Vaidegi B 已提交
2892 2893

```
2894
audioCapturer.getStreamInfo((err, streamInfo) => {
V
Vaidegi B 已提交
2895
    if (err) {
2896
        console.error('Failed to get stream info');
V
Vaidegi B 已提交
2897
    } else {
2898 2899 2900 2901 2902
        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 已提交
2903
    }
2904
});
V
Vaidegi B 已提交
2905 2906
```

2907
### getStreamInfo<sup>8+</sup>
V
Vaidegi B 已提交
2908

2909
getStreamInfo(): Promise<AudioStreamInfo\>
V
Vaidegi B 已提交
2910

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

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

W
wusongqing 已提交
2915
**Return value**
V
Vaidegi B 已提交
2916

W
wusongqing 已提交
2917 2918 2919
| Type                                          | Description                           |
| :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
V
Vaidegi B 已提交
2920

W
wusongqing 已提交
2921
**Example**
V
Vaidegi B 已提交
2922 2923

```
2924 2925 2926 2927 2928 2929 2930 2931
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);
2932
});
V
Vaidegi B 已提交
2933 2934
```

2935
### start<sup>8+</sup>
V
Vaidegi B 已提交
2936

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

2939
Starts capturing. This API uses an asynchronous callback to return the result.
2940

W
wusongqing 已提交
2941
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2942

W
wusongqing 已提交
2943
**Parameters**
2944

W
wusongqing 已提交
2945 2946 2947
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
2948

W
wusongqing 已提交
2949
**Example**
2950 2951

```
2952
audioCapturer.start((err) => {
2953 2954 2955 2956 2957
    if (err) {
        console.error('Capturer start failed.');
    } else {
        console.info('Capturer start success.');
    }
2958
});
2959 2960 2961
```


2962
### start<sup>8+</sup>
2963

2964
start(): Promise<void\>
2965

2966
Starts capturing. This API uses a promise to return the result.
2967

W
wusongqing 已提交
2968
**System capability**: SystemCapability.Multimedia.Audio.Capturer
2969

W
wusongqing 已提交
2970
**Return value**
2971

W
wusongqing 已提交
2972 2973 2974
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
2975

W
wusongqing 已提交
2976
**Example**
2977 2978

```
R
rahul 已提交
2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
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);
    });
3001
audioCapturer.start().then(() => {
3002
    console.info('AudioFrameworkRecLog: ---------START---------');
R
rahul 已提交
3003 3004 3005
    console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
    console.info('AudioFrameworkRecLog: AudioCapturer: STATE: '+audioCapturer.state);
    console.info('AudioFrameworkRecLog: Capturer started: SUCCESS ');
3006
    if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
R
rahul 已提交
3007
        console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
3008 3009 3010 3011
    }
}).catch((err) => {
    console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
    stateFlag=false;
3012 3013 3014
});
```

3015
### stop<sup>8+</sup>
3016

3017
stop(callback: AsyncCallback<void\>): void
3018

3019
Stops capturing. This API uses an asynchronous callback to return the result.
3020

W
wusongqing 已提交
3021
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3022

W
wusongqing 已提交
3023
**Parameters**
3024

W
wusongqing 已提交
3025 3026 3027
| Name  | Type                | Mandatory| Description                          |
| :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result.|
3028

W
wusongqing 已提交
3029
**Example**
3030 3031

```
3032
audioCapturer.stop((err) => {
3033 3034 3035 3036 3037
    if (err) {
        console.error('Capturer stop failed');
    } else {
        console.log('Capturer stopped.');
    }
3038
});
3039 3040 3041
```


3042
### stop<sup>8+</sup>
3043

3044
stop(): Promise<void\>
3045

3046
Stops capturing. This API uses a promise to return the result.
3047

W
wusongqing 已提交
3048
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3049

W
wusongqing 已提交
3050
**Return value**
3051

W
wusongqing 已提交
3052 3053 3054
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3055

W
wusongqing 已提交
3056
**Example**
3057 3058 3059

```
audioCapturer.stop().then(() => {
R
rahul 已提交
3060 3061 3062 3063
    console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
    console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
    if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
        console.info('AudioFrameworkRecLog: State is Stopped': ');
3064 3065
    }
}).catch((err) => {
R
rahul 已提交
3066
    console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
3067 3068 3069
});
```

3070
### release<sup>8+</sup>
3071

3072
release(callback: AsyncCallback<void\>): void
3073

W
wusongqing 已提交
3074
Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
3075

W
wusongqing 已提交
3076
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3077

W
wusongqing 已提交
3078
**Parameters**
3079

W
wusongqing 已提交
3080 3081 3082
| Name  | Type                | Mandatory| Description                               |
| :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. |
3083

W
wusongqing 已提交
3084
**Example**
3085 3086

```
3087
audioCapturer.release((err) => {
3088 3089 3090 3091 3092
    if (err) {
        console.error('capturer release failed');
    } else {
        console.log('capturer released.');
    }
3093
});
3094 3095 3096
```


3097
### release<sup>8+</sup>
3098

3099
release(): Promise<void\>
3100

W
wusongqing 已提交
3101
Releases this **AudioCapturer** instance. This API uses a promise to return the result.
3102

W
wusongqing 已提交
3103
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3104

W
wusongqing 已提交
3105
**Return value**
3106

W
wusongqing 已提交
3107 3108 3109
| Type          | Description                         |
| :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result.|
3110

W
wusongqing 已提交
3111
**Example**
3112 3113 3114

```
audioCapturer.release().then(() => {
3115 3116 3117 3118 3119
    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 已提交
3120
    console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
3121 3122 3123 3124
});
```


3125
### read<sup>8+</sup>
3126

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

W
wusongqing 已提交
3129
Reads the buffer. This API uses an asynchronous callback to return the result.
3130

W
wusongqing 已提交
3131
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3132

W
wusongqing 已提交
3133
**Parameters**
3134

W
wusongqing 已提交
3135 3136 3137 3138 3139
| 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.|
3140

W
wusongqing 已提交
3141
**Example**
3142 3143

```
R
rahul 已提交
3144 3145 3146 3147 3148 3149 3150
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRecLog: getBufferSize: SUCCESS '+data);
    bufferSize = data;
    }).catch((err) => {
    console.info('AudioFrameworkRecLog: getBufferSize: EROOR: '+err.message);
    });
3151 3152 3153 3154
audioCapturer.read(bufferSize, true, async(err, buffer) => {
    if (!err) {
        console.log("Success in reading the buffer data");
    }
J
jiao_yanlin 已提交
3155
});
3156 3157 3158
```


3159
### read<sup>8+</sup>
3160

3161
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
3162

W
wusongqing 已提交
3163
Reads the buffer. This API uses a promise to return the result.
3164

W
wusongqing 已提交
3165
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3166

W
wusongqing 已提交
3167
**Parameters**
3168

W
wusongqing 已提交
3169 3170 3171 3172
| Name        | Type   | Mandatory| Description            |
| :------------- | :------ | :--- | :--------------- |
| size           | number  | Yes  | Number of bytes to read.  |
| isBlockingRead | boolean | Yes  | Whether to block the read operation.|
3173

W
wusongqing 已提交
3174
**Return value**
3175

W
wusongqing 已提交
3176 3177 3178
| Type                 | Description                                                  |
| :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
3179

W
wusongqing 已提交
3180
**Example**
3181 3182

```
R
rahul 已提交
3183 3184 3185 3186 3187 3188 3189 3190
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);
3191 3192 3193 3194
audioCapturer.read(bufferSize, true).then((buffer) => {
    console.info('buffer read successfully');
}).catch((err) => {
    console.info('ERROR : '+err.message);
3195 3196 3197 3198
});
```


3199
### getAudioTime<sup>8+</sup>
3200

3201
getAudioTime(callback: AsyncCallback<number\>): void
3202

W
wusongqing 已提交
3203
Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
3204

W
wusongqing 已提交
3205
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3206

W
wusongqing 已提交
3207
**Parameters**
3208

W
wusongqing 已提交
3209 3210 3211
| Name  | Type                  | Mandatory| Description                          |
| :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the timestamp.|
3212

W
wusongqing 已提交
3213
**Example**
3214 3215

```
3216
audioCapturer.getAudioTime((err, timestamp) => {
3217
    console.log('Current timestamp: ' + timestamp);
3218
});
3219 3220 3221
```


3222
### getAudioTime<sup>8+</sup>
3223

3224
getAudioTime(): Promise<number\>
3225

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

W
wusongqing 已提交
3228
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3229

W
wusongqing 已提交
3230
**Return value**
3231

W
wusongqing 已提交
3232 3233 3234
| Type            | Description                         |
| :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp.|
3235

W
wusongqing 已提交
3236
**Example**
3237 3238 3239

```
audioCapturer.getAudioTime().then((audioTime) => {
3240 3241 3242
    console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
}).catch((err) => {
    console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
3243 3244 3245 3246
});
```


3247
### getBufferSize<sup>8+</sup>
3248

3249
getBufferSize(callback: AsyncCallback<number\>): void
3250

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

W
wusongqing 已提交
3253
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3254

W
wusongqing 已提交
3255
**Parameters**
3256

W
wusongqing 已提交
3257 3258 3259
| Name  | Type                  | Mandatory| Description                                |
| :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes  | Callback used to return the buffer size.|
3260

W
wusongqing 已提交
3261
**Example**
3262 3263

```
3264
audioCapturer.getBufferSize((err, bufferSize) => {
3265 3266
    if (!err) {
        console.log('BufferSize : ' + bufferSize);
3267 3268 3269 3270 3271
        audioCapturer.read(bufferSize, true).then((buffer) => {
            console.info('Buffer read is ' + buffer );
        }).catch((err) => {
            console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
        });
3272 3273 3274 3275
    }
});
```

W
wusongqing 已提交
3276

3277
### getBufferSize<sup>8+</sup>
3278

3279
getBufferSize(): Promise<number\>
3280

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

W
wusongqing 已提交
3283
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3284

W
wusongqing 已提交
3285
**Return value**
3286

W
wusongqing 已提交
3287 3288 3289
| Type            | Description                               |
| :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size.|
3290

W
wusongqing 已提交
3291
**Example**
3292 3293

```
R
rahul 已提交
3294 3295 3296 3297 3298 3299
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
    console.info('AudioFrameworkRecLog: getBufferSize :SUCCESS '+ data);
    bufferSize = data;
}).catch((err) => {
    console.info('AudioFrameworkRecLog: getBufferSize :ERROR : '+ err.message);
3300 3301 3302
});
```

W
wusongqing 已提交
3303

3304
### on('markReach')<sup>8+</sup>
3305

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

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

W
wusongqing 已提交
3310
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3311

W
wusongqing 已提交
3312
**Parameters**
3313

W
wusongqing 已提交
3314 3315
| Name  | Type                   | Mandatory| Description                                      |
| :------- | :---------------------- | :--- | :----------------------------------------- |
W
wusongqing 已提交
3316
| 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 已提交
3317 3318
| 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.|
3319

W
wusongqing 已提交
3320
**Example**
3321 3322 3323

```
audioCapturer.on('markReach', 1000, (position) => {
R
rahul 已提交
3324
    if (position == 1000) {
3325 3326 3327 3328 3329
        console.log('ON Triggered successfully');
    }
});
```

3330
### off('markReach')<sup>8+</sup>
3331

3332
off(type: 'markReach'): void
3333

W
wusongqing 已提交
3334
Unsubscribes from mark reached events.
3335

W
wusongqing 已提交
3336
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3337

W
wusongqing 已提交
3338
**Parameters**
3339

W
wusongqing 已提交
3340 3341
| Name| Type  | Mandatory| Description                                         |
| :----- | :----- | :--- | :-------------------------------------------- |
W
wusongqing 已提交
3342
| 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.|
3343

W
wusongqing 已提交
3344
**Example**
3345 3346 3347 3348 3349

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

3350
### on('periodReach')<sup>8+</sup>
3351

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

W
wusongqing 已提交
3354
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
3355

W
wusongqing 已提交
3356
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3357

W
wusongqing 已提交
3358
**Parameters**
3359

W
wusongqing 已提交
3360 3361
| Name  | Type                    | Mandatory| Description                                       |
| :------- | :----------------------- | :--- | :------------------------------------------ |
W
wusongqing 已提交
3362
| 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 已提交
3363
| frame    | number                   | Yes  | Period during which frame capturing is listened. The value must be greater than **0**.           |
W
wusongqing 已提交
3364
| callback | (position: number) => {} | Yes  | Callback invoked when the event is triggered.   |
3365

W
wusongqing 已提交
3366
**Example**
3367 3368 3369

```
audioCapturer.on('periodReach', 1000, (position) => {
R
rahul 已提交
3370
    if (position == 1000) {
3371 3372 3373 3374 3375
        console.log('ON Triggered successfully');
    }
});
```

3376
### off('periodReach')<sup>8+</sup>
3377

3378
off(type: 'periodReach'): void
3379 3380 3381

Unsubscribes from period reached events.

W
wusongqing 已提交
3382
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3383

W
wusongqing 已提交
3384
**Parameters**
3385

W
wusongqing 已提交
3386 3387
| Name| Type  | Mandatory| Description                                           |
| :----- | :----- | :--- | :---------------------------------------------- |
W
wusongqing 已提交
3388
| 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.|
3389

W
wusongqing 已提交
3390
**Example**
3391 3392 3393 3394 3395 3396 3397 3398

```
audioCapturer.off('periodReach')
```

### on('stateChange') <sup>8+</sup>

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

3400
Subscribes to state change events.
3401

W
wusongqing 已提交
3402
**System capability**: SystemCapability.Multimedia.Audio.Capturer
3403

W
wusongqing 已提交
3404
**Parameters**
3405

W
wusongqing 已提交
3406 3407
| Name  | Type                      | Mandatory| Description                                       |
| :------- | :------------------------- | :--- | :------------------------------------------ |
W
wusongqing 已提交
3408
| type     | string                     | Yes  | Event type. The value **stateChange** means the state change event.|
W
wusongqing 已提交
3409
| callback | [AudioState](#audiostate8) | Yes  | Callback used to return the state change.                           |
3410

W
wusongqing 已提交
3411
**Example**
3412 3413

```
3414 3415 3416 3417 3418 3419 3420 3421
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");
    }
});
3422
```