1# @ohos.multimedia.audio (Audio Management) 2 3The **Audio** module provides basic audio management capabilities, including audio volume and audio device management, and audio data collection and rendering. 4 5This module provides the following common audio-related functions: 6 7- [AudioManager](#audiomanager): audio management. 8- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data. 9- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data. 10- [TonePlayer](#toneplayer9): tone player, used to manage and play Dual Tone Multi Frequency (DTMF) tones, such as dial tones and ringback tones. 11 12> **NOTE** 13> 14> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 15 16## Modules to Import 17 18```js 19import audio from '@ohos.multimedia.audio'; 20``` 21 22## Constants 23 24| Name | Type | Readable | Writable| Description | 25| --------------------------------------- | ----------| ---- | ---- | ------------------ | 26| LOCAL_NETWORK_ID<sup>9+</sup> | string | Yes | No | Network ID of the local device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.Audio.Device | 27| DEFAULT_VOLUME_GROUP_ID<sup>9+</sup> | number | Yes | No | Default volume group ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Volume | 28| DEFAULT_INTERRUPT_GROUP_ID<sup>9+</sup> | number | Yes | No | Default audio interruption group ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Interrupt | 29 30**Example** 31 32```js 33import audio from '@ohos.multimedia.audio'; 34 35const localNetworkId = audio.LOCAL_NETWORK_ID; 36const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID; 37const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID; 38``` 39 40## audio.getAudioManager 41 42getAudioManager(): AudioManager 43 44Obtains an **AudioManager** instance. 45 46**System capability**: SystemCapability.Multimedia.Audio.Core 47 48**Return value** 49 50| Type | Description | 51| ----------------------------- | ------------ | 52| [AudioManager](#audiomanager) | **AudioManager** instance.| 53 54**Example** 55```js 56let audioManager = audio.getAudioManager(); 57``` 58 59## audio.createAudioRenderer<sup>8+</sup> 60 61createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void 62 63Creates an **AudioRenderer** instance. This API uses an asynchronous callback to return the result. 64 65**System capability**: SystemCapability.Multimedia.Audio.Renderer 66 67**Parameters** 68 69| Name | Type | Mandatory| Description | 70| -------- | ----------------------------------------------- | ---- | ---------------- | 71| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | 72| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the **AudioRenderer** instance.| 73 74**Example** 75 76```js 77import featureAbility from '@ohos.ability.featureAbility'; 78import fs from '@ohos.file.fs'; 79import audio from '@ohos.multimedia.audio'; 80 81let audioStreamInfo = { 82 samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, 83 channels: audio.AudioChannel.CHANNEL_1, 84 sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, 85 encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW 86} 87 88let audioRendererInfo = { 89 content: audio.ContentType.CONTENT_TYPE_SPEECH, 90 usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, 91 rendererFlags: 0 92} 93 94let audioRendererOptions = { 95 streamInfo: audioStreamInfo, 96 rendererInfo: audioRendererInfo 97} 98 99audio.createAudioRenderer(audioRendererOptions,(err, data) => { 100 if (err) { 101 console.error(`AudioRenderer Created: Error: ${err}`); 102 } else { 103 console.info('AudioRenderer Created: Success: SUCCESS'); 104 let audioRenderer = data; 105 } 106}); 107``` 108 109## audio.createAudioRenderer<sup>8+</sup> 110 111createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\> 112 113Creates an **AudioRenderer** instance. This API uses a promise to return the result. 114 115**System capability**: SystemCapability.Multimedia.Audio.Renderer 116 117**Parameters** 118 119| Name | Type | Mandatory| Description | 120| :------ | :--------------------------------------------- | :--- | :----------- | 121| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations.| 122 123**Return value** 124 125| Type | Description | 126| ----------------------------------------- | ---------------- | 127| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.| 128 129**Example** 130 131```js 132import featureAbility from '@ohos.ability.featureAbility'; 133import fs from '@ohos.file.fs'; 134import audio from '@ohos.multimedia.audio'; 135 136let audioStreamInfo = { 137 samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, 138 channels: audio.AudioChannel.CHANNEL_1, 139 sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, 140 encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW 141} 142 143let audioRendererInfo = { 144 content: audio.ContentType.CONTENT_TYPE_SPEECH, 145 usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, 146 rendererFlags: 0 147} 148 149let audioRendererOptions = { 150 streamInfo: audioStreamInfo, 151 rendererInfo: audioRendererInfo 152} 153 154let audioRenderer; 155audio.createAudioRenderer(audioRendererOptions).then((data) => { 156 audioRenderer = data; 157 console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS'); 158}).catch((err) => { 159 console.error(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR : ${err}`); 160}); 161``` 162 163## audio.createAudioCapturer<sup>8+</sup> 164 165createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void 166 167Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result. 168 169**System capability**: SystemCapability.Multimedia.Audio.Capturer 170 171**Required permissions**: ohos.permission.MICROPHONE 172 173**Parameters** 174 175| Name | Type | Mandatory| Description | 176| :------- | :---------------------------------------------- | :--- | :--------------- | 177| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.| 178| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the **AudioCapturer** instance.| 179 180**Example** 181 182```js 183import audio from '@ohos.multimedia.audio'; 184let audioStreamInfo = { 185 samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, 186 channels: audio.AudioChannel.CHANNEL_2, 187 sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, 188 encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW 189} 190 191let audioCapturerInfo = { 192 source: audio.SourceType.SOURCE_TYPE_MIC, 193 capturerFlags: 0 194} 195 196let audioCapturerOptions = { 197 streamInfo: audioStreamInfo, 198 capturerInfo: audioCapturerInfo 199} 200 201audio.createAudioCapturer(audioCapturerOptions, (err, data) => { 202 if (err) { 203 console.error(`AudioCapturer Created : Error: ${err}`); 204 } else { 205 console.info('AudioCapturer Created : Success : SUCCESS'); 206 let audioCapturer = data; 207 } 208}); 209``` 210 211## audio.createAudioCapturer<sup>8+</sup> 212 213createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> 214 215Creates an **AudioCapturer** instance. This API uses a promise to return the result. 216 217**System capability**: SystemCapability.Multimedia.Audio.Capturer 218 219**Required permissions**: ohos.permission.MICROPHONE 220 221**Parameters** 222 223| Name | Type | Mandatory| Description | 224| :------ | :--------------------------------------------- | :--- | :--------------- | 225| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.| 226 227**Return value** 228 229| Type | Description | 230| ----------------------------------------- | -------------- | 231| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.| 232 233**Example** 234 235```js 236import audio from '@ohos.multimedia.audio'; 237 238let audioStreamInfo = { 239 samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, 240 channels: audio.AudioChannel.CHANNEL_2, 241 sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, 242 encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW 243} 244 245let audioCapturerInfo = { 246 source: audio.SourceType.SOURCE_TYPE_MIC, 247 capturerFlags: 0 248} 249 250let audioCapturerOptions = { 251 streamInfo: audioStreamInfo, 252 capturerInfo: audioCapturerInfo 253} 254 255let audioCapturer; 256audio.createAudioCapturer(audioCapturerOptions).then((data) => { 257 audioCapturer = data; 258 console.info('AudioCapturer Created : Success : Stream Type: SUCCESS'); 259}).catch((err) => { 260 console.error(`AudioCapturer Created : ERROR : ${err}`); 261}); 262``` 263 264## audio.createTonePlayer<sup>9+</sup> 265 266createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback<TonePlayer>): void 267 268Creates a **TonePlayer** instance. This API uses an asynchronous callback to return the result. 269 270**System capability**: SystemCapability.Multimedia.Audio.Tone 271 272**System API**: This is a system API. 273 274**Parameters** 275 276| Name | Type | Mandatory| Description | 277| -------- | ----------------------------------------------- | ---- | -------------- | 278| options | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.| 279| callback | AsyncCallback<[TonePlayer](#toneplayer9)> | Yes | Callback used to return the **TonePlayer** instance.| 280 281**Example** 282 283```js 284import audio from '@ohos.multimedia.audio'; 285 286let audioRendererInfo = { 287 content : audio.ContentType.CONTENT_TYPE_SONIFICATION, 288 usage : audio.StreamUsage.STREAM_USAGE_MEDIA, 289 rendererFlags : 0 290} 291let tonePlayer; 292 293audio.createTonePlayer(audioRendererInfo, (err, data) => { 294 console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`); 295 if (err) { 296 console.error(`callback call createTonePlayer return error: ${err.message}`); 297 } else { 298 console.info(`callback call createTonePlayer return data: ${data}`); 299 tonePlayer = data; 300 } 301}); 302``` 303 304## audio.createTonePlayer<sup>9+</sup> 305 306createTonePlayer(options: AudioRendererInfo): Promise<TonePlayer> 307 308Creates a **TonePlayer** instance. This API uses a promise to return the result. 309 310**System capability**: SystemCapability.Multimedia.Audio.Tone 311 312**System API**: This is a system API. 313 314**Parameters** 315 316| Name | Type | Mandatory| Description | 317| :------ | :---------------------------------------------| :--- | :----------- | 318| options | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.| 319 320**Return value** 321 322| Type | Description | 323| ----------------------------------------- | -------------------------------- | 324| Promise<[TonePlayer](#toneplayer9)> | Promise used to return the **TonePlayer** instance. | 325 326**Example** 327 328```js 329import audio from '@ohos.multimedia.audio'; 330let tonePlayer; 331async function createTonePlayerBefore(){ 332 let audioRendererInfo = { 333 content : audio.ContentType.CONTENT_TYPE_SONIFICATION, 334 usage : audio.StreamUsage.STREAM_USAGE_MEDIA, 335 rendererFlags : 0 336 } 337 tonePlayer = await audio.createTonePlayer(audioRendererInfo); 338} 339``` 340 341## AudioVolumeType 342 343Enumerates the audio stream types. 344 345**System capability**: SystemCapability.Multimedia.Audio.Volume 346 347| Name | Value | Description | 348| ---------------------------- | ------ | ---------- | 349| VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls.| 350| RINGTONE | 2 | Audio stream for ringtones. | 351| MEDIA | 3 | Audio stream for media purpose. | 352| VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant.| 353| ALL<sup>9+</sup> | 100 | All public audio streams.<br>This is a system API.| 354 355## InterruptRequestResultType<sup>9+</sup> 356 357Enumerates the result types of audio interruption requests. 358 359**System capability**: SystemCapability.Multimedia.Audio.Interrupt 360 361**System API**: This is a system API. 362 363| Name | Value | Description | 364| ---------------------------- | ------ | ---------- | 365| INTERRUPT_REQUEST_GRANT | 0 | The audio interruption request is accepted.| 366| INTERRUPT_REQUEST_REJECT | 1 | The audio interruption request is denied. There may be a stream with a higher priority.| 367 368## InterruptMode<sup>9+</sup> 369 370Enumerates the audio interruption modes. 371 372**System capability**: SystemCapability.Multimedia.Audio.Interrupt 373 374| Name | Value | Description | 375| ---------------------------- | ------ | ---------- | 376| SHARE_MODE | 0 | Shared mode.| 377| INDEPENDENT_MODE | 1 | Independent mode.| 378 379## DeviceFlag 380 381Enumerates the audio device flags. 382 383**System capability**: SystemCapability.Multimedia.Audio.Device 384 385| Name | Value | Description | 386| ------------------------------- | ------ | ------------------------------------------------- | 387| NONE_DEVICES_FLAG<sup>9+</sup> | 0 | No device.<br>This is a system API. | 388| OUTPUT_DEVICES_FLAG | 1 | Output device.| 389| INPUT_DEVICES_FLAG | 2 | Input device.| 390| ALL_DEVICES_FLAG | 3 | All devices.| 391| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4 | Distributed output device.<br>This is a system API. | 392| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup> | 8 | Distributed input device.<br>This is a system API. | 393| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup> | 12 | Distributed input and output device.<br>This is a system API. | 394 395## DeviceRole 396 397Enumerates the audio device roles. 398 399**System capability**: SystemCapability.Multimedia.Audio.Device 400 401| Name | Value | Description | 402| ------------- | ------ | -------------- | 403| INPUT_DEVICE | 1 | Input role.| 404| OUTPUT_DEVICE | 2 | Output role.| 405 406## DeviceType 407 408Enumerates the audio device types. 409 410**System capability**: SystemCapability.Multimedia.Audio.Device 411 412| Name | Value | Description | 413| ---------------------| ------ | --------------------------------------------------------- | 414| INVALID | 0 | Invalid device. | 415| EARPIECE | 1 | Earpiece. | 416| SPEAKER | 2 | Speaker. | 417| WIRED_HEADSET | 3 | Wired headset with a microphone. | 418| WIRED_HEADPHONES | 4 | Wired headset without microphone. | 419| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | 420| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.| 421| MIC | 15 | Microphone. | 422| USB_HEADSET | 22 | USB Type-C headset. | 423| DEFAULT<sup>9+</sup> | 1000 | Default device type. | 424 425## CommunicationDeviceType<sup>9+</sup> 426 427Enumerates the device types used for communication. 428 429**System capability**: SystemCapability.Multimedia.Audio.Communication 430 431| Name | Value | Description | 432| ------------- | ------ | -------------| 433| SPEAKER | 2 | Speaker. | 434 435## AudioRingMode 436 437Enumerates the ringer modes. 438 439**System capability**: SystemCapability.Multimedia.Audio.Communication 440 441| Name | Value | Description | 442| ------------------- | ------ | ---------- | 443| RINGER_MODE_SILENT | 0 | Silent mode.| 444| RINGER_MODE_VIBRATE | 1 | Vibration mode.| 445| RINGER_MODE_NORMAL | 2 | Normal mode.| 446 447## AudioSampleFormat<sup>8+</sup> 448 449Enumerates the audio sample formats. 450 451**System capability**: SystemCapability.Multimedia.Audio.Core 452 453| Name | Value | Description | 454| ---------------------------------- | ------ | -------------------------- | 455| SAMPLE_FORMAT_INVALID | -1 | Invalid format. | 456| SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. | 457| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.| 458| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.| 459| SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.| 460| SAMPLE_FORMAT_F32LE<sup>9+</sup> | 4 | Signed 32-bit floating point number, little endian.<br>Due to system restrictions, only some devices support this sampling format.| 461 462## AudioErrors<sup>9+</sup> 463 464Enumerates the audio error codes. 465 466**System capability**: SystemCapability.Multimedia.Audio.Core 467 468| Name | Value | Description | 469| ---------------------| --------| ----------------- | 470| ERROR_INVALID_PARAM | 6800101 | Invalid parameter. | 471| ERROR_NO_MEMORY | 6800102 | Memory allocation failure. | 472| ERROR_ILLEGAL_STATE | 6800103 | Unsupported state. | 473| ERROR_UNSUPPORTED | 6800104 | Unsupported parameter value. | 474| ERROR_TIMEOUT | 6800105 | Processing timeout. | 475| ERROR_STREAM_LIMIT | 6800201 | Too many audio streams.| 476| ERROR_SYSTEM | 6800301 | System error. | 477 478## AudioChannel<sup>8+</sup> 479 480Enumerates the audio channels. 481 482**System capability**: SystemCapability.Multimedia.Audio.Core 483 484| Name | Value | Description | 485| --------- | -------- | -------- | 486| CHANNEL_1 | 0x1 << 0 | Mono.| 487| CHANNEL_2 | 0x1 << 1 | Dual-channel.| 488 489## AudioSamplingRate<sup>8+</sup> 490 491Enumerates the audio sampling rates. The sampling rates supported vary according to the device in use. 492 493**System capability**: SystemCapability.Multimedia.Audio.Core 494 495| Name | Value | Description | 496| ----------------- | ------ | --------------- | 497| SAMPLE_RATE_8000 | 8000 | The sampling rate is 8000. | 498| SAMPLE_RATE_11025 | 11025 | The sampling rate is 11025.| 499| SAMPLE_RATE_12000 | 12000 | The sampling rate is 12000.| 500| SAMPLE_RATE_16000 | 16000 | The sampling rate is 16000.| 501| SAMPLE_RATE_22050 | 22050 | The sampling rate is 22050.| 502| SAMPLE_RATE_24000 | 24000 | The sampling rate is 24000.| 503| SAMPLE_RATE_32000 | 32000 | The sampling rate is 32000.| 504| SAMPLE_RATE_44100 | 44100 | The sampling rate is 44100.| 505| SAMPLE_RATE_48000 | 48000 | The sampling rate is 48000.| 506| SAMPLE_RATE_64000 | 64000 | The sampling rate is 64000.| 507| SAMPLE_RATE_96000 | 96000 | The sampling rate is 96000.| 508 509## AudioEncodingType<sup>8+</sup> 510 511Enumerates the audio encoding types. 512 513**System capability**: SystemCapability.Multimedia.Audio.Core 514 515| Name | Value | Description | 516| --------------------- | ------ | --------- | 517| ENCODING_TYPE_INVALID | -1 | Invalid. | 518| ENCODING_TYPE_RAW | 0 | PCM encoding.| 519 520## ContentType 521 522Enumerates the audio content types. 523 524**System capability**: SystemCapability.Multimedia.Audio.Core 525 526| Name | Value | Description | 527| ---------------------------------- | ------ | ---------- | 528| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.| 529| CONTENT_TYPE_SPEECH | 1 | Speech. | 530| CONTENT_TYPE_MUSIC | 2 | Music. | 531| CONTENT_TYPE_MOVIE | 3 | Movie. | 532| CONTENT_TYPE_SONIFICATION | 4 | Notification tone. | 533| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone. | 534 535## StreamUsage 536 537Enumerates the audio stream usage. 538 539**System capability**: SystemCapability.Multimedia.Audio.Core 540 541| Name | Value | Description | 542| ------------------------------------------| ------ | ---------- | 543| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.| 544| STREAM_USAGE_MEDIA | 1 | Used for media. | 545| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.| 546| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3 | Used for voice assistant.| 547| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.| 548 549## InterruptRequestType<sup>9+</sup> 550 551Enumerates the audio interruption request types. 552 553**System API**: This is a system API. 554 555**System capability**: SystemCapability.Multimedia.Audio.Interrupt 556 557| Name | Value | Description | 558| ---------------------------------- | ------ | ------------------------- | 559| INTERRUPT_REQUEST_TYPE_DEFAULT | 0 | Default type, which can be used to interrupt audio requests. | 560 561## AudioState<sup>8+</sup> 562 563Enumerates the audio states. 564 565**System capability**: SystemCapability.Multimedia.Audio.Core 566 567| Name | Value | Description | 568| -------------- | ------ | ---------------- | 569| STATE_INVALID | -1 | Invalid state. | 570| STATE_NEW | 0 | Creating instance state.| 571| STATE_PREPARED | 1 | Prepared. | 572| STATE_RUNNING | 2 | Running. | 573| STATE_STOPPED | 3 | Stopped. | 574| STATE_RELEASED | 4 | Released. | 575| STATE_PAUSED | 5 | Paused. | 576 577## AudioRendererRate<sup>8+</sup> 578 579Enumerates the audio renderer rates. 580 581**System capability**: SystemCapability.Multimedia.Audio.Renderer 582 583| Name | Value | Description | 584| ------------------ | ------ | ---------- | 585| RENDER_RATE_NORMAL | 0 | Normal rate.| 586| RENDER_RATE_DOUBLE | 1 | Double rate. | 587| RENDER_RATE_HALF | 2 | Half rate. | 588 589## InterruptType 590 591Enumerates the audio interruption types. 592 593**System capability**: SystemCapability.Multimedia.Audio.Renderer 594 595| Name | Value | Description | 596| -------------------- | ------ | ---------------------- | 597| INTERRUPT_TYPE_BEGIN | 1 | Audio interruption started.| 598| INTERRUPT_TYPE_END | 2 | Audio interruption ended.| 599 600## InterruptForceType<sup>9+</sup> 601 602Enumerates the types of force that causes audio interruption. 603 604**System capability**: SystemCapability.Multimedia.Audio.Renderer 605 606| Name | Value | Description | 607| --------------- | ------ | ------------------------------------ | 608| INTERRUPT_FORCE | 0 | Forced action taken by the system. | 609| INTERRUPT_SHARE | 1 | The application can choose to take action or ignore.| 610 611## InterruptHint 612 613Enumerates the hints provided along with audio interruption. 614 615**System capability**: SystemCapability.Multimedia.Audio.Renderer 616 617| Name | Value | Description | 618| ---------------------------------- | ------ | -------------------------------------------- | 619| INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. | 620| INTERRUPT_HINT_RESUME | 1 | Resume the playback. | 621| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. | 622| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. | 623| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)| 624| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. | 625 626## AudioStreamInfo<sup>8+</sup> 627 628Describes audio stream information. 629 630**System capability**: SystemCapability.Multimedia.Audio.Core 631 632| Name | Type | Mandatory| Description | 633| ------------ | ------------------------------------------------- | ---- | ------------------ | 634| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Audio sampling rate.| 635| channels | [AudioChannel](#audiochannel8) | Yes | Number of audio channels.| 636| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. | 637| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. | 638 639## AudioRendererInfo<sup>8+</sup> 640 641Describes audio renderer information. 642 643**System capability**: SystemCapability.Multimedia.Audio.Core 644 645| Name | Type | Mandatory | Description | 646| ------------- | --------------------------- | ---- | ---------------- | 647| content | [ContentType](#contenttype) | Yes | Audio content type. | 648| usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.| 649| rendererFlags | number | Yes | Audio renderer flags.| 650 651## InterruptResult<sup>9+</sup> 652 653Describes the audio interruption result. 654 655**System capability**: SystemCapability.Multimedia.Audio.Interrupt 656 657**System API**: This is a system API. 658 659| Name | Type | Mandatory| Description | 660| --------------| -------------------------------------------------------------- | ---- | ---------------- | 661| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9) | Yes | Audio interruption request type.| 662| interruptNode | number | Yes | Node to interrupt.| 663 664## AudioRendererOptions<sup>8+</sup> 665 666Describes audio renderer configurations. 667 668**System capability**: SystemCapability.Multimedia.Audio.Renderer 669 670| Name | Type | Mandatory | Description | 671| ------------ | ---------------------------------------- | ---- | ---------------- | 672| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.| 673| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.| 674 675## InterruptEvent<sup>9+</sup> 676 677Describes the interruption event received by the application when playback is interrupted. 678 679**System capability**: SystemCapability.Multimedia.Audio.Renderer 680 681| Name | Type |Mandatory | Description | 682| --------- | ------------------------------------------ | ---- | ------------------------------------ | 683| eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or ended. | 684| forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the interruption is taken by the system or to be taken by the application.| 685| hintType | [InterruptHint](#interrupthint) | Yes | Hint provided along the interruption. | 686 687## VolumeEvent<sup>8+</sup> 688 689Describes the event received by the application when the volume is changed. 690 691**System API**: This is a system API. 692 693**System capability**: SystemCapability.Multimedia.Audio.Volume 694 695| Name | Type | Mandatory | Description | 696| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 697| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 698| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| 699| updateUi | boolean | Yes | Whether to show the volume change in UI. | 700| volumeGroupId<sup>9+</sup> | number | Yes | Volume group ID. It can be used as an input parameter of **getGroupManager**. | 701| networkId<sup>9+</sup> | string | Yes | Network ID. | 702 703## MicStateChangeEvent<sup>9+</sup> 704 705Describes the event received by the application when the microphone mute status changes. 706 707**System capability**: SystemCapability.Multimedia.Audio.Device 708 709| Name | Type | Mandatory| Description | 710| ---------- | ----------------------------------- | ---- |-------------------------------------------------------- | 711| mute | boolean | Yes | Mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite. | 712 713## ConnectType<sup>9+</sup> 714 715Enumerates the types of connected devices. 716 717**System API**: This is a system API. 718 719**System capability**: SystemCapability.Multimedia.Audio.Volume 720 721| Name | Value | Description | 722| :------------------------------ | :----- | :--------------------- | 723| CONNECT_TYPE_LOCAL | 1 | Local device. | 724| CONNECT_TYPE_DISTRIBUTED | 2 | Distributed device. | 725 726## VolumeGroupInfos<sup>9+</sup> 727 728Describes the volume group information. The value is an array of [VolumeGroupInfo](#volumegroupinfo9) and is read-only. 729 730**System API**: This is a system API. 731 732**System capability**: SystemCapability.Multimedia.Audio.Volume 733 734## VolumeGroupInfo<sup>9+</sup> 735 736Describes the volume group information. 737 738**System API**: This is a system API. 739 740**System capability**: SystemCapability.Multimedia.Audio.Volume 741 742| Name | Type | Readable| Writable| Description | 743| -------------------------- | -------------------------- | ---- | ---- | ---------- | 744| networkId<sup>9+</sup> | string | Yes | No | Network ID of the device. | 745| groupId<sup>9+</sup> | number | Yes | No | Group ID of the device.| 746| mappingId<sup>9+</sup> | number | Yes | No | Group mapping ID.| 747| groupName<sup>9+</sup> | string | Yes | No | Group name.| 748| type<sup>9+</sup> | [ConnectType](#connecttype9)| Yes | No | Type of the connected device.| 749 750## DeviceChangeAction 751 752Describes the device connection status and device information. 753 754**System capability**: SystemCapability.Multimedia.Audio.Device 755 756| Name | Type | Mandatory| Description | 757| :---------------- | :------------------------------------------------ | :--- | :----------------- | 758| type | [DeviceChangeType](#devicechangetype) | Yes | Device connection status.| 759| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. | 760 761## DeviceChangeType 762 763Enumerates the device connection statuses. 764 765**System capability**: SystemCapability.Multimedia.Audio.Device 766 767| Name | Value | Description | 768| :--------- | :----- | :------------- | 769| CONNECT | 0 | Connected. | 770| DISCONNECT | 1 | Disconnected.| 771 772## AudioCapturerOptions<sup>8+</sup> 773 774Describes audio capturer configurations. 775 776**System capability**: SystemCapability.Multimedia.Audio.Capturer 777 778| Name | Type | Mandatory| Description | 779| ------------ | --------------------------------------- | ---- | ---------------- | 780| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.| 781| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes | Audio capturer information.| 782 783## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a> 784 785Describes audio capturer information. 786 787**System capability**: SystemCapability.Multimedia.Audio.Core 788 789| Name | Type | Mandatory| Description | 790| :------------ | :------------------------ | :--- | :--------------- | 791| source | [SourceType](#sourcetype) | Yes | Audio source type. | 792| capturerFlags | number | Yes | Audio capturer flags.| 793 794## SourceType<sup>8+</sup><a name="sourcetype"></a> 795 796Enumerates the audio source types. 797 798**System capability**: SystemCapability.Multimedia.Audio.Core 799 800| Name | Value | Description | 801| :------------------------------------------- | :----- | :--------------------- | 802| SOURCE_TYPE_INVALID | -1 | Invalid audio source. | 803| SOURCE_TYPE_MIC | 0 | Mic source. | 804| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup> | 1 | Voice recognition source. | 805| SOURCE_TYPE_VOICE_COMMUNICATION | 7 | Voice communication source.| 806 807## AudioScene<sup>8+</sup><a name="audioscene"></a> 808 809Enumerates the audio scenes. 810 811**System capability**: SystemCapability.Multimedia.Audio.Communication 812 813| Name | Value | Description | 814| :--------------------- | :----- | :-------------------------------------------- | 815| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. | 816| AUDIO_SCENE_RINGING | 1 | Ringing audio scene.<br>This is a system API.| 817| AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API.| 818| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | 819 820## AudioManager 821 822Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance. 823 824### setAudioParameter 825 826setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void 827 828Sets an audio parameter. This API uses an asynchronous callback to return the result. 829 830This 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. 831 832**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS 833 834**System capability**: SystemCapability.Multimedia.Audio.Core 835 836**Parameters** 837 838| Name | Type | Mandatory| Description | 839| -------- | ------------------------- | ---- | ------------------------ | 840| key | string | Yes | Key of the audio parameter to set. | 841| value | string | Yes | Value of the audio parameter to set. | 842| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 843 844**Example** 845 846```js 847audioManager.setAudioParameter('key_example', 'value_example', (err) => { 848 if (err) { 849 console.error(`Failed to set the audio parameter. ${err}`); 850 return; 851 } 852 console.info('Callback invoked to indicate a successful setting of the audio parameter.'); 853}); 854``` 855 856### setAudioParameter 857 858setAudioParameter(key: string, value: string): Promise<void> 859 860Sets an audio parameter. This API uses a promise to return the result. 861 862This 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. 863 864**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS 865 866**System capability**: SystemCapability.Multimedia.Audio.Core 867 868**Parameters** 869 870| Name| Type | Mandatory| Description | 871| ------ | ------ | ---- | ---------------------- | 872| key | string | Yes | Key of the audio parameter to set.| 873| value | string | Yes | Value of the audio parameter to set.| 874 875**Return value** 876 877| Type | Description | 878| ------------------- | ------------------------------- | 879| Promise<void> | Promise used to return the result.| 880 881**Example** 882 883```js 884audioManager.setAudioParameter('key_example', 'value_example').then(() => { 885 console.info('Promise returned to indicate a successful setting of the audio parameter.'); 886}); 887``` 888 889### getAudioParameter 890 891getAudioParameter(key: string, callback: AsyncCallback<string>): void 892 893Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result. 894 895This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only. 896 897**System capability**: SystemCapability.Multimedia.Audio.Core 898 899**Parameters** 900 901| Name | Type | Mandatory| Description | 902| -------- | --------------------------- | ---- | ---------------------------- | 903| key | string | Yes | Key of the audio parameter whose value is to be obtained. | 904| callback | AsyncCallback<string> | Yes | Callback used to return the value of the audio parameter.| 905 906**Example** 907 908```js 909audioManager.getAudioParameter('key_example', (err, value) => { 910 if (err) { 911 console.error(`Failed to obtain the value of the audio parameter. ${err}`); 912 return; 913 } 914 console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`); 915}); 916``` 917 918### getAudioParameter 919 920getAudioParameter(key: string): Promise<string> 921 922Obtains the value of an audio parameter. This API uses a promise to return the result. 923 924This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and can be obtained from the device manual. The example below is for reference only. 925 926**System capability**: SystemCapability.Multimedia.Audio.Core 927 928**Parameters** 929 930| Name| Type | Mandatory| Description | 931| ------ | ------ | ---- | ---------------------- | 932| key | string | Yes | Key of the audio parameter whose value is to be obtained.| 933 934**Return value** 935 936| Type | Description | 937| --------------------- | ----------------------------------- | 938| Promise<string> | Promise used to return the value of the audio parameter.| 939 940**Example** 941 942```js 943audioManager.getAudioParameter('key_example').then((value) => { 944 console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`); 945}); 946``` 947 948### setAudioScene<sup>8+</sup> 949 950setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void 951 952Sets an audio scene. This API uses an asynchronous callback to return the result. 953 954**System API**: This is a system API. 955 956**System capability**: SystemCapability.Multimedia.Audio.Communication 957 958**Parameters** 959 960| Name | Type | Mandatory| Description | 961| :------- | :----------------------------------- | :--- | :------------------- | 962| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set. | 963| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| 964 965**Example** 966 967```js 968audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { 969 if (err) { 970 console.error(`Failed to set the audio scene mode. ${err}`); 971 return; 972 } 973 console.info('Callback invoked to indicate a successful setting of the audio scene mode.'); 974}); 975``` 976 977### setAudioScene<sup>8+</sup> 978 979setAudioScene\(scene: AudioScene\): Promise<void\> 980 981Sets an audio scene. This API uses a promise to return the result. 982 983**System API**: This is a system API. 984 985**System capability**: SystemCapability.Multimedia.Audio.Communication 986 987**Parameters** 988 989| Name| Type | Mandatory| Description | 990| :----- | :----------------------------------- | :--- | :------------- | 991| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set.| 992 993**Return value** 994 995| Type | Description | 996| :------------- | :------------------- | 997| Promise<void\> | Promise used to return the result.| 998 999**Example** 1000 1001```js 1002audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => { 1003 console.info('Promise returned to indicate a successful setting of the audio scene mode.'); 1004}).catch ((err) => { 1005 console.error(`Failed to set the audio scene mode ${err}`); 1006}); 1007``` 1008 1009### getAudioScene<sup>8+</sup> 1010 1011getAudioScene\(callback: AsyncCallback<AudioScene\>\): void 1012 1013Obtains the audio scene. This API uses an asynchronous callback to return the result. 1014 1015**System capability**: SystemCapability.Multimedia.Audio.Communication 1016 1017**Parameters** 1018 1019| Name | Type | Mandatory| Description | 1020| :------- | :-------------------------------------------------- | :--- | :--------------------------- | 1021| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene.| 1022 1023**Example** 1024 1025```js 1026audioManager.getAudioScene((err, value) => { 1027 if (err) { 1028 console.error(`Failed to obtain the audio scene mode. ${err}`); 1029 return; 1030 } 1031 console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`); 1032}); 1033``` 1034 1035### getAudioScene<sup>8+</sup> 1036 1037getAudioScene\(\): Promise<AudioScene\> 1038 1039Obtains the audio scene. This API uses a promise to return the result. 1040 1041**System capability**: SystemCapability.Multimedia.Audio.Communication 1042 1043**Return value** 1044 1045| Type | Description | 1046| :-------------------------------------------- | :--------------------------- | 1047| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.| 1048 1049**Example** 1050 1051```js 1052audioManager.getAudioScene().then((value) => { 1053 console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`); 1054}).catch ((err) => { 1055 console.error(`Failed to obtain the audio scene mode ${err}`); 1056}); 1057``` 1058 1059### getVolumeManager<sup>9+</sup> 1060 1061getVolumeManager(): AudioVolumeManager 1062 1063Obtains an **AudioVolumeManager** instance. 1064 1065**System capability**: SystemCapability.Multimedia.Audio.Volume 1066 1067**Example** 1068 1069```js 1070let audioVolumeManager = audioManager.getVolumeManager(); 1071``` 1072 1073### getStreamManager<sup>9+</sup> 1074 1075getStreamManager(): AudioStreamManager 1076 1077Obtains an **AudioStreamManager** instance. 1078 1079**System capability**: SystemCapability.Multimedia.Audio.Core 1080 1081**Example** 1082 1083```js 1084let audioStreamManager = audioManager.getStreamManager(); 1085``` 1086 1087### getRoutingManager<sup>9+</sup> 1088 1089getRoutingManager(): AudioRoutingManager 1090 1091Obtains an **AudioRoutingManager** instance. 1092 1093**System capability**: SystemCapability.Multimedia.Audio.Device 1094 1095**Example** 1096 1097```js 1098let audioRoutingManager = audioManager.getRoutingManager(); 1099``` 1100 1101### setVolume<sup>(deprecated)</sup> 1102 1103setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void 1104 1105Sets the volume for a stream. This API uses an asynchronous callback to return the result. 1106 1107> **NOTE** 1108> 1109> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. 1110 1111**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 1112 1113This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 1114 1115**System capability**: SystemCapability.Multimedia.Audio.Volume 1116 1117**Parameters** 1118 1119| Name | Type | Mandatory| Description | 1120| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 1121| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1122| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| 1123| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1124 1125**Example** 1126 1127```js 1128audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { 1129 if (err) { 1130 console.error(`Failed to set the volume. ${err}`); 1131 return; 1132 } 1133 console.info('Callback invoked to indicate a successful volume setting.'); 1134}); 1135``` 1136 1137### setVolume<sup>(deprecated)</sup> 1138 1139setVolume(volumeType: AudioVolumeType, volume: number): Promise<void> 1140 1141Sets the volume for a stream. This API uses a promise to return the result. 1142 1143> **NOTE** 1144> 1145> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setVolume](#setvolume9) in **AudioVolumeGroupManager**. 1146 1147**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 1148 1149This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 1150 1151**System capability**: SystemCapability.Multimedia.Audio.Volume 1152 1153**Parameters** 1154 1155| Name | Type | Mandatory| Description | 1156| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 1157| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1158| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| 1159 1160**Return value** 1161 1162| Type | Description | 1163| ------------------- | ----------------------------- | 1164| Promise<void> | Promise used to return the result.| 1165 1166**Example** 1167 1168```js 1169audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { 1170 console.info('Promise returned to indicate a successful volume setting.'); 1171}); 1172``` 1173 1174### getVolume<sup>(deprecated)</sup> 1175 1176getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 1177 1178Obtains the volume of a stream. This API uses an asynchronous callback to return the result. 1179 1180> **NOTE** 1181> 1182> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**. 1183 1184**System capability**: SystemCapability.Multimedia.Audio.Volume 1185 1186**Parameters** 1187 1188| Name | Type | Mandatory| Description | 1189| ---------- | ----------------------------------- | ---- | ------------------ | 1190| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1191| callback | AsyncCallback<number> | Yes | Callback used to return the volume.| 1192 1193**Example** 1194 1195```js 1196audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 1197 if (err) { 1198 console.error(`Failed to obtain the volume. ${err}`); 1199 return; 1200 } 1201 console.info('Callback invoked to indicate that the volume is obtained.'); 1202}); 1203``` 1204 1205### getVolume<sup>(deprecated)</sup> 1206 1207getVolume(volumeType: AudioVolumeType): Promise<number> 1208 1209Obtains the volume of a stream. This API uses a promise to return the result. 1210 1211> **NOTE** 1212> 1213> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getVolume](#getvolume9) in **AudioVolumeGroupManager**. 1214 1215**System capability**: SystemCapability.Multimedia.Audio.Volume 1216 1217**Parameters** 1218 1219| Name | Type | Mandatory| Description | 1220| ---------- | ----------------------------------- | ---- | ------------ | 1221| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 1222 1223**Return value** 1224 1225| Type | Description | 1226| --------------------- | ------------------------- | 1227| Promise<number> | Promise used to return the volume.| 1228 1229**Example** 1230 1231```js 1232audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { 1233 console.info(`Promise returned to indicate that the volume is obtained ${value} .`); 1234}); 1235``` 1236 1237### getMinVolume<sup>(deprecated)</sup> 1238 1239getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 1240 1241Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result. 1242 1243> **NOTE** 1244> 1245> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**. 1246 1247**System capability**: SystemCapability.Multimedia.Audio.Volume 1248 1249**Parameters** 1250 1251| Name | Type | Mandatory| Description | 1252| ---------- | ----------------------------------- | ---- | ------------------ | 1253| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1254| callback | AsyncCallback<number> | Yes | Callback used to return the minimum volume.| 1255 1256**Example** 1257 1258```js 1259audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 1260 if (err) { 1261 console.error(`Failed to obtain the minimum volume. ${err}`); 1262 return; 1263 } 1264 console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`); 1265}); 1266``` 1267 1268### getMinVolume<sup>(deprecated)</sup> 1269 1270getMinVolume(volumeType: AudioVolumeType): Promise<number> 1271 1272Obtains the minimum volume allowed for a stream. This API uses a promise to return the result. 1273 1274> **NOTE** 1275> 1276> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMinVolume](#getminvolume9) in **AudioVolumeGroupManager**. 1277 1278**System capability**: SystemCapability.Multimedia.Audio.Volume 1279 1280**Parameters** 1281 1282| Name | Type | Mandatory| Description | 1283| ---------- | ----------------------------------- | ---- | ------------ | 1284| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 1285 1286**Return value** 1287 1288| Type | Description | 1289| --------------------- | ------------------------- | 1290| Promise<number> | Promise used to return the minimum volume.| 1291 1292**Example** 1293 1294```js 1295audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { 1296 console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`); 1297}); 1298``` 1299 1300### getMaxVolume<sup>(deprecated)</sup> 1301 1302getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 1303 1304Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result. 1305 1306> **NOTE** 1307> 1308> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**. 1309 1310**System capability**: SystemCapability.Multimedia.Audio.Volume 1311 1312**Parameters** 1313 1314| Name | Type | Mandatory| Description | 1315| ---------- | ----------------------------------- | ---- | ---------------------- | 1316| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1317| callback | AsyncCallback<number> | Yes | Callback used to return the maximum volume.| 1318 1319**Example** 1320 1321```js 1322audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 1323 if (err) { 1324 console.error(`Failed to obtain the maximum volume. ${err}`); 1325 return; 1326 } 1327 console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`); 1328}); 1329``` 1330 1331### getMaxVolume<sup>(deprecated)</sup> 1332 1333getMaxVolume(volumeType: AudioVolumeType): Promise<number> 1334 1335Obtains the maximum volume allowed for a stream. This API uses a promise to return the result. 1336 1337> **NOTE** 1338> 1339> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getMaxVolume](#getmaxvolume9) in **AudioVolumeGroupManager**. 1340 1341**System capability**: SystemCapability.Multimedia.Audio.Volume 1342 1343**Parameters** 1344 1345| Name | Type | Mandatory| Description | 1346| ---------- | ----------------------------------- | ---- | ------------ | 1347| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 1348 1349**Return value** 1350 1351| Type | Description | 1352| --------------------- | ----------------------------- | 1353| Promise<number> | Promise used to return the maximum volume.| 1354 1355**Example** 1356 1357```js 1358audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { 1359 console.info('Promised returned to indicate that the maximum volume is obtained.'); 1360}); 1361``` 1362 1363### mute<sup>(deprecated)</sup> 1364 1365mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void 1366 1367Mutes or unmutes a stream. This API uses an asynchronous callback to return the result. 1368 1369> **NOTE** 1370> 1371> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. 1372 1373**System capability**: SystemCapability.Multimedia.Audio.Volume 1374 1375**Parameters** 1376 1377| Name | Type | Mandatory| Description | 1378| ---------- | ----------------------------------- | ---- | ------------------------------------- | 1379| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1380| mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.| 1381| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1382 1383**Example** 1384 1385```js 1386audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { 1387 if (err) { 1388 console.error(`Failed to mute the stream. ${err}`); 1389 return; 1390 } 1391 console.info('Callback invoked to indicate that the stream is muted.'); 1392}); 1393``` 1394 1395### mute<sup>(deprecated)</sup> 1396 1397mute(volumeType: AudioVolumeType, mute: boolean): Promise<void> 1398 1399Mutes or unmutes a stream. This API uses a promise to return the result. 1400 1401> **NOTE** 1402> 1403> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [mute](#mute9) in **AudioVolumeGroupManager**. 1404 1405**System capability**: SystemCapability.Multimedia.Audio.Volume 1406 1407**Parameters** 1408 1409| Name | Type | Mandatory| Description | 1410| ---------- | ----------------------------------- | ---- | ------------------------------------- | 1411| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1412| mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.| 1413 1414**Return value** 1415 1416| Type | Description | 1417| ------------------- | ----------------------------- | 1418| Promise<void> | Promise used to return the result.| 1419 1420**Example** 1421 1422 1423```js 1424audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { 1425 console.info('Promise returned to indicate that the stream is muted.'); 1426}); 1427``` 1428 1429### isMute<sup>(deprecated)</sup> 1430 1431isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 1432 1433Checks whether a stream is muted. This API uses an asynchronous callback to return the result. 1434 1435> **NOTE** 1436> 1437> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**. 1438 1439**System capability**: SystemCapability.Multimedia.Audio.Volume 1440 1441**Parameters** 1442 1443| Name | Type | Mandatory| Description | 1444| ---------- | ----------------------------------- | ---- | ----------------------------------------------- | 1445| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1446| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.| 1447 1448**Example** 1449 1450```js 1451audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { 1452 if (err) { 1453 console.error(`Failed to obtain the mute status. ${err}`); 1454 return; 1455 } 1456 console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`); 1457}); 1458``` 1459 1460### isMute<sup>(deprecated)</sup> 1461 1462isMute(volumeType: AudioVolumeType): Promise<boolean> 1463 1464Checks whether a stream is muted. This API uses a promise to return the result. 1465 1466> **NOTE** 1467> 1468> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMute](#ismute9) in **AudioVolumeGroupManager**. 1469 1470**System capability**: SystemCapability.Multimedia.Audio.Volume 1471 1472**Parameters** 1473 1474| Name | Type | Mandatory| Description | 1475| ---------- | ----------------------------------- | ---- | ------------ | 1476| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 1477 1478**Return value** 1479 1480| Type | Description | 1481| ---------------------- | ------------------------------------------------------ | 1482| Promise<boolean> | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.| 1483 1484**Example** 1485 1486```js 1487audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { 1488 console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`); 1489}); 1490``` 1491 1492### isActive<sup>(deprecated)</sup> 1493 1494isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 1495 1496Checks whether a stream is active. This API uses an asynchronous callback to return the result. 1497 1498> **NOTE** 1499> 1500> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**. 1501 1502**System capability**: SystemCapability.Multimedia.Audio.Volume 1503 1504**Parameters** 1505 1506| Name | Type | Mandatory| Description | 1507| ---------- | ----------------------------------- | ---- | ------------------------------------------------- | 1508| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 1509| callback | AsyncCallback<boolean> | 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.| 1510 1511**Example** 1512 1513```js 1514audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { 1515 if (err) { 1516 console.error(`Failed to obtain the active status of the stream. ${err}`); 1517 return; 1518 } 1519 console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`); 1520}); 1521``` 1522 1523### isActive<sup>(deprecated)</sup> 1524 1525isActive(volumeType: AudioVolumeType): Promise<boolean> 1526 1527Checks whether a stream is active. This API uses a promise to return the result. 1528 1529> **NOTE** 1530> 1531> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isActive](#isactive9) in **AudioStreamManager**. 1532 1533**System capability**: SystemCapability.Multimedia.Audio.Volume 1534 1535**Parameters** 1536 1537| Name | Type | Mandatory| Description | 1538| ---------- | ----------------------------------- | ---- | ------------ | 1539| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 1540 1541**Return value** 1542 1543| Type | Description | 1544| ---------------------- | -------------------------------------------------------- | 1545| Promise<boolean> | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.| 1546 1547**Example** 1548 1549```js 1550audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { 1551 console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`); 1552}); 1553``` 1554 1555### setRingerMode<sup>(deprecated)</sup> 1556 1557setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void 1558 1559Sets the ringer mode. This API uses an asynchronous callback to return the result. 1560 1561> **NOTE** 1562> 1563> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. 1564 1565**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 1566 1567This permission is required only for muting or unmuting the ringer. 1568 1569**System capability**: SystemCapability.Multimedia.Audio.Communication 1570 1571**Parameters** 1572 1573| Name | Type | Mandatory| Description | 1574| -------- | ------------------------------- | ---- | ------------------------ | 1575| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | 1576| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1577 1578**Example** 1579 1580```js 1581audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { 1582 if (err) { 1583 console.error(`Failed to set the ringer mode. ${err}`); 1584 return; 1585 } 1586 console.info('Callback invoked to indicate a successful setting of the ringer mode.'); 1587}); 1588``` 1589 1590### setRingerMode<sup>(deprecated)</sup> 1591 1592setRingerMode(mode: AudioRingMode): Promise<void> 1593 1594Sets the ringer mode. This API uses a promise to return the result. 1595 1596> **NOTE** 1597> 1598> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setRingerMode](#setringermode9) in **AudioVolumeGroupManager**. 1599 1600**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 1601 1602This permission is required only for muting or unmuting the ringer. 1603 1604**System capability**: SystemCapability.Multimedia.Audio.Communication 1605 1606**Parameters** 1607 1608| Name| Type | Mandatory| Description | 1609| ------ | ------------------------------- | ---- | -------------- | 1610| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.| 1611 1612**Return value** 1613 1614| Type | Description | 1615| ------------------- | ------------------------------- | 1616| Promise<void> | Promise used to return the result.| 1617 1618**Example** 1619 1620```js 1621audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { 1622 console.info('Promise returned to indicate a successful setting of the ringer mode.'); 1623}); 1624``` 1625 1626### getRingerMode<sup>(deprecated)</sup> 1627 1628getRingerMode(callback: AsyncCallback<AudioRingMode>): void 1629 1630Obtains the ringer mode. This API uses an asynchronous callback to return the result. 1631 1632> **NOTE** 1633> 1634> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**. 1635 1636**System capability**: SystemCapability.Multimedia.Audio.Communication 1637 1638**Parameters** 1639 1640| Name | Type | Mandatory| Description | 1641| -------- | ---------------------------------------------------- | ---- | ------------------------ | 1642| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode.| 1643 1644**Example** 1645 1646```js 1647audioManager.getRingerMode((err, value) => { 1648 if (err) { 1649 console.error(`Failed to obtain the ringer mode. ${err}`); 1650 return; 1651 } 1652 console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`); 1653}); 1654``` 1655 1656### getRingerMode<sup>(deprecated)</sup> 1657 1658getRingerMode(): Promise<AudioRingMode> 1659 1660Obtains the ringer mode. This API uses a promise to return the result. 1661 1662> **NOTE** 1663> 1664> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](#getringermode9) in **AudioVolumeGroupManager**. 1665 1666**System capability**: SystemCapability.Multimedia.Audio.Communication 1667 1668**Return value** 1669 1670| Type | Description | 1671| ---------------------------------------------- | ------------------------------- | 1672| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode.| 1673 1674**Example** 1675 1676```js 1677audioManager.getRingerMode().then((value) => { 1678 console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`); 1679}); 1680``` 1681 1682### getDevices<sup>(deprecated)</sup> 1683 1684getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void 1685 1686Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result. 1687 1688> **NOTE** 1689> 1690> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**. 1691 1692**System capability**: SystemCapability.Multimedia.Audio.Device 1693 1694**Parameters** 1695 1696| Name | Type | Mandatory| Description | 1697| ---------- | ------------------------------------------------------------ | ---- | -------------------- | 1698| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | 1699| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list.| 1700 1701**Example** 1702```js 1703audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { 1704 if (err) { 1705 console.error(`Failed to obtain the device list. ${err}`); 1706 return; 1707 } 1708 console.info('Callback invoked to indicate that the device list is obtained.'); 1709}); 1710``` 1711 1712### getDevices<sup>(deprecated)</sup> 1713 1714getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors> 1715 1716Obtains the audio devices with a specific flag. This API uses a promise to return the result. 1717 1718> **NOTE** 1719> 1720> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](#getdevices9) in **AudioRoutingManager**. 1721 1722**System capability**: SystemCapability.Multimedia.Audio.Device 1723 1724**Parameters** 1725 1726| Name | Type | Mandatory| Description | 1727| ---------- | ------------------------- | ---- | ---------------- | 1728| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.| 1729 1730**Return value** 1731 1732| Type | Description | 1733| ------------------------------------------------------------ | ------------------------- | 1734| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list.| 1735 1736**Example** 1737 1738```js 1739audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 1740 console.info('Promise returned to indicate that the device list is obtained.'); 1741}); 1742``` 1743 1744### setDeviceActive<sup>(deprecated)</sup> 1745 1746setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void 1747 1748Sets a device to the active state. This API uses an asynchronous callback to return the result. 1749 1750> **NOTE** 1751> 1752> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**. 1753 1754**System capability**: SystemCapability.Multimedia.Audio.Device 1755 1756**Parameters** 1757 1758| Name | Type | Mandatory| Description | 1759| ---------- | ------------------------------------- | ---- | ------------------------ | 1760| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. | 1761| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. | 1762| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1763 1764**Example** 1765 1766```js 1767audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => { 1768 if (err) { 1769 console.error(`Failed to set the active status of the device. ${err}`); 1770 return; 1771 } 1772 console.info('Callback invoked to indicate that the device is set to the active status.'); 1773}); 1774``` 1775 1776### setDeviceActive<sup>(deprecated)</sup> 1777 1778setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void> 1779 1780Sets a device to the active state. This API uses a promise to return the result. 1781 1782> **NOTE** 1783> 1784> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](#setcommunicationdevice9) in **AudioRoutingManager**. 1785 1786**System capability**: SystemCapability.Multimedia.Audio.Device 1787 1788**Parameters** 1789 1790| Name | Type | Mandatory| Description | 1791| ---------- | ------------------------------------- | ---- | ------------------ | 1792| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type.| 1793| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. | 1794 1795**Return value** 1796 1797| Type | Description | 1798| ------------------- | ------------------------------- | 1799| Promise<void> | Promise used to return the result.| 1800 1801**Example** 1802 1803 1804```js 1805audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => { 1806 console.info('Promise returned to indicate that the device is set to the active status.'); 1807}); 1808``` 1809 1810### isDeviceActive<sup>(deprecated)</sup> 1811 1812isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): void 1813 1814Checks whether a device is active. This API uses an asynchronous callback to return the result. 1815 1816> **NOTE** 1817> 1818> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**. 1819 1820**System capability**: SystemCapability.Multimedia.Audio.Device 1821 1822**Parameters** 1823 1824| Name | Type | Mandatory| Description | 1825| ---------- | ------------------------------------- | ---- | ------------------------ | 1826| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type. | 1827| callback | AsyncCallback<boolean> | Yes | Callback used to return the active state of the device.| 1828 1829**Example** 1830 1831```js 1832audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => { 1833 if (err) { 1834 console.error(`Failed to obtain the active status of the device. ${err}`); 1835 return; 1836 } 1837 console.info('Callback invoked to indicate that the active status of the device is obtained.'); 1838}); 1839``` 1840 1841### isDeviceActive<sup>(deprecated)</sup> 1842 1843isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean> 1844 1845Checks whether a device is active. This API uses a promise to return the result. 1846 1847> **NOTE** 1848> 1849> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](#iscommunicationdeviceactive9) in **AudioRoutingManager**. 1850 1851**System capability**: SystemCapability.Multimedia.Audio.Device 1852 1853**Parameters** 1854 1855| Name | Type | Mandatory| Description | 1856| ---------- | ------------------------------------- | ---- | ------------------ | 1857| deviceType | [ActiveDeviceType](#activedevicetypedeprecated) | Yes | Active audio device type.| 1858 1859**Return value** 1860 1861| Type | Description | 1862| ---------------------- | ------------------------------- | 1863| Promise<boolean> | Promise used to return the active state of the device.| 1864 1865**Example** 1866 1867```js 1868audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => { 1869 console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`); 1870}); 1871``` 1872 1873### setMicrophoneMute<sup>(deprecated)</sup> 1874 1875setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void 1876 1877Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. 1878 1879> **NOTE** 1880> 1881> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**. 1882 1883**Required permissions**: ohos.permission.MICROPHONE 1884 1885**System capability**: SystemCapability.Multimedia.Audio.Device 1886 1887**Parameters** 1888 1889| Name | Type | Mandatory| Description | 1890| -------- | ------------------------- | ---- | --------------------------------------------- | 1891| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 1892| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 1893 1894**Example** 1895 1896```js 1897audioManager.setMicrophoneMute(true, (err) => { 1898 if (err) { 1899 console.error(`Failed to mute the microphone. ${err}`); 1900 return; 1901 } 1902 console.info('Callback invoked to indicate that the microphone is muted.'); 1903}); 1904``` 1905 1906### setMicrophoneMute<sup>(deprecated)</sup> 1907 1908setMicrophoneMute(mute: boolean): Promise<void> 1909 1910Mutes or unmutes the microphone. This API uses a promise to return the result. 1911 1912> **NOTE** 1913> 1914> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setMicrophoneMute](#setmicrophonemute9) in **AudioVolumeGroupManager**. 1915 1916**Required permissions**: ohos.permission.MICROPHONE 1917 1918**System capability**: SystemCapability.Multimedia.Audio.Device 1919 1920**Parameters** 1921 1922| Name| Type | Mandatory| Description | 1923| ------ | ------- | ---- | --------------------------------------------- | 1924| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 1925 1926**Return value** 1927 1928| Type | Description | 1929| ------------------- | ------------------------------- | 1930| Promise<void> | Promise used to return the result.| 1931 1932**Example** 1933 1934```js 1935audioManager.setMicrophoneMute(true).then(() => { 1936 console.info('Promise returned to indicate that the microphone is muted.'); 1937}); 1938``` 1939 1940### isMicrophoneMute<sup>(deprecated)</sup> 1941 1942isMicrophoneMute(callback: AsyncCallback<boolean>): void 1943 1944Checks whether the microphone is muted. This API uses an asynchronous callback to return the result. 1945 1946> **NOTE** 1947> 1948> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**. 1949 1950**Required permissions**: ohos.permission.MICROPHONE 1951 1952**System capability**: SystemCapability.Multimedia.Audio.Device 1953 1954**Parameters** 1955 1956| Name | Type | Mandatory| Description | 1957| -------- | ---------------------------- | ---- | ------------------------------------------------------- | 1958| callback | AsyncCallback<boolean> | 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.| 1959 1960**Example** 1961 1962```js 1963audioManager.isMicrophoneMute((err, value) => { 1964 if (err) { 1965 console.error(`Failed to obtain the mute status of the microphone. ${err}`); 1966 return; 1967 } 1968 console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`); 1969}); 1970``` 1971 1972### isMicrophoneMute<sup>(deprecated)</sup> 1973 1974isMicrophoneMute(): Promise<boolean> 1975 1976Checks whether the microphone is muted. This API uses a promise to return the result. 1977 1978> **NOTE** 1979> 1980> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](#ismicrophonemute9) in **AudioVolumeGroupManager**. 1981 1982**Required permissions**: ohos.permission.MICROPHONE 1983 1984**System capability**: SystemCapability.Multimedia.Audio.Device 1985 1986**Return value** 1987 1988| Type | Description | 1989| ---------------------- | ------------------------------------------------------------ | 1990| Promise<boolean> | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.| 1991 1992**Example** 1993 1994```js 1995audioManager.isMicrophoneMute().then((value) => { 1996 console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`); 1997}); 1998``` 1999 2000### on('volumeChange')<sup>(deprecated)</sup> 2001 2002on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void 2003 2004> **NOTE** 2005> 2006> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioVolumeManager**. 2007 2008Subscribes to system volume change events. 2009 2010**System API**: This is a system API. 2011 2012Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance. 2013 2014**System capability**: SystemCapability.Multimedia.Audio.Volume 2015 2016**Parameters** 2017 2018| Name | Type | Mandatory| Description | 2019| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 2020| type | string | Yes | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when a system volume change is detected.| 2021| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to return the system volume change event. | 2022 2023**Example** 2024 2025```js 2026audioManager.on('volumeChange', (volumeEvent) => { 2027 console.info(`VolumeType of stream: ${volumeEvent.volumeType} `); 2028 console.info(`Volume level: ${volumeEvent.volume} `); 2029 console.info(`Whether to updateUI: ${volumeEvent.updateUi} `); 2030}); 2031``` 2032 2033### on('ringerModeChange')<sup>(deprecated)</sup> 2034 2035on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void 2036 2037Subscribes to ringer mode change events. 2038 2039> **NOTE** 2040> 2041> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('ringerModeChange')](#onringermodechange9) in **AudioVolumeGroupManager**. 2042 2043**System API**: This is a system API. 2044 2045**System capability**: SystemCapability.Multimedia.Audio.Communication 2046 2047**Parameters** 2048 2049| Name | Type | Mandatory| Description | 2050| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | 2051| type | string | Yes | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected.| 2052| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode change event. | 2053 2054**Example** 2055 2056```js 2057audioManager.on('ringerModeChange', (ringerMode) => { 2058 console.info(`Updated ringermode: ${ringerMode}`); 2059}); 2060``` 2061 2062### on('deviceChange')<sup>(deprecated)</sup> 2063 2064on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void 2065 2066Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback. 2067 2068> **NOTE** 2069> 2070> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on](#on9) in **AudioRoutingManager**. 2071 2072**System capability**: SystemCapability.Multimedia.Audio.Device 2073 2074**Parameters** 2075 2076| Name | Type | Mandatory| Description | 2077| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- | 2078| type | string | Yes | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.| 2079| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes | Callback used to return the device update details. | 2080 2081**Example** 2082 2083```js 2084audioManager.on('deviceChange', (deviceChanged) => { 2085 console.info(`device change type : ${deviceChanged.type} `); 2086 console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `); 2087 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `); 2088 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `); 2089}); 2090``` 2091 2092### off('deviceChange')<sup>(deprecated)</sup> 2093 2094off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void 2095 2096Unsubscribes from device change events. 2097 2098> **NOTE** 2099> 2100> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off](#off9) in **AudioRoutingManager**. 2101 2102**System capability**: SystemCapability.Multimedia.Audio.Device 2103 2104**Parameters** 2105 2106| Name | Type | Mandatory| Description | 2107| -------- | --------------------------------------------------- | ---- | ------------------------------------------ | 2108| type | string | Yes | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.| 2109| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to return the device update details. | 2110 2111**Example** 2112 2113```js 2114audioManager.off('deviceChange', (deviceChanged) => { 2115 console.info('Should be no callback.'); 2116}); 2117``` 2118 2119### on('interrupt')<sup>(deprecated)</sup> 2120 2121on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void 2122 2123Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback. 2124 2125Same as [on('audioInterrupt')](#onaudiointerrupt9), this API is used to listen for focus changes. However, this API is used in scenarios without audio streams (no **AudioRenderer** instance is created), such as frequency modulation (FM) and voice wakeup. 2126 2127> **NOTE** 2128> 2129> This API is supported since API version 7 and deprecated since API version 9. 2130 2131**System capability**: SystemCapability.Multimedia.Audio.Renderer 2132 2133**Parameters** 2134 2135| Name | Type | Mandatory| Description | 2136| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 2137| 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.| 2138| interrupt | AudioInterrupt | Yes | Audio interruption event type. | 2139| callback | Callback<[InterruptAction](#interruptactiondeprecated)> | Yes | Callback invoked for the audio interruption event. | 2140 2141**Example** 2142 2143```js 2144let interAudioInterrupt = { 2145 streamUsage:2, 2146 contentType:0, 2147 pauseWhenDucked:true 2148}; 2149audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { 2150 if (InterruptAction.actionType === 0) { 2151 console.info('An event to gain the audio focus starts.'); 2152 console.info(`Focus gain event: ${InterruptAction} `); 2153 } 2154 if (InterruptAction.actionType === 1) { 2155 console.info('An audio interruption event starts.'); 2156 console.info(`Audio interruption event: ${InterruptAction} `); 2157 } 2158}); 2159``` 2160 2161### off('interrupt')<sup>(deprecated)</sup> 2162 2163off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void 2164 2165Unsubscribes from audio interruption events. 2166 2167> **NOTE** 2168> 2169> This API is supported since API version 7 and deprecated since API version 9. 2170 2171**System capability**: SystemCapability.Multimedia.Audio.Renderer 2172 2173**Parameters** 2174 2175| Name | Type | Mandatory| Description | 2176| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 2177| 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.| 2178| interrupt | AudioInterrupt | Yes | Audio interruption event type. | 2179| callback | Callback<[InterruptAction](#interruptactiondeprecated)> | No | Callback invoked for the audio interruption event. | 2180 2181**Example** 2182 2183```js 2184let interAudioInterrupt = { 2185 streamUsage:2, 2186 contentType:0, 2187 pauseWhenDucked:true 2188}; 2189audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { 2190 if (InterruptAction.actionType === 0) { 2191 console.info('An event to release the audio focus starts.'); 2192 console.info(`Focus release event: ${InterruptAction} `); 2193 } 2194}); 2195``` 2196 2197## AudioVolumeManager<sup>9+</sup> 2198 2199Implements audio volume management. Before calling an API in **AudioVolumeManager**, you must use [getVolumeManager](#getvolumemanager9) to obtain an **AudioVolumeManager** instance. 2200 2201### getVolumeGroupInfos<sup>9+</sup> 2202 2203getVolumeGroupInfos(networkId: string, callback: AsyncCallback<VolumeGroupInfos\>\): void 2204 2205Obtains the volume groups. This API uses an asynchronous callback to return the result. 2206 2207**System API**: This is a system API. 2208 2209**System capability**: SystemCapability.Multimedia.Audio.Volume 2210 2211**Parameters** 2212 2213| Name | Type | Mandatory| Description | 2214| ---------- | ------------------------------------------------------------ | ---- | -------------------- | 2215| networkId | string | Yes | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**. | 2216| callback | AsyncCallback<[VolumeGroupInfos](#volumegroupinfos9)> | Yes | Callback used to return the volume group information array.| 2217 2218**Example** 2219```js 2220audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err, value) => { 2221 if (err) { 2222 console.error(`Failed to obtain the volume group infos list. ${err}`); 2223 return; 2224 } 2225 console.info('Callback invoked to indicate that the volume group infos list is obtained.'); 2226}); 2227``` 2228 2229### getVolumeGroupInfos<sup>9+</sup> 2230 2231getVolumeGroupInfos(networkId: string\): Promise<VolumeGroupInfos\> 2232 2233Obtains the volume groups. This API uses a promise to return the result. 2234 2235**System API**: This is a system API. 2236 2237**System capability**: SystemCapability.Multimedia.Audio.Volume 2238 2239**Parameters** 2240 2241| Name | Type | Mandatory| Description | 2242| ---------- | ------------------| ---- | -------------------- | 2243| networkId | string | Yes | Network ID of the device. The network ID of the local device is **audio.LOCAL_NETWORK_ID**. | 2244 2245**Return value** 2246 2247| Type | Description | 2248| ------------------- | ----------------------------- | 2249| Promise<[VolumeGroupInfos](#volumegroupinfos9)> | Volume group information array.| 2250 2251**Example** 2252 2253```js 2254async function getVolumeGroupInfos(){ 2255 let volumegroupinfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID); 2256 console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos)) 2257} 2258``` 2259 2260### getVolumeGroupManager<sup>9+</sup> 2261 2262getVolumeGroupManager(groupId: number, callback: AsyncCallback<AudioVolumeGroupManager\>\): void 2263 2264Obtains the audio group manager. This API uses an asynchronous callback to return the result. 2265 2266**System capability**: SystemCapability.Multimedia.Audio.Volume 2267 2268**Parameters** 2269 2270| Name | Type | Mandatory| Description | 2271| ---------- | ------------------------------------------------------------ | ---- | -------------------- | 2272| groupId | number | Yes | Volume group ID. | 2273| callback | AsyncCallback<[AudioVolumeGroupManager](#audiovolumegroupmanager9)> | Yes | Callback used to return the audio group manager.| 2274 2275**Example** 2276 2277```js 2278let groupid = audio.DEFAULT_VOLUME_GROUP_ID; 2279audioVolumeManager.getVolumeGroupManager(groupid, (err, value) => { 2280 if (err) { 2281 console.error(`Failed to obtain the volume group infos list. ${err}`); 2282 return; 2283 } 2284 console.info('Callback invoked to indicate that the volume group infos list is obtained.'); 2285}); 2286 2287``` 2288 2289### getVolumeGroupManager<sup>9+</sup> 2290 2291getVolumeGroupManager(groupId: number\): Promise<AudioVolumeGroupManager\> 2292 2293Obtains the audio group manager. This API uses a promise to return the result. 2294 2295**System capability**: SystemCapability.Multimedia.Audio.Volume 2296 2297**Parameters** 2298 2299| Name | Type | Mandatory| Description | 2300| ---------- | ---------------------------------------- | ---- | ---------------- | 2301| groupId | number | Yes | Volume group ID. | 2302 2303**Return value** 2304 2305| Type | Description | 2306| ------------------- | ----------------------------- | 2307| Promise< [AudioVolumeGroupManager](#audiovolumegroupmanager9) > | Promise used to return the audio group manager.| 2308 2309**Example** 2310 2311```js 2312let groupid = audio.DEFAULT_VOLUME_GROUP_ID; 2313let audioVolumeGroupManager; 2314getVolumeGroupManager(); 2315async function getVolumeGroupManager(){ 2316 audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid); 2317 console.info('Callback invoked to indicate that the volume group infos list is obtained.'); 2318} 2319 2320``` 2321 2322### on('volumeChange')<sup>9+</sup> 2323 2324on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void 2325 2326Subscribes to system volume change events. This API uses an asynchronous callback to return the result. 2327 2328**System capability**: SystemCapability.Multimedia.Audio.Volume 2329 2330**Parameters** 2331 2332| Name | Type | Mandatory| Description | 2333| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 2334| type | string | Yes | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when the system volume changes.| 2335| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to return the system volume change event. | 2336 2337**Error codes** 2338 2339For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 2340 2341| ID| Error Message| 2342| ------- | --------------------------------------------| 2343| 6800101 | if input parameter value error | 2344 2345**Example** 2346 2347```js 2348audioVolumeManager.on('volumeChange', (volumeEvent) => { 2349 console.info(`VolumeType of stream: ${volumeEvent.volumeType} `); 2350 console.info(`Volume level: ${volumeEvent.volume} `); 2351 console.info(`Whether to updateUI: ${volumeEvent.updateUi} `); 2352}); 2353``` 2354 2355## AudioVolumeGroupManager<sup>9+</sup> 2356 2357Manages the volume of an audio group. Before calling any API in **AudioVolumeGroupManager**, you must use [getVolumeGroupManager](#getvolumegroupmanager9) to obtain an **AudioVolumeGroupManager** instance. 2358 2359### setVolume<sup>9+</sup> 2360 2361setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void 2362 2363Sets the volume for a stream. This API uses an asynchronous callback to return the result. 2364 2365**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2366 2367This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 2368 2369**System API**: This is a system API. 2370 2371**System capability**: SystemCapability.Multimedia.Audio.Volume 2372 2373**Parameters** 2374 2375| Name | Type | Mandatory| Description | 2376| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 2377| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2378| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| 2379| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2380 2381**Example** 2382 2383```js 2384audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { 2385 if (err) { 2386 console.error(`Failed to set the volume. ${err}`); 2387 return; 2388 } 2389 console.info('Callback invoked to indicate a successful volume setting.'); 2390}); 2391``` 2392 2393### setVolume<sup>9+</sup> 2394 2395setVolume(volumeType: AudioVolumeType, volume: number): Promise<void> 2396 2397Sets the volume for a stream. This API uses a promise to return the result. 2398 2399**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2400 2401This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 2402 2403**System API**: This is a system API. 2404 2405**System capability**: SystemCapability.Multimedia.Audio.Volume 2406 2407**Parameters** 2408 2409| Name | Type | Mandatory| Description | 2410| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 2411| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2412| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| 2413 2414**Return value** 2415 2416| Type | Description | 2417| ------------------- | ----------------------------- | 2418| Promise<void> | Promise used to return the result.| 2419 2420**Example** 2421 2422```js 2423audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { 2424 console.info('Promise returned to indicate a successful volume setting.'); 2425}); 2426``` 2427 2428### getVolume<sup>9+</sup> 2429 2430getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 2431 2432Obtains the volume of a stream. This API uses an asynchronous callback to return the result. 2433 2434**System capability**: SystemCapability.Multimedia.Audio.Volume 2435 2436**Parameters** 2437 2438| Name | Type | Mandatory| Description | 2439| ---------- | ----------------------------------- | ---- | ------------------ | 2440| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2441| callback | AsyncCallback<number> | Yes | Callback used to return the volume.| 2442 2443**Example** 2444 2445```js 2446audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 2447 if (err) { 2448 console.error(`Failed to obtain the volume. ${err}`); 2449 return; 2450 } 2451 console.info('Callback invoked to indicate that the volume is obtained.'); 2452}); 2453``` 2454 2455### getVolume<sup>9+</sup> 2456 2457getVolume(volumeType: AudioVolumeType): Promise<number> 2458 2459Obtains the volume of a stream. This API uses a promise to return the result. 2460 2461**System capability**: SystemCapability.Multimedia.Audio.Volume 2462 2463**Parameters** 2464 2465| Name | Type | Mandatory| Description | 2466| ---------- | ----------------------------------- | ---- | ------------ | 2467| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 2468 2469**Return value** 2470 2471| Type | Description | 2472| --------------------- | ------------------------- | 2473| Promise<number> | Promise used to return the volume.| 2474 2475**Example** 2476 2477```js 2478audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { 2479 console.info(`Promise returned to indicate that the volume is obtained ${value}.`); 2480}); 2481``` 2482 2483### getMinVolume<sup>9+</sup> 2484 2485getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 2486 2487Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result. 2488 2489**System capability**: SystemCapability.Multimedia.Audio.Volume 2490 2491**Parameters** 2492 2493| Name | Type | Mandatory| Description | 2494| ---------- | ----------------------------------- | ---- | ------------------ | 2495| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2496| callback | AsyncCallback<number> | Yes | Callback used to return the minimum volume.| 2497 2498**Example** 2499 2500```js 2501audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 2502 if (err) { 2503 console.error(`Failed to obtain the minimum volume. ${err}`); 2504 return; 2505 } 2506 console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`); 2507}); 2508``` 2509 2510### getMinVolume<sup>9+</sup> 2511 2512getMinVolume(volumeType: AudioVolumeType): Promise<number> 2513 2514Obtains the minimum volume allowed for a stream. This API uses a promise to return the result. 2515 2516**System capability**: SystemCapability.Multimedia.Audio.Volume 2517 2518**Parameters** 2519 2520| Name | Type | Mandatory| Description | 2521| ---------- | ----------------------------------- | ---- | ------------ | 2522| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 2523 2524**Return value** 2525 2526| Type | Description | 2527| --------------------- | ------------------------- | 2528| Promise<number> | Promise used to return the minimum volume.| 2529 2530**Example** 2531 2532```js 2533audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { 2534 console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`); 2535}); 2536``` 2537 2538### getMaxVolume<sup>9+</sup> 2539 2540getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 2541 2542Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result. 2543 2544**System capability**: SystemCapability.Multimedia.Audio.Volume 2545 2546**Parameters** 2547 2548| Name | Type | Mandatory| Description | 2549| ---------- | ----------------------------------- | ---- | ---------------------- | 2550| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2551| callback | AsyncCallback<number> | Yes | Callback used to return the maximum volume.| 2552 2553**Example** 2554 2555```js 2556audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { 2557 if (err) { 2558 console.error(`Failed to obtain the maximum volume. ${err}`); 2559 return; 2560 } 2561 console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`); 2562}); 2563``` 2564 2565### getMaxVolume<sup>9+</sup> 2566 2567getMaxVolume(volumeType: AudioVolumeType): Promise<number> 2568 2569Obtains the maximum volume allowed for a stream. This API uses a promise to return the result. 2570 2571**System capability**: SystemCapability.Multimedia.Audio.Volume 2572 2573**Parameters** 2574 2575| Name | Type | Mandatory| Description | 2576| ---------- | ----------------------------------- | ---- | ------------ | 2577| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 2578 2579**Return value** 2580 2581| Type | Description | 2582| --------------------- | ----------------------------- | 2583| Promise<number> | Promise used to return the maximum volume.| 2584 2585**Example** 2586 2587```js 2588audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { 2589 console.info('Promised returned to indicate that the maximum volume is obtained.'); 2590}); 2591``` 2592 2593### mute<sup>9+</sup> 2594 2595mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void 2596 2597Mutes or unmutes a stream. This API uses an asynchronous callback to return the result. 2598 2599**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2600 2601This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 2602 2603**System API**: This is a system API. 2604 2605**System capability**: SystemCapability.Multimedia.Audio.Volume 2606 2607**Parameters** 2608 2609| Name | Type | Mandatory| Description | 2610| ---------- | ----------------------------------- | ---- | ------------------------------------- | 2611| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2612| mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.| 2613| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2614 2615**Example** 2616 2617```js 2618audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { 2619 if (err) { 2620 console.error(`Failed to mute the stream. ${err}`); 2621 return; 2622 } 2623 console.info('Callback invoked to indicate that the stream is muted.'); 2624}); 2625``` 2626 2627### mute<sup>9+</sup> 2628 2629mute(volumeType: AudioVolumeType, mute: boolean): Promise<void> 2630 2631Mutes or unmutes a stream. This API uses a promise to return the result. 2632 2633**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2634 2635This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 2636 2637**System API**: This is a system API. 2638 2639**System capability**: SystemCapability.Multimedia.Audio.Volume 2640 2641**Parameters** 2642 2643| Name | Type | Mandatory| Description | 2644| ---------- | ----------------------------------- | ---- | ------------------------------------- | 2645| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2646| mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.| 2647 2648**Return value** 2649 2650| Type | Description | 2651| ------------------- | ----------------------------- | 2652| Promise<void> | Promise used to return the result.| 2653 2654**Example** 2655 2656```js 2657audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { 2658 console.info('Promise returned to indicate that the stream is muted.'); 2659}); 2660``` 2661 2662### isMute<sup>9+</sup> 2663 2664isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 2665 2666Checks whether a stream is muted. This API uses an asynchronous callback to return the result. 2667 2668**System capability**: SystemCapability.Multimedia.Audio.Volume 2669 2670**Parameters** 2671 2672| Name | Type | Mandatory| Description | 2673| ---------- | ----------------------------------- | ---- | ----------------------------------------------- | 2674| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | 2675| callback | AsyncCallback<boolean> | 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.| 2676 2677**Example** 2678 2679```js 2680audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { 2681 if (err) { 2682 console.error(`Failed to obtain the mute status. ${err}`); 2683 return; 2684 } 2685 console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`); 2686}); 2687``` 2688 2689### isMute<sup>9+</sup> 2690 2691isMute(volumeType: AudioVolumeType): Promise<boolean> 2692 2693Checks whether a stream is muted. This API uses a promise to return the result. 2694 2695**System capability**: SystemCapability.Multimedia.Audio.Volume 2696 2697**Parameters** 2698 2699| Name | Type | Mandatory| Description | 2700| ---------- | ----------------------------------- | ---- | ------------ | 2701| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.| 2702 2703**Return value** 2704 2705| Type | Description | 2706| ---------------------- | ------------------------------------------------------ | 2707| Promise<boolean> | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.| 2708 2709**Example** 2710 2711```js 2712audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { 2713 console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`); 2714}); 2715``` 2716 2717### setRingerMode<sup>9+</sup> 2718 2719setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void 2720 2721Sets the ringer mode. This API uses an asynchronous callback to return the result. 2722 2723**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2724 2725This permission is required only for muting or unmuting the ringer. 2726 2727**System API**: This is a system API. 2728 2729**System capability**: SystemCapability.Multimedia.Audio.Volume 2730 2731**Parameters** 2732 2733| Name | Type | Mandatory| Description | 2734| -------- | ------------------------------- | ---- | ------------------------ | 2735| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | 2736| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 2737 2738**Example** 2739 2740```js 2741audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { 2742 if (err) { 2743 console.error(`Failed to set the ringer mode. ${err}`); 2744 return; 2745 } 2746 console.info('Callback invoked to indicate a successful setting of the ringer mode.'); 2747}); 2748``` 2749 2750### setRingerMode<sup>9+</sup> 2751 2752setRingerMode(mode: AudioRingMode): Promise<void> 2753 2754Sets the ringer mode. This API uses a promise to return the result. 2755 2756**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 2757 2758This permission is required only for muting or unmuting the ringer. 2759 2760**System API**: This is a system API. 2761 2762**System capability**: SystemCapability.Multimedia.Audio.Volume 2763 2764**Parameters** 2765 2766| Name| Type | Mandatory| Description | 2767| ------ | ------------------------------- | ---- | -------------- | 2768| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.| 2769 2770**Return value** 2771 2772| Type | Description | 2773| ------------------- | ------------------------------- | 2774| Promise<void> | Promise used to return the result.| 2775 2776**Example** 2777 2778```js 2779audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { 2780 console.info('Promise returned to indicate a successful setting of the ringer mode.'); 2781}); 2782``` 2783 2784### getRingerMode<sup>9+</sup> 2785 2786getRingerMode(callback: AsyncCallback<AudioRingMode>): void 2787 2788Obtains the ringer mode. This API uses an asynchronous callback to return the result. 2789 2790**System capability**: SystemCapability.Multimedia.Audio.Volume 2791 2792**Parameters** 2793 2794| Name | Type | Mandatory| Description | 2795| -------- | ---------------------------------------------------- | ---- | ------------------------ | 2796| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode.| 2797 2798**Example** 2799 2800```js 2801audioVolumeGroupManager.getRingerMode((err, value) => { 2802 if (err) { 2803 console.error(`Failed to obtain the ringer mode. ${err}`); 2804 return; 2805 } 2806 console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`); 2807}); 2808``` 2809 2810### getRingerMode<sup>9+</sup> 2811 2812getRingerMode(): Promise<AudioRingMode> 2813 2814Obtains the ringer mode. This API uses a promise to return the result. 2815 2816**System capability**: SystemCapability.Multimedia.Audio.Volume 2817 2818**Return value** 2819 2820| Type | Description | 2821| ---------------------------------------------- | ------------------------------- | 2822| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode.| 2823 2824**Example** 2825 2826```js 2827audioVolumeGroupManager.getRingerMode().then((value) => { 2828 console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`); 2829}); 2830``` 2831 2832### on('ringerModeChange')<sup>9+</sup> 2833 2834on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void 2835 2836Subscribes to ringer mode change events. 2837 2838**System capability**: SystemCapability.Multimedia.Audio.Volume 2839 2840**Parameters** 2841 2842| Name | Type | Mandatory| Description | 2843| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | 2844| type | string | Yes | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected.| 2845| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the system volume change event. | 2846 2847**Error codes** 2848 2849For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 2850 2851| ID| Error Message| 2852| ------- | --------------------------------------------| 2853| 6800101 | if input parameter value error | 2854 2855**Example** 2856 2857```js 2858audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => { 2859 console.info(`Updated ringermode: ${ringerMode}`); 2860}); 2861``` 2862### setMicrophoneMute<sup>9+</sup> 2863 2864setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void 2865 2866Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. 2867 2868**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG 2869 2870**System capability**: SystemCapability.Multimedia.Audio.Volume 2871 2872**Parameters** 2873 2874| Name | Type | Mandatory| Description | 2875| -------- | ------------------------- | ---- | --------------------------------------------- | 2876| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 2877| callback | AsyncCallback<void> | Yes | Callback used to return the result. | 2878 2879**Example** 2880 2881```js 2882audioVolumeGroupManager.setMicrophoneMute(true, (err) => { 2883 if (err) { 2884 console.error(`Failed to mute the microphone. ${err}`); 2885 return; 2886 } 2887 console.info('Callback invoked to indicate that the microphone is muted.'); 2888}); 2889``` 2890 2891### setMicrophoneMute<sup>9+</sup> 2892 2893setMicrophoneMute(mute: boolean): Promise<void> 2894 2895Mutes or unmutes the microphone. This API uses a promise to return the result. 2896 2897**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG 2898 2899**System capability**: SystemCapability.Multimedia.Audio.Volume 2900 2901**Parameters** 2902 2903| Name| Type | Mandatory| Description | 2904| ------ | ------- | ---- | --------------------------------------------- | 2905| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 2906 2907**Return value** 2908 2909| Type | Description | 2910| ------------------- | ------------------------------- | 2911| Promise<void> | Promise used to return the result.| 2912 2913**Example** 2914 2915```js 2916audioVolumeGroupManager.setMicrophoneMute(true).then(() => { 2917 console.info('Promise returned to indicate that the microphone is muted.'); 2918}); 2919``` 2920 2921### isMicrophoneMute<sup>9+</sup> 2922 2923isMicrophoneMute(callback: AsyncCallback<boolean>): void 2924 2925Checks whether the microphone is muted. This API uses an asynchronous callback to return the result. 2926 2927**System capability**: SystemCapability.Multimedia.Audio.Volume 2928 2929**Parameters** 2930 2931| Name | Type | Mandatory| Description | 2932| -------- | ---------------------------- | ---- | ------------------------------------------------------- | 2933| callback | AsyncCallback<boolean> | 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.| 2934 2935**Example** 2936 2937```js 2938audioVolumeGroupManager.isMicrophoneMute((err, value) => { 2939 if (err) { 2940 console.error(`Failed to obtain the mute status of the microphone. ${err}`); 2941 return; 2942 } 2943 console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`); 2944}); 2945``` 2946 2947### isMicrophoneMute<sup>9+</sup> 2948 2949isMicrophoneMute(): Promise<boolean> 2950 2951Checks whether the microphone is muted. This API uses a promise to return the result. 2952 2953**System capability**: SystemCapability.Multimedia.Audio.Volume 2954 2955**Return value** 2956 2957| Type | Description | 2958| ---------------------- | ------------------------------------------------------------ | 2959| Promise<boolean> | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.| 2960 2961**Example** 2962 2963```js 2964audioVolumeGroupManager.isMicrophoneMute().then((value) => { 2965 console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`); 2966}); 2967``` 2968 2969### on('micStateChange')<sup>9+</sup> 2970 2971on(type: 'micStateChange', callback: Callback<MicStateChangeEvent>): void 2972 2973Subscribes to system microphone state change events. 2974 2975Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance. 2976 2977**System capability**: SystemCapability.Multimedia.Audio.Volume 2978 2979**Parameters** 2980 2981| Name | Type | Mandatory| Description | 2982| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 2983| type | string | Yes | Event type. The value **'micStateChange'** means the system microphone state change event, which is triggered when the system microphone state changes.| 2984| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | Yes | Callback used to return the changed microphone state. | 2985 2986**Error codes** 2987 2988For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 2989 2990| ID| Error Message| 2991| ------- | --------------------------------------------| 2992| 6800101 | if input parameter value error | 2993 2994**Example** 2995 2996```js 2997audioVolumeGroupManager.on('micStateChange', (micStateChange) => { 2998 console.info(`Current microphone status is: ${micStateChange.mute} `); 2999}); 3000``` 3001 3002## AudioStreamManager<sup>9+</sup> 3003 3004Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance. 3005 3006### getCurrentAudioRendererInfoArray<sup>9+</sup> 3007 3008getCurrentAudioRendererInfoArray(callback: AsyncCallback<AudioRendererChangeInfoArray>): void 3009 3010Obtains the information about the current audio renderer. This API uses an asynchronous callback to return the result. 3011 3012**System capability**: SystemCapability.Multimedia.Audio.Renderer 3013 3014**Parameters** 3015 3016| Name | Type | Mandatory | Description | 3017| -------- | ----------------------------------- | -------- | --------------------------- | 3018| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes | Callback used to return the audio renderer information.| 3019 3020**Example** 3021 3022```js 3023audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => { 3024 console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****'); 3025 if (err) { 3026 console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`); 3027 } else { 3028 if (AudioRendererChangeInfoArray != null) { 3029 for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { 3030 let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i]; 3031 console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`); 3032 console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`); 3033 console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`); 3034 console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`); 3035 console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 3036 console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`); 3037 for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) { 3038 console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`); 3039 console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`); 3040 console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`); 3041 console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`); 3042 console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`); 3043 console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`); 3044 console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`); 3045 console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`); 3046 } 3047 } 3048 } 3049 } 3050}); 3051``` 3052 3053### getCurrentAudioRendererInfoArray<sup>9+</sup> 3054 3055getCurrentAudioRendererInfoArray(): Promise<AudioRendererChangeInfoArray> 3056 3057Obtains the information about the current audio renderer. This API uses a promise to return the result. 3058 3059**System capability**: SystemCapability.Multimedia.Audio.Renderer 3060 3061**Return value** 3062 3063| Type | Description | 3064| ---------------------------------------------------------------------------------| --------------------------------------- | 3065| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise used to return the audio renderer information. | 3066 3067**Example** 3068 3069```js 3070async function getCurrentAudioRendererInfoArray(){ 3071 await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) { 3072 console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`); 3073 if (AudioRendererChangeInfoArray != null) { 3074 for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { 3075 let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i]; 3076 console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`); 3077 console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`); 3078 console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`); 3079 console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`); 3080 console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 3081 console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`); 3082 for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) { 3083 console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`); 3084 console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`); 3085 console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`); 3086 console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`); 3087 console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`); 3088 console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`); 3089 console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`); 3090 console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`); 3091 } 3092 } 3093 } 3094 }).catch((err) => { 3095 console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`); 3096 }); 3097} 3098``` 3099 3100### getCurrentAudioCapturerInfoArray<sup>9+</sup> 3101 3102getCurrentAudioCapturerInfoArray(callback: AsyncCallback<AudioCapturerChangeInfoArray>): void 3103 3104Obtains the information about the current audio capturer. This API uses an asynchronous callback to return the result. 3105 3106**System capability**: SystemCapability.Multimedia.Audio.Renderer 3107 3108**Parameters** 3109 3110| Name | Type | Mandatory | Description | 3111| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- | 3112| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes | Callback used to return the audio capturer information.| 3113 3114**Example** 3115 3116```js 3117audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => { 3118 console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****'); 3119 if (err) { 3120 console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`); 3121 } else { 3122 if (AudioCapturerChangeInfoArray != null) { 3123 for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { 3124 console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`); 3125 console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`); 3126 console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`); 3127 console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`); 3128 console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`); 3129 for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) { 3130 console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`); 3131 console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`); 3132 console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`); 3133 console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`); 3134 console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`); 3135 console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`); 3136 console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`); 3137 console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`); 3138 } 3139 } 3140 } 3141 } 3142}); 3143``` 3144 3145### getCurrentAudioCapturerInfoArray<sup>9+</sup> 3146 3147getCurrentAudioCapturerInfoArray(): Promise<AudioCapturerChangeInfoArray> 3148 3149Obtains the information about the current audio capturer. This API uses a promise to return the result. 3150 3151**System capability**: SystemCapability.Multimedia.Audio.Renderer 3152 3153**Return value** 3154 3155| Type | Description | 3156| -----------------------------------------------------------------------------| ----------------------------------- | 3157| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise used to return the audio capturer information. | 3158 3159**Example** 3160 3161```js 3162async function getCurrentAudioCapturerInfoArray(){ 3163 await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) { 3164 console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****'); 3165 if (AudioCapturerChangeInfoArray != null) { 3166 for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { 3167 console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`); 3168 console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`); 3169 console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`); 3170 console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`); 3171 console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`); 3172 for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) { 3173 console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`); 3174 console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`); 3175 console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`); 3176 console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`); 3177 console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`); 3178 console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`); 3179 console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`); 3180 console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`); 3181 } 3182 } 3183 } 3184 }).catch((err) => { 3185 console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`); 3186 }); 3187} 3188``` 3189 3190### on('audioRendererChange')<sup>9+</sup> 3191 3192on(type: "audioRendererChange", callback: Callback<AudioRendererChangeInfoArray>): void 3193 3194Subscribes to audio renderer change events. 3195 3196**System capability**: SystemCapability.Multimedia.Audio.Renderer 3197 3198**Parameters** 3199 3200| Name | Type | Mandatory | Description | 3201| -------- | ---------- | --------- | ------------------------------------------------------------------------ | 3202| type | string | Yes | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes. | 3203| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes | Callback used to return the result. | 3204 3205**Error codes** 3206 3207For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3208 3209| ID| Error Message| 3210| ------- | --------------------------------------------| 3211| 6800101 | if input parameter value error | 3212 3213**Example** 3214 3215```js 3216audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => { 3217 for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { 3218 let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i]; 3219 console.info(`## RendererChange on is called for ${i} ##`); 3220 console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`); 3221 console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`); 3222 console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`); 3223 console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`); 3224 console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`); 3225 console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`); 3226 for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) { 3227 console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`); 3228 console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`); 3229 console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`); 3230 console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`); 3231 console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`); 3232 console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`); 3233 console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`); 3234 console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`); 3235 } 3236 } 3237}); 3238``` 3239 3240### off('audioRendererChange')<sup>9+</sup> 3241 3242off(type: "audioRendererChange"): void 3243 3244Unsubscribes from audio renderer change events. 3245 3246**System capability**: SystemCapability.Multimedia.Audio.Renderer 3247 3248**Parameters** 3249 3250| Name | Type | Mandatory| Description | 3251| -------- | ------- | ---- | ---------------- | 3252| type | string | Yes | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.| 3253 3254**Error codes** 3255 3256For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3257 3258| ID| Error Message| 3259| ------- | --------------------------------------------| 3260| 6800101 | if input parameter value error | 3261 3262**Example** 3263 3264```js 3265audioStreamManager.off('audioRendererChange'); 3266console.info('######### RendererChange Off is called #########'); 3267``` 3268 3269### on('audioCapturerChange')<sup>9+</sup> 3270 3271on(type: "audioCapturerChange", callback: Callback<AudioCapturerChangeInfoArray>): void 3272 3273Subscribes to audio capturer change events. 3274 3275**System capability**: SystemCapability.Multimedia.Audio.Capturer 3276 3277**Parameters** 3278 3279| Name | Type | Mandatory | Description | 3280| -------- | ------- | --------- | ----------------------------------------------------------------------- | 3281| type | string | Yes | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes. | 3282| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes | Callback used to return the result. | 3283 3284**Error codes** 3285 3286For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3287 3288| ID| Error Message| 3289| ------- | --------------------------------------------| 3290| 6800101 | if input parameter value error | 3291 3292**Example** 3293 3294```js 3295audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => { 3296 for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { 3297 console.info(`## CapChange on is called for element ${i} ##`); 3298 console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`); 3299 console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`); 3300 console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`); 3301 console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`); 3302 console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`); 3303 let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors; 3304 for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) { 3305 console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`); 3306 console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`); 3307 console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`); 3308 console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`); 3309 console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`); 3310 console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`); 3311 console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`); 3312 console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`); 3313 } 3314 } 3315}); 3316``` 3317 3318### off('audioCapturerChange')<sup>9+</sup> 3319 3320off(type: "audioCapturerChange"): void; 3321 3322Unsubscribes from audio capturer change events. 3323 3324**System capability**: SystemCapability.Multimedia.Audio.Capturer 3325 3326**Parameters** 3327 3328| Name | Type | Mandatory| Description | 3329| -------- | -------- | --- | ------------------------------------------------------------- | 3330| type | string |Yes | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.| 3331 3332**Error codes** 3333 3334For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3335 3336| ID| Error Message| 3337| ------- | --------------------------------------------| 3338| 6800101 | if input parameter value error | 3339 3340**Example** 3341 3342```js 3343audioStreamManager.off('audioCapturerChange'); 3344console.info('######### CapturerChange Off is called #########'); 3345 3346``` 3347 3348### isActive<sup>9+</sup> 3349 3350isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 3351 3352Checks whether a stream is active. This API uses an asynchronous callback to return the result. 3353 3354**System capability**: SystemCapability.Multimedia.Audio.Renderer 3355 3356**Parameters** 3357 3358| Name | Type | Mandatory| Description | 3359| ---------- | ----------------------------------- | ---- | ------------------------------------------------- | 3360| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream types. | 3361| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.| 3362 3363**Example** 3364 3365```js 3366audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { 3367 if (err) { 3368 console.error(`Failed to obtain the active status of the stream. ${err}`); 3369 return; 3370 } 3371 console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`); 3372}); 3373``` 3374 3375### isActive<sup>9+</sup> 3376 3377isActive(volumeType: AudioVolumeType): Promise<boolean> 3378 3379Checks whether a stream is active. This API uses a promise to return the result. 3380 3381**System capability**: SystemCapability.Multimedia.Audio.Renderer 3382 3383**Parameters** 3384 3385| Name | Type | Mandatory| Description | 3386| ---------- | ----------------------------------- | ---- | ------------ | 3387| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream types.| 3388 3389**Return value** 3390 3391| Type | Description | 3392| ---------------------- | -------------------------------------------------------- | 3393| Promise<boolean> | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.| 3394 3395**Example** 3396 3397```js 3398audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { 3399 console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`); 3400}); 3401``` 3402 3403## AudioRoutingManager<sup>9+</sup> 3404 3405Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance. 3406 3407### getDevices<sup>9+</sup> 3408 3409getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void 3410 3411Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result. 3412 3413**System capability**: SystemCapability.Multimedia.Audio.Device 3414 3415**Parameters** 3416 3417| Name | Type | Mandatory| Description | 3418| ---------- | ------------------------------------------------------------ | ---- | -------------------- | 3419| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | 3420| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list.| 3421 3422**Example** 3423 3424```js 3425audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { 3426 if (err) { 3427 console.error(`Failed to obtain the device list. ${err}`); 3428 return; 3429 } 3430 console.info('Callback invoked to indicate that the device list is obtained.'); 3431}); 3432``` 3433 3434### getDevices<sup>9+</sup> 3435 3436getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors> 3437 3438Obtains the audio devices with a specific flag. This API uses a promise to return the result. 3439 3440**System capability**: SystemCapability.Multimedia.Audio.Device 3441 3442**Parameters** 3443 3444| Name | Type | Mandatory| Description | 3445| ---------- | ------------------------- | ---- | ---------------- | 3446| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.| 3447 3448**Return value** 3449 3450| Type | Description | 3451| ------------------------------------------------------------ | ------------------------- | 3452| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list.| 3453 3454**Example** 3455 3456```js 3457audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 3458 console.info('Promise returned to indicate that the device list is obtained.'); 3459}); 3460``` 3461 3462### on<sup>9+</sup> 3463 3464on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback<DeviceChangeAction\>): void 3465 3466Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback. 3467 3468**System capability**: SystemCapability.Multimedia.Audio.Device 3469 3470**Parameters** 3471 3472| Name | Type | Mandatory| Description | 3473| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- | 3474| type | string | Yes | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.| 3475| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | 3476| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes | Callback used to return the device update details. | 3477 3478**Error codes** 3479 3480For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3481 3482| ID| Error Message| 3483| ------- | --------------------------------------------| 3484| 6800101 | if input parameter value error | 3485 3486**Example** 3487 3488```js 3489audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => { 3490 console.info('device change type : ' + deviceChanged.type); 3491 console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length); 3492 console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole); 3493 console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType); 3494}); 3495``` 3496 3497### off<sup>9+</sup> 3498 3499off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void 3500 3501Unsubscribes from device change events. 3502 3503**System capability**: SystemCapability.Multimedia.Audio.Device 3504 3505**Parameters** 3506 3507| Name | Type | Mandatory| Description | 3508| -------- | --------------------------------------------------- | ---- | ------------------------------------------ | 3509| type | string | Yes | Event type. The value **'deviceChange'** means the device change event, which is triggered when a device connection status change is detected.| 3510| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to return the device update details. | 3511 3512**Error codes** 3513 3514For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 3515 3516| ID| Error Message| 3517| ------- | --------------------------------------------| 3518| 6800101 | if input parameter value error | 3519 3520**Example** 3521 3522```js 3523audioRoutingManager.off('deviceChange', (deviceChanged) => { 3524 console.info('Should be no callback.'); 3525}); 3526``` 3527 3528### selectInputDevice<sup>9+</sup> 3529 3530selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void 3531 3532Selects an audio input device. Only one input device can be selected. This API uses an asynchronous callback to return the result. 3533 3534**System API**: This is a system API. 3535 3536**System capability**: SystemCapability.Multimedia.Audio.Device 3537 3538**Parameters** 3539 3540| Name | Type | Mandatory| Description | 3541| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | 3542| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Input device. | 3543| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3544 3545**Example** 3546```js 3547let inputAudioDeviceDescriptor = [{ 3548 deviceRole : audio.DeviceRole.INPUT_DEVICE, 3549 deviceType : audio.DeviceType.EARPIECE, 3550 id : 1, 3551 name : "", 3552 address : "", 3553 sampleRates : [44100], 3554 channelCounts : [2], 3555 channelMasks : [0], 3556 networkId : audio.LOCAL_NETWORK_ID, 3557 interruptGroupId : 1, 3558 volumeGroupId : 1, 3559}]; 3560 3561async function selectInputDevice(){ 3562 audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => { 3563 if (err) { 3564 console.error(`Result ERROR: ${err}`); 3565 } else { 3566 console.info('Select input devices result callback: SUCCESS'); } 3567 }); 3568} 3569``` 3570 3571### selectInputDevice<sup>9+</sup> 3572 3573selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise<void> 3574 3575**System API**: This is a system API. 3576 3577Selects an audio input device. Only one input device can be selected. This API uses a promise to return the result. 3578 3579**System capability**: SystemCapability.Multimedia.Audio.Device 3580 3581**Parameters** 3582 3583| Name | Type | Mandatory| Description | 3584| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | 3585| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Input device. | 3586 3587**Return value** 3588 3589| Type | Description | 3590| --------------------- | --------------------------- | 3591| Promise<void> | Promise used to return the result.| 3592 3593**Example** 3594 3595```js 3596let inputAudioDeviceDescriptor = [{ 3597 deviceRole : audio.DeviceRole.INPUT_DEVICE, 3598 deviceType : audio.DeviceType.EARPIECE, 3599 id : 1, 3600 name : "", 3601 address : "", 3602 sampleRates : [44100], 3603 channelCounts : [2], 3604 channelMasks : [0], 3605 networkId : audio.LOCAL_NETWORK_ID, 3606 interruptGroupId : 1, 3607 volumeGroupId : 1, 3608}]; 3609 3610async function getRoutingManager(){ 3611 audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => { 3612 console.info('Select input devices result promise: SUCCESS'); 3613 }).catch((err) => { 3614 console.error(`Result ERROR: ${err}`); 3615 }); 3616} 3617``` 3618 3619### setCommunicationDevice<sup>9+</sup> 3620 3621setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback<void>): void 3622 3623Sets a communication device to the active state. This API uses an asynchronous callback to return the result. 3624 3625**System capability**: SystemCapability.Multimedia.Audio.Communication 3626 3627**Parameters** 3628 3629| Name | Type | Mandatory| Description | 3630| ---------- | ------------------------------------- | ---- | ------------------------ | 3631| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes | Communication device type. | 3632| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. | 3633| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3634 3635**Example** 3636 3637```js 3638audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => { 3639 if (err) { 3640 console.error(`Failed to set the active status of the device. ${err}`); 3641 return; 3642 } 3643 console.info('Callback invoked to indicate that the device is set to the active status.'); 3644}); 3645``` 3646 3647### setCommunicationDevice<sup>9+</sup> 3648 3649setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise<void> 3650 3651Sets a communication device to the active state. This API uses a promise to return the result. 3652 3653**System capability**: SystemCapability.Multimedia.Audio.Communication 3654 3655**Parameters** 3656 3657| Name | Type | Mandatory| Description | 3658| ---------- | ----------------------------------------------------- | ---- | ------------------ | 3659| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes | Communication device type.| 3660| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. | 3661 3662**Return value** 3663 3664| Type | Description | 3665| ------------------- | ------------------------------- | 3666| Promise<void> | Promise used to return the result.| 3667 3668**Example** 3669 3670```js 3671audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => { 3672 console.info('Promise returned to indicate that the device is set to the active status.'); 3673}); 3674``` 3675 3676### isCommunicationDeviceActive<sup>9+</sup> 3677 3678isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback<boolean>): void 3679 3680Checks whether a communication device is active. This API uses an asynchronous callback to return the result. 3681 3682**System capability**: SystemCapability.Multimedia.Audio.Communication 3683 3684**Parameters** 3685 3686| Name | Type | Mandatory| Description | 3687| ---------- | ---------------------------------------------------- | ---- | ------------------------ | 3688| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes | Communication device type. | 3689| callback | AsyncCallback<boolean> | Yes | Callback used to return the active state of the device.| 3690 3691**Example** 3692 3693```js 3694audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => { 3695 if (err) { 3696 console.error(`Failed to obtain the active status of the device. ${err}`); 3697 return; 3698 } 3699 console.info('Callback invoked to indicate that the active status of the device is obtained.'); 3700}); 3701``` 3702 3703### isCommunicationDeviceActive<sup>9+</sup> 3704 3705isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise<boolean> 3706 3707Checks whether a communication device is active. This API uses a promise to return the result. 3708 3709**System capability**: SystemCapability.Multimedia.Audio.Communication 3710 3711**Parameters** 3712 3713| Name | Type | Mandatory| Description | 3714| ---------- | ---------------------------------------------------- | ---- | ------------------ | 3715| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | Yes | Communication device type.| 3716 3717**Return value** 3718 3719| Type | Description | 3720| ---------------------- | ------------------------------- | 3721| Promise<boolean> | Promise used to return the active state of the device.| 3722 3723**Example** 3724 3725```js 3726audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => { 3727 console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`); 3728}); 3729``` 3730 3731### selectOutputDevice<sup>9+</sup> 3732 3733selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void 3734 3735Selects an audio output device. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result. 3736 3737**System API**: This is a system API. 3738 3739**System capability**: SystemCapability.Multimedia.Audio.Device 3740 3741**Parameters** 3742 3743| Name | Type | Mandatory| Description | 3744| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | 3745| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Output device. | 3746| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3747 3748**Example** 3749```js 3750let outputAudioDeviceDescriptor = [{ 3751 deviceRole : audio.DeviceRole.OUTPUT_DEVICE, 3752 deviceType : audio.DeviceType.SPEAKER, 3753 id : 1, 3754 name : "", 3755 address : "", 3756 sampleRates : [44100], 3757 channelCounts : [2], 3758 channelMasks : [0], 3759 networkId : audio.LOCAL_NETWORK_ID, 3760 interruptGroupId : 1, 3761 volumeGroupId : 1, 3762}]; 3763 3764async function selectOutputDevice(){ 3765 audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => { 3766 if (err) { 3767 console.error(`Result ERROR: ${err}`); 3768 } else { 3769 console.info('Select output devices result callback: SUCCESS'); } 3770 }); 3771} 3772``` 3773 3774### selectOutputDevice<sup>9+</sup> 3775 3776selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise<void> 3777 3778**System API**: This is a system API. 3779 3780Selects an audio output device. Currently, only one output device can be selected. This API uses a promise to return the result. 3781 3782**System capability**: SystemCapability.Multimedia.Audio.Device 3783 3784**Parameters** 3785 3786| Name | Type | Mandatory| Description | 3787| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | 3788| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Output device. | 3789 3790**Return value** 3791 3792| Type | Description | 3793| --------------------- | --------------------------- | 3794| Promise<void> | Promise used to return the result.| 3795 3796**Example** 3797 3798```js 3799let outputAudioDeviceDescriptor = [{ 3800 deviceRole : audio.DeviceRole.OUTPUT_DEVICE, 3801 deviceType : audio.DeviceType.SPEAKER, 3802 id : 1, 3803 name : "", 3804 address : "", 3805 sampleRates : [44100], 3806 channelCounts : [2], 3807 channelMasks : [0], 3808 networkId : audio.LOCAL_NETWORK_ID, 3809 interruptGroupId : 1, 3810 volumeGroupId : 1, 3811}]; 3812 3813async function selectOutputDevice(){ 3814 audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => { 3815 console.info('Select output devices result promise: SUCCESS'); 3816 }).catch((err) => { 3817 console.error(`Result ERROR: ${err}`); 3818 }); 3819} 3820``` 3821 3822### selectOutputDeviceByFilter<sup>9+</sup> 3823 3824selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void 3825 3826**System API**: This is a system API. 3827 3828Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses an asynchronous callback to return the result. 3829 3830**System capability**: SystemCapability.Multimedia.Audio.Device 3831 3832**Parameters** 3833 3834| Name | Type | Mandatory| Description | 3835| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | 3836| filter | [AudioRendererFilter](#audiorendererfilter9) | Yes | Filter criteria. | 3837| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Output device. | 3838| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 3839 3840**Example** 3841```js 3842let outputAudioRendererFilter = { 3843 uid : 20010041, 3844 rendererInfo : { 3845 content : audio.ContentType.CONTENT_TYPE_MUSIC, 3846 usage : audio.StreamUsage.STREAM_USAGE_MEDIA, 3847 rendererFlags : 0 }, 3848 rendererId : 0 }; 3849 3850let outputAudioDeviceDescriptor = [{ 3851 deviceRole : audio.DeviceRole.OUTPUT_DEVICE, 3852 deviceType : audio.DeviceType.SPEAKER, 3853 id : 1, 3854 name : "", 3855 address : "", 3856 sampleRates : [44100], 3857 channelCounts : [2], 3858 channelMasks : [0], 3859 networkId : audio.LOCAL_NETWORK_ID, 3860 interruptGroupId : 1, 3861 volumeGroupId : 1, 3862}]; 3863 3864async function selectOutputDeviceByFilter(){ 3865 audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => { 3866 if (err) { 3867 console.error(`Result ERROR: ${err}`); 3868 } else { 3869 console.info('Select output devices by filter result callback: SUCCESS'); } 3870 }); 3871} 3872``` 3873 3874### selectOutputDeviceByFilter<sup>9+</sup> 3875 3876selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise<void> 3877 3878**System API**: This is a system API. 3879 3880Selects an audio output device based on the filter criteria. Currently, only one output device can be selected. This API uses a promise to return the result. 3881 3882**System capability**: SystemCapability.Multimedia.Audio.Device 3883 3884**Parameters** 3885 3886| Name | Type | Mandatory| Description | 3887| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- | 3888| filter | [AudioRendererFilter](#audiorendererfilter9) | Yes | Filter criteria. | 3889| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Output device. | 3890 3891**Return value** 3892 3893| Type | Description | 3894| --------------------- | --------------------------- | 3895| Promise<void> | Promise used to return the result.| 3896 3897**Example** 3898 3899```js 3900let outputAudioRendererFilter = { 3901 uid : 20010041, 3902 rendererInfo : { 3903 content : audio.ContentType.CONTENT_TYPE_MUSIC, 3904 usage : audio.StreamUsage.STREAM_USAGE_MEDIA, 3905 rendererFlags : 0 }, 3906 rendererId : 0 }; 3907 3908let outputAudioDeviceDescriptor = [{ 3909 deviceRole : audio.DeviceRole.OUTPUT_DEVICE, 3910 deviceType : audio.DeviceType.SPEAKER, 3911 id : 1, 3912 name : "", 3913 address : "", 3914 sampleRates : [44100], 3915 channelCounts : [2], 3916 channelMasks : [0], 3917 networkId : audio.LOCAL_NETWORK_ID, 3918 interruptGroupId : 1, 3919 volumeGroupId : 1, 3920}]; 3921 3922async function selectOutputDeviceByFilter(){ 3923 audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => { 3924 console.info('Select output devices by filter result promise: SUCCESS'); 3925 }).catch((err) => { 3926 console.error(`Result ERROR: ${err}`); 3927 }) 3928} 3929``` 3930 3931## AudioRendererChangeInfoArray<sup>9+</sup> 3932 3933Defines an **AudioRenderChangeInfo** array, which is read-only. 3934 3935**System capability**: SystemCapability.Multimedia.Audio.Renderer 3936 3937## AudioRendererChangeInfo<sup>9+</sup> 3938 3939Describes the audio renderer change event. 3940 3941**System capability**: SystemCapability.Multimedia.Audio.Renderer 3942 3943| Name | Type | Readable | Writable | Description | 3944| ------------- | ---------------------------------------- | -------- | -------- | ---------------------------------------------------------- | 3945| streamId | number | Yes | No | Unique ID of an audio stream. | 3946| clientUid | number | Yes | No | UID of the audio renderer client.<br>This is a system API. | 3947| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | No | Audio renderer information. | 3948| rendererState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API. | 3949 3950**Example** 3951 3952```js 3953 3954import audio from '@ohos.multimedia.audio'; 3955 3956const audioManager = audio.getAudioManager(); 3957let audioStreamManager = audioManager.getStreamManager(); 3958let resultFlag = false; 3959 3960audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => { 3961 for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { 3962 console.info(`## RendererChange on is called for ${i} ##`); 3963 console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`); 3964 console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`); 3965 console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`); 3966 console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`); 3967 console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`); 3968 console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`); 3969 let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors; 3970 for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) { 3971 console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`); 3972 console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`); 3973 console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`); 3974 console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`); 3975 console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`); 3976 console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`); 3977 console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`); 3978 console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks}`); 3979 } 3980 if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) { 3981 resultFlag = true; 3982 console.info(`ResultFlag for ${i} is: ${resultFlag}`); 3983 } 3984 } 3985}); 3986``` 3987 3988 3989## AudioCapturerChangeInfoArray<sup>9+</sup> 3990 3991Defines an **AudioCapturerChangeInfo** array, which is read-only. 3992 3993**System capability**: SystemCapability.Multimedia.Audio.Capturer 3994 3995## AudioCapturerChangeInfo<sup>9+</sup> 3996 3997Describes the audio capturer change event. 3998 3999**System capability**: SystemCapability.Multimedia.Audio.Capturer 4000 4001| Name | Type | Readable | Writable | Description | 4002| ------------- | ---------------------------------------- | -------- | -------- | ---------------------------------------------------------- | 4003| streamId | number | Yes | No | Unique ID of an audio stream. | 4004| clientUid | number | Yes | No | UID of the audio capturer client.<br>This is a system API. | 4005| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | No | Audio capturer information. | 4006| capturerState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API. | 4007 4008**Example** 4009 4010```js 4011import audio from '@ohos.multimedia.audio'; 4012 4013const audioManager = audio.getAudioManager(); 4014let audioStreamManager = audioManager.getStreamManager(); 4015 4016let resultFlag = false; 4017audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => { 4018 for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { 4019 console.info(`## CapChange on is called for element ${i} ##`); 4020 console.info(`StrId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`); 4021 console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`); 4022 console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`); 4023 console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`); 4024 console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`); 4025 let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors; 4026 for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) { 4027 console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`); 4028 console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`); 4029 console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`); 4030 console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`); 4031 console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`); 4032 console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`); 4033 console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`); 4034 console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`); 4035 } 4036 if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) { 4037 resultFlag = true; 4038 console.info(`ResultFlag for element ${i} is: ${resultFlag}`); 4039 } 4040 } 4041}); 4042``` 4043 4044## AudioDeviceDescriptors 4045 4046Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only. 4047 4048## AudioDeviceDescriptor 4049 4050Describes an audio device. 4051 4052**System capability**: SystemCapability.Multimedia.Audio.Device 4053 4054| Name | Type | Readable | Writable | Description | 4055| ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ | 4056| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role. | 4057| deviceType | [DeviceType](#devicetype) | Yes | No | Device type. | 4058| id<sup>9+</sup> | number | Yes | No | Device ID, which is unique. | 4059| name<sup>9+</sup> | string | Yes | No | Device name. | 4060| address<sup>9+</sup> | string | Yes | No | Device address. | 4061| sampleRates<sup>9+</sup> | Array<number> | Yes | No | Supported sampling rates. | 4062| channelCounts<sup>9+</sup> | Array<number> | Yes | No | Number of channels supported. | 4063| channelMasks<sup>9+</sup> | Array<number> | Yes | No | Supported channel masks. | 4064| networkId<sup>9+</sup> | string | Yes | No | ID of the device network.<br>This is a system API. | 4065| interruptGroupId<sup>9+</sup> | number | Yes | No | ID of the interruption group to which the device belongs.<br>This is a system API. | 4066| volumeGroupId<sup>9+</sup> | number | Yes | No | ID of the volume group to which the device belongs.<br>This is a system API. | 4067 4068**Example** 4069 4070```js 4071import audio from '@ohos.multimedia.audio'; 4072 4073function displayDeviceProp(value) { 4074 deviceRoleValue = value.deviceRole; 4075 deviceTypeValue = value.deviceType; 4076} 4077 4078let deviceRoleValue = null; 4079let deviceTypeValue = null; 4080const promise = audio.getAudioManager().getDevices(1); 4081promise.then(function (value) { 4082 console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG'); 4083 value.forEach(displayDeviceProp); 4084 if (deviceTypeValue != null && deviceRoleValue != null){ 4085 console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS'); 4086 } else { 4087 console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL'); 4088 } 4089}); 4090``` 4091 4092## AudioRendererFilter<sup>9+</sup> 4093 4094Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you must obtain an **AudioRendererFilter** instance. 4095 4096**System API**: This is a system API. 4097 4098| Name | Type | Mandatory | Description | 4099| ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ | 4100| uid | number | Yes | Application ID.<br> **System capability**: SystemCapability.Multimedia.Audio.Core | 4101| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No | Audio renderer information.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer | 4102| rendererId | number | No | Unique ID of an audio stream.<br> **System capability**: SystemCapability.Multimedia.Audio.Renderer | 4103 4104**Example** 4105 4106```js 4107let outputAudioRendererFilter = { 4108 "uid":20010041, 4109 "rendererInfo": { 4110 "contentType":audio.ContentType.CONTENT_TYPE_MUSIC, 4111 "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA, 4112 "rendererFlags":0 }, 4113 "rendererId":0 }; 4114``` 4115 4116## AudioRenderer<sup>8+</sup> 4117 4118Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance. 4119 4120### Attributes 4121 4122**System capability**: SystemCapability.Multimedia.Audio.Renderer 4123 4124| Name | Type | Readable | Writable | Description | 4125| ------------------ | -------------------------- | -------- | -------- | --------------------- | 4126| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio renderer state. | 4127 4128**Example** 4129 4130```js 4131let state = audioRenderer.state; 4132``` 4133 4134### getRendererInfo<sup>8+</sup> 4135 4136getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void 4137 4138Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result. 4139 4140**System capability**: SystemCapability.Multimedia.Audio.Renderer 4141 4142**Parameters** 4143 4144| Name | Type | Mandatory | Description | 4145| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | 4146| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information. | 4147 4148**Example** 4149 4150```js 4151audioRenderer.getRendererInfo((err, rendererInfo) => { 4152 console.info('Renderer GetRendererInfo:'); 4153 console.info(`Renderer content: ${rendererInfo.content}`); 4154 console.info(`Renderer usage: ${rendererInfo.usage}`); 4155 console.info(`Renderer flags: ${rendererInfo.rendererFlags}`); 4156}); 4157``` 4158 4159### getRendererInfo<sup>8+</sup> 4160 4161getRendererInfo(): Promise<AudioRendererInfo\> 4162 4163Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result. 4164 4165**System capability**: SystemCapability.Multimedia.Audio.Renderer 4166 4167**Return value** 4168 4169| Type | Description | 4170| -------------------------------------------------- | ------------------------------------------------ | 4171| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. | 4172 4173**Example** 4174 4175```js 4176audioRenderer.getRendererInfo().then((rendererInfo) => { 4177 console.info('Renderer GetRendererInfo:'); 4178 console.info(`Renderer content: ${rendererInfo.content}`); 4179 console.info(`Renderer usage: ${rendererInfo.usage}`); 4180 console.info(`Renderer flags: ${rendererInfo.rendererFlags}`) 4181}).catch((err) => { 4182 console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`); 4183}); 4184``` 4185 4186### getStreamInfo<sup>8+</sup> 4187 4188getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void 4189 4190Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result. 4191 4192**System capability**: SystemCapability.Multimedia.Audio.Renderer 4193 4194**Parameters** 4195 4196| Name | Type | Mandatory | Description | 4197| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- | 4198| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | 4199 4200**Example** 4201 4202```js 4203audioRenderer.getStreamInfo((err, streamInfo) => { 4204 console.info('Renderer GetStreamInfo:'); 4205 console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`); 4206 console.info(`Renderer channel: ${streamInfo.channels}`); 4207 console.info(`Renderer format: ${streamInfo.sampleFormat}`); 4208 console.info(`Renderer encoding type: ${streamInfo.encodingType}`); 4209}); 4210``` 4211 4212### getStreamInfo<sup>8+</sup> 4213 4214getStreamInfo(): Promise<AudioStreamInfo\> 4215 4216Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result. 4217 4218**System capability**: SystemCapability.Multimedia.Audio.Renderer 4219 4220**Return value** 4221 4222| Type | Description | 4223| :--------------------------------------------- | :--------------------------------------------- | 4224| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | 4225 4226**Example** 4227 4228```js 4229audioRenderer.getStreamInfo().then((streamInfo) => { 4230 console.info('Renderer GetStreamInfo:'); 4231 console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`); 4232 console.info(`Renderer channel: ${streamInfo.channels}`); 4233 console.info(`Renderer format: ${streamInfo.sampleFormat}`); 4234 console.info(`Renderer encoding type: ${streamInfo.encodingType}`); 4235}).catch((err) => { 4236 console.error(`ERROR: ${err}`); 4237}); 4238``` 4239 4240### getAudioStreamId<sup>9+</sup> 4241 4242getAudioStreamId(callback: AsyncCallback<number\>): void 4243 4244Obtains the stream ID of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result. 4245 4246**System capability**: SystemCapability.Multimedia.Audio.Renderer 4247 4248**Parameters** 4249 4250| Name | Type | Mandatory | Description | 4251| :------- | :--------------------- | :-------- | :------------------------------------- | 4252| callback | AsyncCallback<number\> | Yes | Callback used to return the stream ID. | 4253 4254**Example** 4255 4256```js 4257audioRenderer.getAudioStreamId((err, streamid) => { 4258 console.info(`Renderer GetStreamId: ${streamid}`); 4259}); 4260``` 4261 4262### getAudioStreamId<sup>9+</sup> 4263 4264getAudioStreamId(): Promise<number\> 4265 4266Obtains the stream ID of this **AudioRenderer** instance. This API uses a promise to return the result. 4267 4268**System capability**: SystemCapability.Multimedia.Audio.Renderer 4269 4270**Return value** 4271 4272| Type | Description | 4273| :--------------- | :------------------------------------ | 4274| Promise<number\> | Promise used to return the stream ID. | 4275 4276**Example** 4277 4278```js 4279audioRenderer.getAudioStreamId().then((streamid) => { 4280 console.info(`Renderer getAudioStreamId: ${streamid}`); 4281}).catch((err) => { 4282 console.error(`ERROR: ${err}`); 4283}); 4284``` 4285 4286### start<sup>8+</sup> 4287 4288start(callback: AsyncCallback<void\>): void 4289 4290Starts the renderer. This API uses an asynchronous callback to return the result. 4291 4292**System capability**: SystemCapability.Multimedia.Audio.Renderer 4293 4294**Parameters** 4295 4296| Name | Type | Mandatory | Description | 4297| -------- | -------------------- | --------- | ----------------------------------- | 4298| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4299 4300**Example** 4301 4302```js 4303audioRenderer.start((err) => { 4304 if (err) { 4305 console.error('Renderer start failed.'); 4306 } else { 4307 console.info('Renderer start success.'); 4308 } 4309}); 4310``` 4311 4312### start<sup>8+</sup> 4313 4314start(): Promise<void\> 4315 4316Starts the renderer. This API uses a promise to return the result. 4317 4318**System capability**: SystemCapability.Multimedia.Audio.Renderer 4319 4320**Return value** 4321 4322| Type | Description | 4323| -------------- | ---------------------------------- | 4324| Promise\<void> | Promise used to return the result. | 4325 4326**Example** 4327 4328```js 4329audioRenderer.start().then(() => { 4330 console.info('Renderer started'); 4331}).catch((err) => { 4332 console.error(`ERROR: ${err}`); 4333}); 4334``` 4335 4336### pause<sup>8+</sup> 4337 4338pause(callback: AsyncCallback\<void>): void 4339 4340Pauses rendering. This API uses an asynchronous callback to return the result. 4341 4342**System capability**: SystemCapability.Multimedia.Audio.Renderer 4343 4344**Parameters** 4345 4346| Name | Type | Mandatory | Description | 4347| -------- | -------------------- | --------- | ----------------------------------- | 4348| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4349 4350**Example** 4351 4352```js 4353audioRenderer.pause((err) => { 4354 if (err) { 4355 console.error('Renderer pause failed'); 4356 } else { 4357 console.info('Renderer paused.'); 4358 } 4359}); 4360``` 4361 4362### pause<sup>8+</sup> 4363 4364pause(): Promise\<void> 4365 4366Pauses rendering. This API uses a promise to return the result. 4367 4368**System capability**: SystemCapability.Multimedia.Audio.Renderer 4369 4370**Return value** 4371 4372| Type | Description | 4373| -------------- | ---------------------------------- | 4374| Promise\<void> | Promise used to return the result. | 4375 4376**Example** 4377 4378```js 4379audioRenderer.pause().then(() => { 4380 console.info('Renderer paused'); 4381}).catch((err) => { 4382 console.error(`ERROR: ${err}`); 4383}); 4384``` 4385 4386### drain<sup>8+</sup> 4387 4388drain(callback: AsyncCallback\<void>): void 4389 4390Drains the playback buffer. This API uses an asynchronous callback to return the result. 4391 4392**System capability**: SystemCapability.Multimedia.Audio.Renderer 4393 4394**Parameters** 4395 4396| Name | Type | Mandatory | Description | 4397| -------- | -------------------- | --------- | ----------------------------------- | 4398| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4399 4400**Example** 4401 4402```js 4403audioRenderer.drain((err) => { 4404 if (err) { 4405 console.error('Renderer drain failed'); 4406 } else { 4407 console.info('Renderer drained.'); 4408 } 4409}); 4410``` 4411 4412### drain<sup>8+</sup> 4413 4414drain(): Promise\<void> 4415 4416Drains the playback buffer. This API uses a promise to return the result. 4417 4418**System capability**: SystemCapability.Multimedia.Audio.Renderer 4419 4420**Return value** 4421 4422| Type | Description | 4423| -------------- | ---------------------------------- | 4424| Promise\<void> | Promise used to return the result. | 4425 4426**Example** 4427 4428```js 4429audioRenderer.drain().then(() => { 4430 console.info('Renderer drained successfully'); 4431}).catch((err) => { 4432 console.error(`ERROR: ${err}`); 4433}); 4434``` 4435 4436### stop<sup>8+</sup> 4437 4438stop(callback: AsyncCallback\<void>): void 4439 4440Stops rendering. This API uses an asynchronous callback to return the result. 4441 4442**System capability**: SystemCapability.Multimedia.Audio.Renderer 4443 4444**Parameters** 4445 4446| Name | Type | Mandatory | Description | 4447| -------- | -------------------- | --------- | ----------------------------------- | 4448| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4449 4450**Example** 4451 4452```js 4453audioRenderer.stop((err) => { 4454 if (err) { 4455 console.error('Renderer stop failed'); 4456 } else { 4457 console.info('Renderer stopped.'); 4458 } 4459}); 4460``` 4461 4462### stop<sup>8+</sup> 4463 4464stop(): Promise\<void> 4465 4466Stops rendering. This API uses a promise to return the result. 4467 4468**System capability**: SystemCapability.Multimedia.Audio.Renderer 4469 4470**Return value** 4471 4472| Type | Description | 4473| -------------- | ---------------------------------- | 4474| Promise\<void> | Promise used to return the result. | 4475 4476**Example** 4477 4478```js 4479audioRenderer.stop().then(() => { 4480 console.info('Renderer stopped successfully'); 4481}).catch((err) => { 4482 console.error(`ERROR: ${err}`); 4483}); 4484``` 4485 4486### release<sup>8+</sup> 4487 4488release(callback: AsyncCallback\<void>): void 4489 4490Releases the renderer. This API uses an asynchronous callback to return the result. 4491 4492**System capability**: SystemCapability.Multimedia.Audio.Renderer 4493 4494**Parameters** 4495 4496| Name | Type | Mandatory | Description | 4497| -------- | -------------------- | --------- | ----------------------------------- | 4498| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4499 4500**Example** 4501 4502```js 4503audioRenderer.release((err) => { 4504 if (err) { 4505 console.error('Renderer release failed'); 4506 } else { 4507 console.info('Renderer released.'); 4508 } 4509}); 4510``` 4511 4512### release<sup>8+</sup> 4513 4514release(): Promise\<void> 4515 4516Releases the renderer. This API uses a promise to return the result. 4517 4518**System capability**: SystemCapability.Multimedia.Audio.Renderer 4519 4520**Return value** 4521 4522| Type | Description | 4523| -------------- | ---------------------------------- | 4524| Promise\<void> | Promise used to return the result. | 4525 4526**Example** 4527 4528```js 4529audioRenderer.release().then(() => { 4530 console.info('Renderer released successfully'); 4531}).catch((err) => { 4532 console.error(`ERROR: ${err}`); 4533}); 4534``` 4535 4536### write<sup>8+</sup> 4537 4538write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void 4539 4540Writes the buffer. This API uses an asynchronous callback to return the result. 4541 4542**System capability**: SystemCapability.Multimedia.Audio.Renderer 4543 4544**Parameters** 4545 4546| Name | Type | Mandatory | Description | 4547| -------- | ---------------------- | --------- | ------------------------------------------------------------ | 4548| buffer | ArrayBuffer | Yes | Buffer to be written. | 4549| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. | 4550 4551**Example** 4552 4553```js 4554let bufferSize; 4555audioRenderer.getBufferSize().then((data)=> { 4556 console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); 4557 bufferSize = data; 4558 }).catch((err) => { 4559 console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); 4560 }); 4561console.info(`Buffer size: ${bufferSize}`); 4562let context = featureAbility.getContext(); 4563let path; 4564async function getCacheDir(){ 4565 path = await context.getCacheDir(); 4566} 4567let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; 4568let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY); 4569let stat = await fs.stat(path); 4570let buf = new ArrayBuffer(bufferSize); 4571let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); 4572for (let i = 0;i < len; i++) { 4573 let options = { 4574 offset: i * bufferSize, 4575 length: bufferSize 4576 } 4577 let readsize = await fs.read(file.fd, buf, options) 4578 let writeSize = await new Promise((resolve,reject)=>{ 4579 audioRenderer.write(buf,(err,writeSize)=>{ 4580 if(err){ 4581 reject(err) 4582 }else{ 4583 resolve(writeSize) 4584 } 4585 }) 4586 }) 4587} 4588``` 4589 4590### write<sup>8+</sup> 4591 4592write(buffer: ArrayBuffer): Promise\<number> 4593 4594Writes the buffer. This API uses a promise to return the result. 4595 4596**System capability**: SystemCapability.Multimedia.Audio.Renderer 4597 4598**Return value** 4599 4600| Type | Description | 4601| ---------------- | ------------------------------------------------------------ | 4602| Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. | 4603 4604**Example** 4605 4606```js 4607let bufferSize; 4608audioRenderer.getBufferSize().then((data) => { 4609 console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); 4610 bufferSize = data; 4611 }).catch((err) => { 4612 console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); 4613 }); 4614console.info(`BufferSize: ${bufferSize}`); 4615let context = featureAbility.getContext(); 4616let path; 4617async function getCacheDir(){ 4618 path = await context.getCacheDir(); 4619} 4620let filePath = path + '/StarWars10s-2C-48000-4SW.wav'; 4621let file = fs.openSync(filePath, fs.OpenMode.READ_ONLY); 4622let stat = await fs.stat(path); 4623let buf = new ArrayBuffer(bufferSize); 4624let len = stat.size % bufferSize == 0 ? Math.floor(stat.size / bufferSize) : Math.floor(stat.size / bufferSize + 1); 4625for (let i = 0;i < len; i++) { 4626 let options = { 4627 offset: i * bufferSize, 4628 length: bufferSize 4629 } 4630 let readsize = await fs.read(file.fd, buf, options) 4631 try{ 4632 let writeSize = await audioRenderer.write(buf); 4633 } catch(err) { 4634 console.error(`audioRenderer.write err: ${err}`); 4635 } 4636} 4637``` 4638 4639### getAudioTime<sup>8+</sup> 4640 4641getAudioTime(callback: AsyncCallback\<number>): void 4642 4643Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result. 4644 4645**System capability**: SystemCapability.Multimedia.Audio.Renderer 4646 4647**Parameters** 4648 4649| Name | Type | Mandatory | Description | 4650| -------- | ---------------------- | --------- | -------------------------------------- | 4651| callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp. | 4652 4653**Example** 4654 4655```js 4656audioRenderer.getAudioTime((err, timestamp) => { 4657 console.info(`Current timestamp: ${timestamp}`); 4658}); 4659``` 4660 4661### getAudioTime<sup>8+</sup> 4662 4663getAudioTime(): Promise\<number> 4664 4665Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result. 4666 4667**System capability**: SystemCapability.Multimedia.Audio.Renderer 4668 4669**Return value** 4670 4671| Type | Description | 4672| ---------------- | ------------------------------------- | 4673| Promise\<number> | Promise used to return the timestamp. | 4674 4675**Example** 4676 4677```js 4678audioRenderer.getAudioTime().then((timestamp) => { 4679 console.info(`Current timestamp: ${timestamp}`); 4680}).catch((err) => { 4681 console.error(`ERROR: ${err}`); 4682}); 4683``` 4684 4685### getBufferSize<sup>8+</sup> 4686 4687getBufferSize(callback: AsyncCallback\<number>): void 4688 4689Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result. 4690 4691**System capability**: SystemCapability.Multimedia.Audio.Renderer 4692 4693**Parameters** 4694 4695| Name | Type | Mandatory | Description | 4696| -------- | ---------------------- | --------- | ---------------------------------------- | 4697| callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size. | 4698 4699**Example** 4700 4701```js 4702let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => { 4703 if (err) { 4704 console.error('getBufferSize error'); 4705 } 4706}); 4707``` 4708 4709### getBufferSize<sup>8+</sup> 4710 4711getBufferSize(): Promise\<number> 4712 4713Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result. 4714 4715**System capability**: SystemCapability.Multimedia.Audio.Renderer 4716 4717**Return value** 4718 4719| Type | Description | 4720| ---------------- | --------------------------------------- | 4721| Promise\<number> | Promise used to return the buffer size. | 4722 4723**Example** 4724 4725```js 4726let bufferSize; 4727audioRenderer.getBufferSize().then((data) => { 4728 console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); 4729 bufferSize = data; 4730}).catch((err) => { 4731 console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); 4732}); 4733``` 4734 4735### setRenderRate<sup>8+</sup> 4736 4737setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void 4738 4739Sets the render rate. This API uses an asynchronous callback to return the result. 4740 4741**System capability**: SystemCapability.Multimedia.Audio.Renderer 4742 4743**Parameters** 4744 4745| Name | Type | Mandatory | Description | 4746| -------- | ---------------------------------------- | --------- | ----------------------------------- | 4747| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | 4748| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4749 4750**Example** 4751 4752```js 4753audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => { 4754 if (err) { 4755 console.error('Failed to set params'); 4756 } else { 4757 console.info('Callback invoked to indicate a successful render rate setting.'); 4758 } 4759}); 4760``` 4761 4762### setRenderRate<sup>8+</sup> 4763 4764setRenderRate(rate: AudioRendererRate): Promise\<void> 4765 4766Sets the render rate. This API uses a promise to return the result. 4767 4768**System capability**: SystemCapability.Multimedia.Audio.Renderer 4769 4770**Parameters** 4771 4772| Name | Type | Mandatory | Description | 4773| ---- | ---------------------------------------- | --------- | ------------------ | 4774| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | 4775 4776**Return value** 4777 4778| Type | Description | 4779| -------------- | ---------------------------------- | 4780| Promise\<void> | Promise used to return the result. | 4781 4782**Example** 4783 4784```js 4785audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => { 4786 console.info('setRenderRate SUCCESS'); 4787}).catch((err) => { 4788 console.error(`ERROR: ${err}`); 4789}); 4790``` 4791 4792### getRenderRate<sup>8+</sup> 4793 4794getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void 4795 4796Obtains the current render rate. This API uses an asynchronous callback to return the result. 4797 4798**System capability**: SystemCapability.Multimedia.Audio.Renderer 4799 4800**Parameters** 4801 4802| Name | Type | Mandatory | Description | 4803| -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- | 4804| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate. | 4805 4806**Example** 4807 4808```js 4809audioRenderer.getRenderRate((err, renderrate) => { 4810 console.info(`getRenderRate: ${renderrate}`); 4811}); 4812``` 4813 4814### getRenderRate<sup>8+</sup> 4815 4816getRenderRate(): Promise\<AudioRendererRate> 4817 4818Obtains the current render rate. This API uses a promise to return the result. 4819 4820**System capability**: SystemCapability.Multimedia.Audio.Renderer 4821 4822**Return value** 4823 4824| Type | Description | 4825| ------------------------------------------------- | --------------------------------------------- | 4826| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. | 4827 4828**Example** 4829 4830```js 4831audioRenderer.getRenderRate().then((renderRate) => { 4832 console.info(`getRenderRate: ${renderRate}`); 4833}).catch((err) => { 4834 console.error(`ERROR: ${err}`); 4835}); 4836``` 4837### setInterruptMode<sup>9+</sup> 4838 4839setInterruptMode(mode: InterruptMode): Promise<void> 4840 4841Sets the audio interruption mode for the application. This API uses a promise to return the result. 4842 4843**System capability**: SystemCapability.Multimedia.Audio.Interrupt 4844 4845**Parameters** 4846 4847| Name | Type | Mandatory | Description | 4848| ---- | -------------------------------- | --------- | ------------------------ | 4849| mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. | 4850 4851**Return value** 4852 4853| Type | Description | 4854| ------------------- | ------------------------------------------------------------ | 4855| Promise<void> | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. | 4856 4857**Example** 4858 4859```js 4860let mode = 0; 4861audioRenderer.setInterruptMode(mode).then(data=>{ 4862 console.info('setInterruptMode Success!'); 4863}).catch((err) => { 4864 console.error(`setInterruptMode Fail: ${err}`); 4865}); 4866``` 4867### setInterruptMode<sup>9+</sup> 4868 4869setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void 4870 4871Sets the audio interruption mode for the application. This API uses an asynchronous callback to return the result. 4872 4873**System capability**: SystemCapability.Multimedia.Audio.Interrupt 4874 4875**Parameters** 4876 4877| Name | Type | Mandatory | Description | 4878| -------- | -------------------------------- | --------- | ----------------------------------- | 4879| mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. | 4880| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4881 4882**Example** 4883 4884```js 4885let mode = 1; 4886audioRenderer.setInterruptMode(mode, (err, data)=>{ 4887 if(err){ 4888 console.error(`setInterruptMode Fail: ${err}`); 4889 } 4890 console.info('setInterruptMode Success!'); 4891}); 4892``` 4893 4894### setVolume<sup>9+</sup> 4895 4896setVolume(volume: number): Promise<void> 4897 4898Sets the volume for the application. This API uses a promise to return the result. 4899 4900**System capability**: SystemCapability.Multimedia.Audio.Renderer 4901 4902**Parameters** 4903 4904| Name | Type | Mandatory | Description | 4905| ------ | ------ | --------- | ------------------------------------------------------------ | 4906| volume | number | Yes | Volume to set, which can be within the range from 0.0 to 1.0. | 4907 4908**Return value** 4909 4910| Type | Description | 4911| ------------------- | ------------------------------------------------------------ | 4912| Promise<void> | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. | 4913 4914**Example** 4915 4916```js 4917audioRenderer.setVolume(0.5).then(data=>{ 4918 console.info('setVolume Success!'); 4919}).catch((err) => { 4920 console.error(`setVolume Fail: ${err}`); 4921}); 4922``` 4923### setVolume<sup>9+</sup> 4924 4925setVolume(volume: number, callback: AsyncCallback\<void>): void 4926 4927Sets the volume for the application. This API uses an asynchronous callback to return the result. 4928 4929**System capability**: SystemCapability.Multimedia.Audio.Renderer 4930 4931**Parameters** 4932 4933| Name | Type | Mandatory | Description | 4934| -------- | -------------------- | --------- | ------------------------------------------------------------ | 4935| volume | number | Yes | Volume to set, which can be within the range from 0.0 to 1.0. | 4936| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 4937 4938**Example** 4939 4940```js 4941audioRenderer.setVolume(0.5, (err, data)=>{ 4942 if(err){ 4943 console.error(`setVolume Fail: ${err}`); 4944 } 4945 console.info('setVolume Success!'); 4946}); 4947``` 4948 4949### on('audioInterrupt')<sup>9+</sup> 4950 4951on(type: 'audioInterrupt', callback: Callback\<InterruptEvent>): void 4952 4953Subscribes to audio interruption events. This API uses a callback to get interrupt events. 4954 4955Same as [on('interrupt')](#oninterruptdeprecated), this API has obtained the focus before **start**, **pause**, or **stop** of **AudioRenderer** is called. Therefore, you do not need to request the focus. 4956 4957**System capability**: SystemCapability.Multimedia.Audio.Interrupt 4958 4959**Parameters** 4960 4961| Name | Type | Mandatory | Description | 4962| -------- | -------------------------------------------- | --------- | ------------------------------------------------------------ | 4963| type | string | Yes | Event type. The value **'audioInterrupt'** means the audio interruption event, which is triggered when audio playback is interrupted. | 4964| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. | 4965 4966**Error codes** 4967 4968For details about the error codes, see [Audio Error Codes](../errorcodes/errorcode-audio.md). 4969 4970| ID | Error Message | 4971| ------- | ------------------------------ | 4972| 6800101 | if input parameter value error | 4973 4974**Example** 4975 4976```js 4977let isPlay; 4978let started; 4979onAudioInterrupt(); 4980 4981async function onAudioInterrupt(){ 4982 audioRenderer.on('audioInterrupt', async(interruptEvent) => { 4983 if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { 4984 switch (interruptEvent.hintType) { 4985 case audio.InterruptHint.INTERRUPT_HINT_PAUSE: 4986 console.info('Force paused. Stop writing'); 4987 isPlay = false; 4988 break; 4989 case audio.InterruptHint.INTERRUPT_HINT_STOP: 4990 console.info('Force stopped. Stop writing'); 4991 isPlay = false; 4992 break; 4993 } 4994 } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) { 4995 switch (interruptEvent.hintType) { 4996 case audio.InterruptHint.INTERRUPT_HINT_RESUME: 4997 console.info('Resume force paused renderer or ignore'); 4998 await audioRenderer.start().then(async function () { 4999 console.info('AudioInterruptMusic: renderInstant started :SUCCESS '); 5000 started = true; 5001 }).catch((err) => { 5002 console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err}`); 5003 started = false; 5004 }); 5005 if (started) { 5006 isPlay = true; 5007 console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`); 5008 } else { 5009 console.error('AudioInterruptMusic Renderer start failed'); 5010 } 5011 break; 5012 case audio.InterruptHint.INTERRUPT_HINT_PAUSE: 5013 console.info('Choose to pause or ignore'); 5014 if (isPlay == true) { 5015 isPlay == false; 5016 console.info('AudioInterruptMusic: Media PAUSE : TRUE'); 5017 } else { 5018 isPlay = true; 5019 console.info('AudioInterruptMusic: Media PLAY : TRUE'); 5020 } 5021 break; 5022 } 5023 } 5024 }); 5025} 5026``` 5027 5028### on('markReach')<sup>8+</sup> 5029 5030on(type: "markReach", frame: number, callback: Callback<number>): void 5031 5032Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is invoked. 5033 5034**System capability**: SystemCapability.Multimedia.Audio.Renderer 5035 5036**Parameters** 5037 5038| Name | Type | Mandatory | Description | 5039| :------- | :---------------- | :-------- | :----------------------------------------------------------- | 5040| type | string | Yes | Event type. The value is fixed at **'markReach'**. | 5041| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | 5042| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. | 5043 5044**Example** 5045 5046```js 5047audioRenderer.on('markReach', 1000, (position) => { 5048 if (position == 1000) { 5049 console.info('ON Triggered successfully'); 5050 } 5051}); 5052``` 5053 5054 5055### off('markReach') <sup>8+</sup> 5056 5057off(type: 'markReach'): void 5058 5059Unsubscribes from mark reached events. 5060 5061**System capability**: SystemCapability.Multimedia.Audio.Renderer 5062 5063**Parameters** 5064 5065| Name | Type | Mandatory | Description | 5066| :--- | :----- | :-------- | :------------------------------------------------- | 5067| type | string | Yes | Event type. The value is fixed at **'markReach'**. | 5068 5069**Example** 5070 5071```js 5072audioRenderer.off('markReach'); 5073``` 5074 5075### on('periodReach') <sup>8+</sup> 5076 5077on(type: "periodReach", frame: number, callback: Callback<number>): void 5078 5079Subscribes to period reached events. When the number of frames rendered reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned. 5080 5081**System capability**: SystemCapability.Multimedia.Audio.Renderer 5082 5083**Parameters** 5084 5085| Name | Type | Mandatory | Description | 5086| :------- | :---------------- | :-------- | :----------------------------------------------------------- | 5087| type | string | Yes | Event type. The value is fixed at **'periodReach'**. | 5088| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | 5089| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. | 5090 5091**Example** 5092 5093```js 5094audioRenderer.on('periodReach', 1000, (position) => { 5095 if (position == 1000) { 5096 console.info('ON Triggered successfully'); 5097 } 5098}); 5099``` 5100 5101### off('periodReach') <sup>8+</sup> 5102 5103off(type: 'periodReach'): void 5104 5105Unsubscribes from period reached events. 5106 5107**System capability**: SystemCapability.Multimedia.Audio.Renderer 5108 5109**Parameters** 5110 5111| Name | Type | Mandatory | Description | 5112| :--- | :----- | :-------- | :--------------------------------------------------- | 5113| type | string | Yes | Event type. The value is fixed at **'periodReach'**. | 5114 5115**Example** 5116 5117```js 5118audioRenderer.off('periodReach') 5119``` 5120 5121### on('stateChange') <sup>8+</sup> 5122 5123on(type: 'stateChange', callback: Callback<AudioState\>): void 5124 5125Subscribes to state change events. 5126 5127**System capability**: SystemCapability.Multimedia.Audio.Renderer 5128 5129**Parameters** 5130 5131| Name | Type | Mandatory | Description | 5132| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- | 5133| type | string | Yes | Event type. The value **stateChange** means the state change event. | 5134| callback | Callback\<[AudioState](#audiostate8)> | Yes | Callback used to return the state change. | 5135 5136**Example** 5137 5138```js 5139audioRenderer.on('stateChange', (state) => { 5140 if (state == 1) { 5141 console.info('audio renderer state is: STATE_PREPARED'); 5142 } 5143 if (state == 2) { 5144 console.info('audio renderer state is: STATE_RUNNING'); 5145 } 5146}); 5147``` 5148 5149## AudioCapturer<sup>8+</sup> 5150 5151Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance. 5152 5153### Attributes 5154 5155**System capability**: SystemCapability.Multimedia.Audio.Capturer 5156 5157| Name | Type | Readable | Writable | Description | 5158| :----------------- | :------------------------- | :------- | :------- | :-------------------- | 5159| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio capturer state. | 5160 5161**Example** 5162 5163```js 5164let state = audioCapturer.state; 5165``` 5166 5167### getCapturerInfo<sup>8+</sup> 5168 5169getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void 5170 5171Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result. 5172 5173**System capability**: SystemCapability.Multimedia.Audio.Capturer 5174 5175**Parameters** 5176 5177| Name | Type | Mandatory | Description | 5178| :------- | :-------------------------------- | :-------- | :------------------------------------------------ | 5179| callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information. | 5180 5181**Example** 5182 5183```js 5184audioCapturer.getCapturerInfo((err, capturerInfo) => { 5185 if (err) { 5186 console.error('Failed to get capture info'); 5187 } else { 5188 console.info('Capturer getCapturerInfo:'); 5189 console.info(`Capturer source: ${capturerInfo.source}`); 5190 console.info(`Capturer flags: ${capturerInfo.capturerFlags}`); 5191 } 5192}); 5193``` 5194 5195 5196### getCapturerInfo<sup>8+</sup> 5197 5198getCapturerInfo(): Promise<AudioCapturerInfo\> 5199 5200Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result. 5201 5202**System capability**: SystemCapability.Multimedia.Audio.Capturer 5203 5204**Return value** 5205 5206| Type | Description | 5207| :------------------------------------------------ | :----------------------------------------------- | 5208| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. | 5209 5210**Example** 5211 5212```js 5213audioCapturer.getCapturerInfo().then((audioParamsGet) => { 5214 if (audioParamsGet != undefined) { 5215 console.info('AudioFrameworkRecLog: Capturer CapturerInfo:'); 5216 console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`); 5217 console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`); 5218 } else { 5219 console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`); 5220 console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect'); 5221 } 5222}).catch((err) => { 5223 console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`); 5224}); 5225``` 5226 5227### getStreamInfo<sup>8+</sup> 5228 5229getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void 5230 5231Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result. 5232 5233**System capability**: SystemCapability.Multimedia.Audio.Capturer 5234 5235**Parameters** 5236 5237| Name | Type | Mandatory | Description | 5238| :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- | 5239| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | 5240 5241**Example** 5242 5243```js 5244audioCapturer.getStreamInfo((err, streamInfo) => { 5245 if (err) { 5246 console.error('Failed to get stream info'); 5247 } else { 5248 console.info('Capturer GetStreamInfo:'); 5249 console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`); 5250 console.info(`Capturer channel: ${streamInfo.channels}`); 5251 console.info(`Capturer format: ${streamInfo.sampleFormat}`); 5252 console.info(`Capturer encoding type: ${streamInfo.encodingType}`); 5253 } 5254}); 5255``` 5256 5257### getStreamInfo<sup>8+</sup> 5258 5259getStreamInfo(): Promise<AudioStreamInfo\> 5260 5261Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result. 5262 5263**System capability**: SystemCapability.Multimedia.Audio.Capturer 5264 5265**Return value** 5266 5267| Type | Description | 5268| :--------------------------------------------- | :--------------------------------------------- | 5269| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | 5270 5271**Example** 5272 5273```js 5274audioCapturer.getStreamInfo().then((audioParamsGet) => { 5275 console.info('getStreamInfo:'); 5276 console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`); 5277 console.info(`samplingRate: ${audioParamsGet.samplingRate}`); 5278 console.info(`channels: ${audioParamsGet.channels}`); 5279 console.info(`encodingType: ${audioParamsGet.encodingType}`); 5280}).catch((err) => { 5281 console.error(`getStreamInfo :ERROR: ${err}`); 5282}); 5283``` 5284 5285### getAudioStreamId<sup>9+</sup> 5286 5287getAudioStreamId(callback: AsyncCallback<number\>): void 5288 5289Obtains the stream ID of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result. 5290 5291**System capability**: SystemCapability.Multimedia.Audio.Capturer 5292 5293**Parameters** 5294 5295| Name | Type | Mandatory | Description | 5296| :------- | :--------------------- | :-------- | :------------------------------------- | 5297| callback | AsyncCallback<number\> | Yes | Callback used to return the stream ID. | 5298 5299**Example** 5300 5301```js 5302audioCapturer.getAudioStreamId((err, streamid) => { 5303 console.info(`audioCapturer GetStreamId: ${streamid}`); 5304}); 5305``` 5306 5307### getAudioStreamId<sup>9+</sup> 5308 5309getAudioStreamId(): Promise<number\> 5310 5311Obtains the stream ID of this **AudioCapturer** instance. This API uses a promise to return the result. 5312 5313**System capability**: SystemCapability.Multimedia.Audio.Capturer 5314 5315**Return value** 5316 5317| Type | Description | 5318| :--------------- | :------------------------------------ | 5319| Promise<number\> | Promise used to return the stream ID. | 5320 5321**Example** 5322 5323```js 5324audioCapturer.getAudioStreamId().then((streamid) => { 5325 console.info(`audioCapturer getAudioStreamId: ${streamid}`); 5326}).catch((err) => { 5327 console.error(`ERROR: ${err}`); 5328}); 5329``` 5330 5331### start<sup>8+</sup> 5332 5333start(callback: AsyncCallback<void\>): void 5334 5335Starts capturing. This API uses an asynchronous callback to return the result. 5336 5337**System capability**: SystemCapability.Multimedia.Audio.Capturer 5338 5339**Parameters** 5340 5341| Name | Type | Mandatory | Description | 5342| :------- | :------------------- | :-------- | :---------------------------------- | 5343| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5344 5345**Example** 5346 5347```js 5348audioCapturer.start((err) => { 5349 if (err) { 5350 console.error('Capturer start failed.'); 5351 } else { 5352 console.info('Capturer start success.'); 5353 } 5354}); 5355``` 5356 5357 5358### start<sup>8+</sup> 5359 5360start(): Promise<void\> 5361 5362Starts capturing. This API uses a promise to return the result. 5363 5364**System capability**: SystemCapability.Multimedia.Audio.Capturer 5365 5366**Return value** 5367 5368| Type | Description | 5369| :------------- | :--------------------------------- | 5370| Promise<void\> | Promise used to return the result. | 5371 5372**Example** 5373 5374```js 5375audioCapturer.start().then(() => { 5376 console.info('AudioFrameworkRecLog: ---------START---------'); 5377 console.info('AudioFrameworkRecLog: Capturer started: SUCCESS'); 5378 console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`); 5379 console.info('AudioFrameworkRecLog: Capturer started: SUCCESS'); 5380 if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) { 5381 console.info('AudioFrameworkRecLog: AudioCapturer is in Running State'); 5382 } 5383}).catch((err) => { 5384 console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`); 5385}); 5386``` 5387 5388### stop<sup>8+</sup> 5389 5390stop(callback: AsyncCallback<void\>): void 5391 5392Stops capturing. This API uses an asynchronous callback to return the result. 5393 5394**System capability**: SystemCapability.Multimedia.Audio.Capturer 5395 5396**Parameters** 5397 5398| Name | Type | Mandatory | Description | 5399| :------- | :------------------- | :-------- | :---------------------------------- | 5400| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5401 5402**Example** 5403 5404```js 5405audioCapturer.stop((err) => { 5406 if (err) { 5407 console.error('Capturer stop failed'); 5408 } else { 5409 console.info('Capturer stopped.'); 5410 } 5411}); 5412``` 5413 5414 5415### stop<sup>8+</sup> 5416 5417stop(): Promise<void\> 5418 5419Stops capturing. This API uses a promise to return the result. 5420 5421**System capability**: SystemCapability.Multimedia.Audio.Capturer 5422 5423**Return value** 5424 5425| Type | Description | 5426| :------------- | :--------------------------------- | 5427| Promise<void\> | Promise used to return the result. | 5428 5429**Example** 5430 5431```js 5432audioCapturer.stop().then(() => { 5433 console.info('AudioFrameworkRecLog: ---------STOP RECORD---------'); 5434 console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS'); 5435 if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){ 5436 console.info('AudioFrameworkRecLog: State is Stopped:'); 5437 } 5438}).catch((err) => { 5439 console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`); 5440}); 5441``` 5442 5443### release<sup>8+</sup> 5444 5445release(callback: AsyncCallback<void\>): void 5446 5447Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result. 5448 5449**System capability**: SystemCapability.Multimedia.Audio.Capturer 5450 5451**Parameters** 5452 5453| Name | Type | Mandatory | Description | 5454| :------- | :------------------- | :-------- | :---------------------------------- | 5455| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5456 5457**Example** 5458 5459```js 5460audioCapturer.release((err) => { 5461 if (err) { 5462 console.error('capturer release failed'); 5463 } else { 5464 console.info('capturer released.'); 5465 } 5466}); 5467``` 5468 5469 5470### release<sup>8+</sup> 5471 5472release(): Promise<void\> 5473 5474Releases this **AudioCapturer** instance. This API uses a promise to return the result. 5475 5476**System capability**: SystemCapability.Multimedia.Audio.Capturer 5477 5478**Return value** 5479 5480| Type | Description | 5481| :------------- | :--------------------------------- | 5482| Promise<void\> | Promise used to return the result. | 5483 5484**Example** 5485 5486```js 5487let stateFlag; 5488audioCapturer.release().then(() => { 5489 console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); 5490 console.info('AudioFrameworkRecLog: Capturer release : SUCCESS'); 5491 console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`); 5492 console.info(`AudioFrameworkRecLog: stateFlag : ${stateFlag}`); 5493}).catch((err) => { 5494 console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`); 5495}); 5496``` 5497 5498### read<sup>8+</sup> 5499 5500read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void 5501 5502Reads the buffer. This API uses an asynchronous callback to return the result. 5503 5504**System capability**: SystemCapability.Multimedia.Audio.Capturer 5505 5506**Parameters** 5507 5508| Name | Type | Mandatory | Description | 5509| :------------- | :-------------------------- | :-------- | :----------------------------------- | 5510| size | number | Yes | Number of bytes to read. | 5511| isBlockingRead | boolean | Yes | Whether to block the read operation. | 5512| callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer. | 5513 5514**Example** 5515 5516```js 5517let bufferSize; 5518audioCapturer.getBufferSize().then((data) => { 5519 console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`); 5520 bufferSize = data; 5521 }).catch((err) => { 5522 console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`); 5523 }); 5524audioCapturer.read(bufferSize, true, async(err, buffer) => { 5525 if (!err) { 5526 console.info('Success in reading the buffer data'); 5527 } 5528}); 5529``` 5530 5531### read<sup>8+</sup> 5532 5533read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\> 5534 5535Reads the buffer. This API uses a promise to return the result. 5536 5537**System capability**: SystemCapability.Multimedia.Audio.Capturer 5538 5539**Parameters** 5540 5541| Name | Type | Mandatory | Description | 5542| :------------- | :------ | :-------- | :----------------------------------- | 5543| size | number | Yes | Number of bytes to read. | 5544| isBlockingRead | boolean | Yes | Whether to block the read operation. | 5545 5546**Return value** 5547 5548| Type | Description | 5549| :-------------------- | :----------------------------------------------------------- | 5550| Promise<ArrayBuffer\> | Promise used to return the result. If the operation is successful, the buffer data read is returned; otherwise, an error code is returned. | 5551 5552**Example** 5553 5554```js 5555let bufferSize; 5556audioCapturer.getBufferSize().then((data) => { 5557 console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`); 5558 bufferSize = data; 5559 }).catch((err) => { 5560 console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`); 5561 }); 5562console.info(`Buffer size: ${bufferSize}`); 5563audioCapturer.read(bufferSize, true).then((buffer) => { 5564 console.info('buffer read successfully'); 5565}).catch((err) => { 5566 console.info(`ERROR : ${err}`); 5567}); 5568``` 5569 5570### getAudioTime<sup>8+</sup> 5571 5572getAudioTime(callback: AsyncCallback<number\>): void 5573 5574Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result. 5575 5576**System capability**: SystemCapability.Multimedia.Audio.Capturer 5577 5578**Parameters** 5579 5580| Name | Type | Mandatory | Description | 5581| :------- | :--------------------- | :-------- | :---------------------------------- | 5582| callback | AsyncCallback<number\> | Yes | Callback used to return the result. | 5583 5584**Example** 5585 5586```js 5587audioCapturer.getAudioTime((err, timestamp) => { 5588 console.info(`Current timestamp: ${timestamp}`); 5589}); 5590``` 5591 5592### getAudioTime<sup>8+</sup> 5593 5594getAudioTime(): Promise<number\> 5595 5596Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result. 5597 5598**System capability**: SystemCapability.Multimedia.Audio.Capturer 5599 5600**Return value** 5601 5602| Type | Description | 5603| :--------------- | :------------------------------------ | 5604| Promise<number\> | Promise used to return the timestamp. | 5605 5606**Example** 5607 5608```js 5609audioCapturer.getAudioTime().then((audioTime) => { 5610 console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`); 5611}).catch((err) => { 5612 console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`); 5613}); 5614``` 5615 5616### getBufferSize<sup>8+</sup> 5617 5618getBufferSize(callback: AsyncCallback<number\>): void 5619 5620Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result. 5621 5622**System capability**: SystemCapability.Multimedia.Audio.Capturer 5623 5624**Parameters** 5625 5626| Name | Type | Mandatory | Description | 5627| :------- | :--------------------- | :-------- | :--------------------------------------- | 5628| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | 5629 5630**Example** 5631 5632```js 5633audioCapturer.getBufferSize((err, bufferSize) => { 5634 if (!err) { 5635 console.info(`BufferSize : ${bufferSize}`); 5636 audioCapturer.read(bufferSize, true).then((buffer) => { 5637 console.info(`Buffer read is ${buffer}`); 5638 }).catch((err) => { 5639 console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`); 5640 }); 5641 } 5642}); 5643``` 5644 5645### getBufferSize<sup>8+</sup> 5646 5647getBufferSize(): Promise<number\> 5648 5649Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result. 5650 5651**System capability**: SystemCapability.Multimedia.Audio.Capturer 5652 5653**Return value** 5654 5655| Type | Description | 5656| :--------------- | :-------------------------------------- | 5657| Promise<number\> | Promise used to return the buffer size. | 5658 5659**Example** 5660 5661```js 5662let bufferSize; 5663audioCapturer.getBufferSize().then((data) => { 5664 console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`); 5665 bufferSize = data; 5666}).catch((err) => { 5667 console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`); 5668}); 5669``` 5670 5671### on('markReach')<sup>8+</sup> 5672 5673on(type: "markReach", frame: number, callback: Callback<number>): void 5674 5675Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is invoked. 5676 5677**System capability**: SystemCapability.Multimedia.Audio.Capturer 5678 5679**Parameters** 5680 5681| Name | Type | Mandatory | Description | 5682| :------- | :---------------- | :-------- | :----------------------------------------------------------- | 5683| type | string | Yes | Event type. The value is fixed at **'markReach'**. | 5684| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | 5685| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. | 5686 5687**Example** 5688 5689```js 5690audioCapturer.on('markReach', 1000, (position) => { 5691 if (position == 1000) { 5692 console.info('ON Triggered successfully'); 5693 } 5694}); 5695``` 5696 5697### off('markReach')<sup>8+</sup> 5698 5699off(type: 'markReach'): void 5700 5701Unsubscribes from mark reached events. 5702 5703**System capability**: SystemCapability.Multimedia.Audio.Capturer 5704 5705**Parameters** 5706 5707| Name | Type | Mandatory | Description | 5708| :--- | :----- | :-------- | :------------------------------------------------- | 5709| type | string | Yes | Event type. The value is fixed at **'markReach'**. | 5710 5711**Example** 5712 5713```js 5714audioCapturer.off('markReach'); 5715``` 5716 5717### on('periodReach')<sup>8+</sup> 5718 5719on(type: "periodReach", frame: number, callback: Callback<number>): void 5720 5721Subscribes to period reached events. When the number of frames captured reaches the value of the **frame** parameter, a callback is triggered and the specified value is returned. 5722 5723**System capability**: SystemCapability.Multimedia.Audio.Capturer 5724 5725**Parameters** 5726 5727| Name | Type | Mandatory | Description | 5728| :------- | :---------------- | :-------- | :----------------------------------------------------------- | 5729| type | string | Yes | Event type. The value is fixed at **'periodReach'**. | 5730| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | 5731| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. | 5732 5733**Example** 5734 5735```js 5736audioCapturer.on('periodReach', 1000, (position) => { 5737 if (position == 1000) { 5738 console.info('ON Triggered successfully'); 5739 } 5740}); 5741``` 5742 5743### off('periodReach')<sup>8+</sup> 5744 5745off(type: 'periodReach'): void 5746 5747Unsubscribes from period reached events. 5748 5749**System capability**: SystemCapability.Multimedia.Audio.Capturer 5750 5751**Parameters** 5752 5753| Name | Type | Mandatory | Description | 5754| :--- | :----- | :-------- | :--------------------------------------------------- | 5755| type | string | Yes | Event type. The value is fixed at **'periodReach'**. | 5756 5757**Example** 5758 5759```js 5760audioCapturer.off('periodReach') 5761``` 5762 5763### on('stateChange') <sup>8+</sup> 5764 5765on(type: 'stateChange', callback: Callback<AudioState\>): void 5766 5767Subscribes to state change events. 5768 5769**System capability**: SystemCapability.Multimedia.Audio.Capturer 5770 5771**Parameters** 5772 5773| Name | Type | Mandatory | Description | 5774| :------- | :------------------------------------ | :-------- | :----------------------------------------------------------- | 5775| type | string | Yes | Event type. The value **stateChange** means the state change event. | 5776| callback | Callback\<[AudioState](#audiostate8)> | Yes | Callback used to return the state change. | 5777 5778**Example** 5779 5780```js 5781audioCapturer.on('stateChange', (state) => { 5782 if (state == 1) { 5783 console.info('audio capturer state is: STATE_PREPARED'); 5784 } 5785 if (state == 2) { 5786 console.info('audio capturer state is: STATE_RUNNING'); 5787 } 5788}); 5789``` 5790 5791## ToneType<sup>9+</sup> 5792 5793Enumerates the tone types of the player. 5794 5795**System API**: This is a system API. 5796 5797**System capability**: SystemCapability.Multimedia.Audio.Tone 5798 5799| Name | Value | Description | 5800| :----------------------------------------------- | :---- | :-------------------------------------------- | 5801| TONE_TYPE_DIAL_0 | 0 | DTMF tone of key 0. | 5802| TONE_TYPE_DIAL_1 | 1 | DTMF tone of key 1. | 5803| TONE_TYPE_DIAL_2 | 2 | DTMF tone of key 2. | 5804| TONE_TYPE_DIAL_3 | 3 | DTMF tone of key 3. | 5805| TONE_TYPE_DIAL_4 | 4 | DTMF tone of key 4. | 5806| TONE_TYPE_DIAL_5 | 5 | DTMF tone of key 5. | 5807| TONE_TYPE_DIAL_6 | 6 | DTMF tone of key 6. | 5808| TONE_TYPE_DIAL_7 | 7 | DTMF tone of key 7. | 5809| TONE_TYPE_DIAL_8 | 8 | DTMF tone of key 8. | 5810| TONE_TYPE_DIAL_9 | 9 | DTMF tone of key 9. | 5811| TONE_TYPE_DIAL_S | 10 | DTMF tone of the star key (*). | 5812| TONE_TYPE_DIAL_P | 11 | DTMF tone of the pound key (#). | 5813| TONE_TYPE_DIAL_A | 12 | DTMF tone of key A. | 5814| TONE_TYPE_DIAL_B | 13 | DTMF tone of key B. | 5815| TONE_TYPE_DIAL_C | 14 | DTMF tone of key C. | 5816| TONE_TYPE_DIAL_D | 15 | DTMF tone of key D. | 5817| TONE_TYPE_COMMON_SUPERVISORY_DIAL | 100 | Supervisory tone - dial tone. | 5818| TONE_TYPE_COMMON_SUPERVISORY_BUSY | 101 | Supervisory tone - busy. | 5819| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION | 102 | Supervisory tone - congestion. | 5820| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK | 103 | Supervisory tone - radio path acknowledgment. | 5821| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104 | Supervisory tone - radio path not available. | 5822| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING | 106 | Supervisory tone - call waiting tone. | 5823| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE | 107 | Supervisory tone - ringing tone. | 5824| TONE_TYPE_COMMON_PROPRIETARY_BEEP | 200 | Proprietary tone - beep tone. | 5825| TONE_TYPE_COMMON_PROPRIETARY_ACK | 201 | Proprietary tone - ACK. | 5826| TONE_TYPE_COMMON_PROPRIETARY_PROMPT | 203 | Proprietary tone - PROMPT. | 5827| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP | 204 | Proprietary tone - double beep tone. | 5828 5829## TonePlayer<sup>9+</sup> 5830 5831Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones. 5832 5833**System API**: This is a system API. 5834 5835### load<sup>9+</sup> 5836 5837load(type: ToneType, callback: AsyncCallback<void>): void 5838 5839Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result. 5840 5841**System API**: This is a system API. 5842 5843**System capability**: SystemCapability.Multimedia.Audio.Tone 5844 5845**Parameters** 5846 5847| Name | Type | Mandatory | Description | 5848| :------- | :--------------------- | :-------- | :---------------------------------- | 5849| type | [ToneType](#tonetype9) | Yes | Tone type. | 5850| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5851 5852**Example** 5853 5854```js 5855tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => { 5856 if (err) { 5857 console.error(`callback call load failed error: ${err.message}`); 5858 return; 5859 } else { 5860 console.info('callback call load success'); 5861 } 5862}); 5863``` 5864 5865### load<sup>9+</sup> 5866 5867load(type: ToneType): Promise<void> 5868 5869Loads the DTMF tone configuration. This API uses a promise to return the result. 5870 5871**System API**: This is a system API. 5872 5873**System capability**: SystemCapability.Multimedia.Audio.Tone 5874 5875**Parameters** 5876 5877| Name | Type | Mandatory | Description | 5878| :--- | :--------------------- | :-------- | ----------- | 5879| type | [ToneType](#tonetype9) | Yes | Tone type. | 5880 5881**Return value** 5882 5883| Type | Description | 5884| :------------- | :--------------------------------- | 5885| Promise<void\> | Promise used to return the result. | 5886 5887**Example** 5888 5889```js 5890tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => { 5891 console.info('promise call load '); 5892}).catch(() => { 5893 console.error('promise call load fail'); 5894}); 5895``` 5896 5897### start<sup>9+</sup> 5898 5899start(callback: AsyncCallback<void>): void 5900 5901Starts DTMF tone playing. This API uses an asynchronous callback to return the result. 5902 5903**System API**: This is a system API. 5904 5905**System capability**: SystemCapability.Multimedia.Audio.Tone 5906 5907**Parameters** 5908 5909| Name | Type | Mandatory | Description | 5910| :------- | :------------------- | :-------- | :---------------------------------- | 5911| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5912 5913**Example** 5914 5915```js 5916tonePlayer.start((err) => { 5917 if (err) { 5918 console.error(`callback call start failed error: ${err.message}`); 5919 return; 5920 } else { 5921 console.info('callback call start success'); 5922 } 5923}); 5924``` 5925 5926### start<sup>9+</sup> 5927 5928start(): Promise<void> 5929 5930Starts DTMF tone playing. This API uses a promise to return the result. 5931 5932**System API**: This is a system API. 5933 5934**System capability**: SystemCapability.Multimedia.Audio.Tone 5935 5936**Return value** 5937 5938| Type | Description | 5939| :------------- | :--------------------------------- | 5940| Promise<void\> | Promise used to return the result. | 5941 5942**Example** 5943 5944```js 5945tonePlayer.start().then(() => { 5946 console.info('promise call start'); 5947}).catch(() => { 5948 console.error('promise call start fail'); 5949}); 5950``` 5951 5952### stop<sup>9+</sup> 5953 5954stop(callback: AsyncCallback<void>): void 5955 5956Stops the tone that is being played. This API uses an asynchronous callback to return the result. 5957 5958**System API**: This is a system API. 5959 5960**System capability**: SystemCapability.Multimedia.Audio.Tone 5961 5962**Parameters** 5963 5964| Name | Type | Mandatory | Description | 5965| :------- | :------------------- | :-------- | :---------------------------------- | 5966| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 5967 5968**Example** 5969 5970```js 5971tonePlayer.stop((err) => { 5972 if (err) { 5973 console.error(`callback call stop error: ${err.message}`); 5974 return; 5975 } else { 5976 console.error('callback call stop success '); 5977 } 5978}); 5979``` 5980 5981### stop<sup>9+</sup> 5982 5983stop(): Promise<void> 5984 5985Stops the tone that is being played. This API uses a promise to return the result. 5986 5987**System API**: This is a system API. 5988 5989**System capability**: SystemCapability.Multimedia.Audio.Tone 5990 5991**Return value** 5992 5993| Type | Description | 5994| :------------- | :--------------------------------- | 5995| Promise<void\> | Promise used to return the result. | 5996 5997**Example** 5998 5999```js 6000tonePlayer.stop().then(() => { 6001 console.info('promise call stop finish'); 6002}).catch(() => { 6003 console.error('promise call stop fail'); 6004}); 6005``` 6006 6007### release<sup>9+</sup> 6008 6009release(callback: AsyncCallback<void>): void 6010 6011Releases the resources associated with the **TonePlayer** instance. This API uses an asynchronous callback to return the result. 6012 6013**System API**: This is a system API. 6014 6015**System capability**: SystemCapability.Multimedia.Audio.Tone 6016 6017**Parameters** 6018 6019| Name | Type | Mandatory | Description | 6020| :------- | :------------------- | :-------- | :---------------------------------- | 6021| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | 6022 6023**Example** 6024 6025```js 6026tonePlayer.release((err) => { 6027 if (err) { 6028 console.error(`callback call release failed error: ${err.message}`); 6029 return; 6030 } else { 6031 console.info('callback call release success '); 6032 } 6033}); 6034``` 6035 6036### release<sup>9+</sup> 6037 6038release(): Promise<void> 6039 6040Releases the resources associated with the **TonePlayer** instance. This API uses a promise to return the result. 6041 6042**System API**: This is a system API. 6043 6044**System capability**: SystemCapability.Multimedia.Audio.Tone 6045 6046**Return value** 6047 6048| Type | Description | 6049| :------------- | :--------------------------------- | 6050| Promise<void\> | Promise used to return the result. | 6051 6052**Example** 6053 6054```js 6055tonePlayer.release().then(() => { 6056 console.info('promise call release'); 6057}).catch(() => { 6058 console.error('promise call release fail'); 6059}); 6060``` 6061 6062## ActiveDeviceType<sup>(deprecated)</sup> 6063 6064Enumerates the active device types. 6065 6066> **NOTE** 6067> 6068> This API is deprecated since API version 9. You are advised to use [CommunicationDeviceType](#communicationdevicetype9) instead. 6069 6070**System capability**: SystemCapability.Multimedia.Audio.Device 6071 6072| Name | Value | Description | 6073| ------------- | ----- | ------------------------------------------------------------ | 6074| SPEAKER | 2 | Speaker. | 6075| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | 6076 6077## InterruptActionType<sup>(deprecated)</sup> 6078 6079Enumerates the returned event types for audio interruption events. 6080 6081> **NOTE** 6082> 6083> This API is supported since API version 7 and deprecated since API version 9. 6084 6085**System capability**: SystemCapability.Multimedia.Audio.Renderer 6086 6087| Name | Value | Description | 6088| -------------- | ----- | ------------------------- | 6089| TYPE_ACTIVATED | 0 | Focus gain event. | 6090| TYPE_INTERRUPT | 1 | Audio interruption event. | 6091 6092## AudioInterrupt<sup>(deprecated)</sup> 6093 6094Describes input parameters of audio interruption events. 6095 6096> **NOTE** 6097> 6098> This API is supported since API version 7 and deprecated since API version 9. 6099 6100**System capability**: SystemCapability.Multimedia.Audio.Renderer 6101 6102| Name | Type | Mandatory | Description | 6103| --------------- | --------------------------- | --------- | ------------------------------------------------------------ | 6104| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage. | 6105| contentType | [ContentType](#contenttype) | Yes | Audio content type. | 6106| pauseWhenDucked | boolean | Yes | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite. | 6107 6108## InterruptAction<sup>(deprecated)</sup> 6109 6110Describes the callback invoked for audio interruption or focus gain events. 6111 6112> **NOTE** 6113> 6114> This API is supported since API version 7 and deprecated since API version 9. 6115 6116**System capability**: SystemCapability.Multimedia.Audio.Renderer 6117 6118| Name | Type | Mandatory | Description | 6119| ---------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------ | 6120| actionType | [InterruptActionType](#interruptactiontypedeprecated) | Yes | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event. | 6121| type | [InterruptType](#interrupttype) | No | Type of the audio interruption event. | 6122| hint | [InterruptHint](#interrupthint) | No | Hint provided along with the audio interruption event. | 6123| 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. |