1# Interface (AudioVolumeGroupManager) 2 3> **NOTE** 4> 5> - 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. 6> - The initial APIs of this interface are supported since API version 9. 7 8This interface implements volume management for an audio group. 9 10Before calling any API in AudioVolumeGroupManager, you must use [getVolumeGroupManager](arkts-apis-audio-AudioVolumeManager.md#getvolumegroupmanager9) to obtain an AudioVolumeGroupManager instance. 11 12## Modules to Import 13 14```ts 15import { audio } from '@kit.AudioKit'; 16``` 17 18## getVolume<sup>(deprecated)</sup> 19 20getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 21 22Obtains the volume of a stream. This API uses an asynchronous callback to return the result. 23 24> **NOTE** 25> 26> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumebystream20) instead. 27 28**System capability**: SystemCapability.Multimedia.Audio.Volume 29 30**Parameters** 31 32| Name | Type | Mandatory| Description | 33| ---------- | ----------------------------------- | ---- | ------------------ | 34| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 35| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the stream volume obtained; otherwise, **err** is an error object. The volume range of a specified stream can be obtained by calling [getMinVolume](#getminvolumedeprecated) and [getMaxVolume](#getmaxvolumedeprecated).| 36 37**Example** 38 39```ts 40import { BusinessError } from '@kit.BasicServicesKit'; 41 42audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 43 if (err) { 44 console.error(`Failed to obtain the volume. ${err}`); 45 return; 46 } 47 console.info('Callback invoked to indicate that the volume is obtained.'); 48}); 49``` 50 51## getVolume<sup>(deprecated)</sup> 52 53getVolume(volumeType: AudioVolumeType): Promise<number> 54 55Obtains the volume of a stream. This API uses a promise to return the result. 56 57> **NOTE** 58> 59> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumebystream20) instead. 60 61**System capability**: SystemCapability.Multimedia.Audio.Volume 62 63**Parameters** 64 65| Name | Type | Mandatory| Description | 66| ---------- | ----------------------------------- | ---- | ------------ | 67| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 68 69**Return value** 70 71| Type | Description | 72| --------------------- | ------------------------- | 73| Promise<number> | Promise used to return the volume of the stream. The volume range of a specified stream can be obtained by calling [getMinVolume](#getminvolumedeprecated) and [getMaxVolume](#getmaxvolumedeprecated).| 74 75**Example** 76 77```ts 78audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => { 79 console.info(`Promise returned to indicate that the volume is obtained ${value}.`); 80}); 81``` 82 83## getVolumeSync<sup>(deprecated)</sup> 84 85getVolumeSync(volumeType: AudioVolumeType): number 86 87Obtains the volume of a stream. This API returns the result synchronously. 88 89> **NOTE** 90> 91> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumebystream20) instead. 92 93**System capability**: SystemCapability.Multimedia.Audio.Volume 94 95**Parameters** 96 97| Name | Type | Mandatory| Description | 98| ---------- | ----------------------------------- | ---- | ------------ | 99| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 100 101**Return value** 102 103| Type | Description | 104| --------------------- | ------------------------- | 105| number | Volume of the stream. The volume range of a specified stream can be obtained by calling [getMinVolume](#getminvolumedeprecated) and [getMaxVolume](#getmaxvolumedeprecated).| 106 107**Error codes** 108 109For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 110 111| ID| Error Message| 112| ------- | --------------------------------------------| 113| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 114| 6800101 | Parameter verification failed. | 115 116**Example** 117 118```ts 119import { BusinessError } from '@kit.BasicServicesKit'; 120 121try { 122 let value: number = audioVolumeGroupManager.getVolumeSync(audio.AudioVolumeType.MEDIA); 123 console.info(`Indicate that the volume is obtained ${value}.`); 124} catch (err) { 125 let error = err as BusinessError; 126 console.error(`Failed to obtain the volume, error ${error}.`); 127} 128``` 129 130## getMinVolume<sup>(deprecated)</sup> 131 132getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 133 134Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result. 135 136> **NOTE** 137> 138> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getMinVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getminvolumebystream20) instead. 139 140**System capability**: SystemCapability.Multimedia.Audio.Volume 141 142**Parameters** 143 144| Name | Type | Mandatory| Description | 145| ---------- | ----------------------------------- | ---- | ------------------ | 146| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 147| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the minimum stream volume obtained; otherwise, **err** is an error object.| 148 149**Example** 150 151```ts 152import { BusinessError } from '@kit.BasicServicesKit'; 153 154audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 155 if (err) { 156 console.error(`Failed to obtain the minimum volume. ${err}`); 157 return; 158 } 159 console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`); 160}); 161``` 162 163## getMinVolume<sup>(deprecated)</sup> 164 165getMinVolume(volumeType: AudioVolumeType): Promise<number> 166 167Obtains the minimum volume allowed for a stream. This API uses a promise to return the result. 168 169> **NOTE** 170> 171> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getMinVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getminvolumebystream20) instead. 172 173**System capability**: SystemCapability.Multimedia.Audio.Volume 174 175**Parameters** 176 177| Name | Type | Mandatory| Description | 178| ---------- | ----------------------------------- | ---- | ------------ | 179| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 180 181**Return value** 182 183| Type | Description | 184| --------------------- | ------------------------- | 185| Promise<number> | Promise used to return the minimum volume.| 186 187**Example** 188 189```ts 190audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => { 191 console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`); 192}); 193``` 194 195## getMinVolumeSync<sup>(deprecated)</sup> 196 197getMinVolumeSync(volumeType: AudioVolumeType): number 198 199Obtains the minimum volume allowed for a stream. This API returns the result synchronously. 200 201> **NOTE** 202> 203> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getMinVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getminvolumebystream20) instead. 204 205**System capability**: SystemCapability.Multimedia.Audio.Volume 206 207**Parameters** 208 209| Name | Type | Mandatory| Description | 210| ---------- | ----------------------------------- | ---- | ------------ | 211| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 212 213**Return value** 214 215| Type | Description | 216| --------------------- | ------------------------- | 217| number | Minimum volume.| 218 219**Error codes** 220 221For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 222 223| ID| Error Message| 224| ------- | --------------------------------------------| 225| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 226| 6800101 | Parameter verification failed. | 227 228**Example** 229 230```ts 231import { BusinessError } from '@kit.BasicServicesKit'; 232 233try { 234 let value: number = audioVolumeGroupManager.getMinVolumeSync(audio.AudioVolumeType.MEDIA); 235 console.info(`Indicate that the minimum volume is obtained ${value}.`); 236} catch (err) { 237 let error = err as BusinessError; 238 console.error(`Failed to obtain the minimum volume, error ${error}.`); 239} 240``` 241 242## getMaxVolume<sup>(deprecated)</sup> 243 244getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 245 246Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result. 247 248> **NOTE** 249> 250> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getMaxVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getmaxvolumebystream20) instead. 251 252**System capability**: SystemCapability.Multimedia.Audio.Volume 253 254**Parameters** 255 256| Name | Type | Mandatory| Description | 257| ---------- | ----------------------------------- | ---- | ---------------------- | 258| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 259| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the maximum stream volume obtained; otherwise, **err** is an error object.| 260 261**Example** 262 263```ts 264import { BusinessError } from '@kit.BasicServicesKit'; 265 266audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 267 if (err) { 268 console.error(`Failed to obtain the maximum volume. ${err}`); 269 return; 270 } 271 console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`); 272}); 273``` 274 275## getMaxVolume<sup>(deprecated)</sup> 276 277getMaxVolume(volumeType: AudioVolumeType): Promise<number> 278 279Obtains the maximum volume allowed for a stream. This API uses a promise to return the result. 280 281> **NOTE** 282> 283> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [getMaxVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getmaxvolumebystream20) instead. 284 285**System capability**: SystemCapability.Multimedia.Audio.Volume 286 287**Parameters** 288 289| Name | Type | Mandatory| Description | 290| ---------- | ----------------------------------- | ---- | ------------ | 291| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 292 293**Return value** 294 295| Type | Description | 296| --------------------- | ----------------------------- | 297| Promise<number> | Promise used to return the maximum volume.| 298 299**Example** 300 301```ts 302audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => { 303 console.info('Promised returned to indicate that the maximum volume is obtained.'); 304}); 305``` 306 307## getMaxVolumeSync<sup>(deprecated)</sup> 308 309getMaxVolumeSync(volumeType: AudioVolumeType): number 310 311Obtains the maximum volume allowed for a stream. This API returns the result synchronously. 312 313> **NOTE** 314> 315> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getMaxVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getmaxvolumebystream20) instead. 316 317**System capability**: SystemCapability.Multimedia.Audio.Volume 318 319**Parameters** 320 321| Name | Type | Mandatory| Description | 322| ---------- | ----------------------------------- | ---- | ------------ | 323| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 324 325**Return value** 326 327| Type | Description | 328| --------------------- | ----------------------------- | 329| number | Maximum volume.| 330 331**Error codes** 332 333For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 334 335| ID| Error Message| 336| ------- | --------------------------------------------| 337| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 338| 6800101 | Parameter verification failed. | 339 340**Example** 341 342```ts 343import { BusinessError } from '@kit.BasicServicesKit'; 344 345try { 346 let value: number = audioVolumeGroupManager.getMaxVolumeSync(audio.AudioVolumeType.MEDIA); 347 console.info(`Indicate that the maximum volume is obtained. ${value}`); 348} catch (err) { 349 let error = err as BusinessError; 350 console.error(`Failed to obtain the maximum volume, error ${error}.`); 351} 352``` 353 354## isMute<sup>(deprecated)</sup> 355 356isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 357 358Checks whether a stream is muted. This API uses an asynchronous callback to return the result. 359 360> **NOTE** 361> 362> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [isSystemMutedForStream](arkts-apis-audio-AudioVolumeManager.md#issystemmutedforstream20) instead. 363 364**System capability**: SystemCapability.Multimedia.Audio.Volume 365 366**Parameters** 367 368| Name | Type | Mandatory| Description | 369| ---------- | ----------------------------------- | ---- | ----------------------------------------------- | 370| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 371| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the stream is muted or **false** if not muted; otherwise, **err** is an error object.| 372 373**Example** 374 375```ts 376import { BusinessError } from '@kit.BasicServicesKit'; 377 378audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => { 379 if (err) { 380 console.error(`Failed to obtain the mute status. ${err}`); 381 return; 382 } 383 console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`); 384}); 385``` 386 387## isMute<sup>(deprecated)</sup> 388 389isMute(volumeType: AudioVolumeType): Promise<boolean> 390 391Checks whether a stream is muted. This API uses a promise to return the result. 392 393> **NOTE** 394> 395> This API is supported since API version 9 and deprecated since API version 20. You are advised to use [isSystemMutedForStream](arkts-apis-audio-AudioVolumeManager.md#issystemmutedforstream20) instead. 396 397**System capability**: SystemCapability.Multimedia.Audio.Volume 398 399**Parameters** 400 401| Name | Type | Mandatory| Description | 402| ---------- | ----------------------------------- | ---- | ------------ | 403| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 404 405**Return value** 406 407| Type | Description | 408| ---------------------- | ------------------------------------------------------ | 409| Promise<boolean> | Promise used to return the result. The value **true** means that the stream is muted, and **false** means the opposite.| 410 411**Example** 412 413```ts 414audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => { 415 console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`); 416}); 417``` 418 419## isMuteSync<sup>(deprecated)</sup> 420 421isMuteSync(volumeType: AudioVolumeType): boolean 422 423Checks whether a stream is muted. This API returns the result synchronously. 424 425> **NOTE** 426> 427> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [isSystemMutedForStream](arkts-apis-audio-AudioVolumeManager.md#issystemmutedforstream20) instead. 428 429**System capability**: SystemCapability.Multimedia.Audio.Volume 430 431**Parameters** 432 433| Name | Type | Mandatory| Description | 434| ---------- | ----------------------------------- | ---- | ------------ | 435| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 436 437**Return value** 438 439| Type | Description | 440| ---------------------- | ------------------------------------------------------ | 441| boolean | Check result. The value **true** means that the stream is muted, and **false** means the opposite.| 442 443**Error codes** 444 445For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 446 447| ID| Error Message| 448| ------- | --------------------------------------------| 449| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 450| 6800101 | Parameter verification failed. | 451 452**Example** 453 454```ts 455import { BusinessError } from '@kit.BasicServicesKit'; 456 457try { 458 let value: boolean = audioVolumeGroupManager.isMuteSync(audio.AudioVolumeType.MEDIA); 459 console.info(`Indicate that the mute status of the stream is obtained ${value}.`); 460} catch (err) { 461 let error = err as BusinessError; 462 console.error(`Failed to obtain the mute status of the stream, error ${error}.`); 463} 464``` 465 466## getRingerMode<sup>9+</sup> 467 468getRingerMode(callback: AsyncCallback<AudioRingMode>): void 469 470Obtains the ringer mode. This API uses an asynchronous callback to return the result. 471 472**System capability**: SystemCapability.Multimedia.Audio.Volume 473 474**Parameters** 475 476| Name | Type | Mandatory| Description | 477| -------- | ---------------------------------------------------- | ---- | ------------------------ | 478| callback | AsyncCallback<[AudioRingMode](arkts-apis-audio-e.md#audioringmode)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the ringer mode obtained; otherwise, **err** is an error object.| 479 480**Example** 481 482```ts 483import { BusinessError } from '@kit.BasicServicesKit'; 484 485audioVolumeGroupManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => { 486 if (err) { 487 console.error(`Failed to obtain the ringer mode. ${err}`); 488 return; 489 } 490 console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`); 491}); 492``` 493 494## getRingerMode<sup>9+</sup> 495 496getRingerMode(): Promise<AudioRingMode> 497 498Obtains the ringer mode. This API uses a promise to return the result. 499 500**System capability**: SystemCapability.Multimedia.Audio.Volume 501 502**Return value** 503 504| Type | Description | 505| ---------------------------------------------- | ------------------------------- | 506| Promise<[AudioRingMode](arkts-apis-audio-e.md#audioringmode)> | Promise used to return the ringer mode.| 507 508**Example** 509 510```ts 511audioVolumeGroupManager.getRingerMode().then((value: audio.AudioRingMode) => { 512 console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`); 513}); 514``` 515 516## getRingerModeSync<sup>10+</sup> 517 518getRingerModeSync(): AudioRingMode 519 520Obtains the ringer mode. This API returns the result synchronously. 521 522**System capability**: SystemCapability.Multimedia.Audio.Volume 523 524**Return value** 525 526| Type | Description | 527| ---------------------------------------------- | ------------------------------- | 528| [AudioRingMode](arkts-apis-audio-e.md#audioringmode) | Ringer mode.| 529 530**Example** 531 532```ts 533import { BusinessError } from '@kit.BasicServicesKit'; 534 535try { 536 let value: audio.AudioRingMode = audioVolumeGroupManager.getRingerModeSync(); 537 console.info(`Indicate that the ringer mode is obtained ${value}.`); 538} catch (err) { 539 let error = err as BusinessError; 540 console.error(`Failed to obtain the ringer mode, error ${error}.`); 541} 542``` 543 544## on('ringerModeChange')<sup>9+</sup> 545 546on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void 547 548Subscribes to the ringer mode change event, which is triggered when [audioringmode](arkts-apis-audio-e.md#audioringmode) is changed. This API uses an asynchronous callback to return the result. 549 550**System capability**: SystemCapability.Multimedia.Audio.Volume 551 552**Parameters** 553 554| Name | Type | Mandatory| Description | 555| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | 556| type | string | Yes | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.| 557| callback | Callback<[AudioRingMode](arkts-apis-audio-e.md#audioringmode)> | Yes | Callback used to return the changed ringer mode.| 558 559**Error codes** 560 561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 562 563| ID| Error Message| 564| ------- | --------------------------------------------| 565| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 566| 6800101 | Parameter verification failed. | 567 568**Example** 569 570```ts 571audioVolumeGroupManager.on('ringerModeChange', (ringerMode: audio.AudioRingMode) => { 572 console.info(`Updated ringermode: ${ringerMode}`); 573}); 574``` 575 576## off('ringerModeChange')<sup>18+</sup> 577 578off(type: 'ringerModeChange', callback?: Callback<AudioRingMode>): void 579 580Subscribes to the ringer mode change event. This API uses an asynchronous callback to return the result. 581 582**System capability**: SystemCapability.Multimedia.Audio.Volume 583 584**Parameters** 585 586| Name | Type | Mandatory| Description | 587| -------- | -------------------------------------- |----| ------------------------------------------------------------ | 588| type | string | Yes | Event type. The event **'ringerModeChange'** is triggered when the ringer mode is changed.| 589| callback |Callback<[AudioRingMode](arkts-apis-audio-e.md#audioringmode)> | No | Callback used to return the changed ringer mode.| 590 591**Error codes** 592 593For details about the error codes, see [Audio Error Codes](errorcode-audio.md). 594 595| ID| Error Message| 596| ------- | --------------------------------------------| 597| 6800101 | Parameter verification failed. | 598 599**Example** 600 601```ts 602// Cancel all subscriptions to the event. 603audioVolumeGroupManager.off('ringerModeChange'); 604 605// For the same event, if the callback parameter passed to the off API is the same as that passed to the on API, the off API cancels the subscription registered with the specified callback parameter. 606let ringerModeChangeCallback = (ringerMode: audio.AudioRingMode) => { 607 console.info(`Updated ringermode: ${ringerMode}`); 608}; 609 610audioVolumeGroupManager.on('ringerModeChange', ringerModeChangeCallback); 611 612audioVolumeGroupManager.off('ringerModeChange', ringerModeChangeCallback); 613``` 614 615## isMicrophoneMute<sup>9+</sup> 616 617isMicrophoneMute(callback: AsyncCallback<boolean>): void 618 619Checks whether the microphone is muted. This API uses an asynchronous callback to return the result. 620 621**System capability**: SystemCapability.Multimedia.Audio.Volume 622 623**Parameters** 624 625| Name | Type | Mandatory| Description | 626| -------- | ---------------------------- | ---- | ------------------------------------------------------- | 627| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the microphone is muted or **false** if not muted; otherwise, **err** is an error object.| 628 629**Example** 630 631```ts 632import { BusinessError } from '@kit.BasicServicesKit'; 633 634audioVolumeGroupManager.isMicrophoneMute((err: BusinessError, value: boolean) => { 635 if (err) { 636 console.error(`Failed to obtain the mute status of the microphone. ${err}`); 637 return; 638 } 639 console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`); 640}); 641``` 642 643## isMicrophoneMute<sup>9+</sup> 644 645isMicrophoneMute(): Promise<boolean> 646 647Checks whether the microphone is muted. This API uses a promise to return the result. 648 649**System capability**: SystemCapability.Multimedia.Audio.Volume 650 651**Return value** 652 653| Type | Description | 654| ---------------------- | ------------------------------------------------------------ | 655| Promise<boolean> | Promise used to return the result. The value **true** means that the microphone is muted, and **false** means the opposite.| 656 657**Example** 658 659```ts 660audioVolumeGroupManager.isMicrophoneMute().then((value: boolean) => { 661 console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`); 662}); 663``` 664 665## isMicrophoneMuteSync<sup>10+</sup> 666 667isMicrophoneMuteSync(): boolean 668 669Checks whether the microphone is muted. This API returns the result synchronously. 670 671**System capability**: SystemCapability.Multimedia.Audio.Volume 672 673**Return value** 674 675| Type | Description | 676| ---------------------- | ------------------------------------------------------------ | 677| boolean | Check result. The value **true** means that the microphone is muted, and **false** means the opposite.| 678 679**Example** 680 681```ts 682import { BusinessError } from '@kit.BasicServicesKit'; 683 684try { 685 let value: boolean = audioVolumeGroupManager.isMicrophoneMuteSync(); 686 console.info(`Indicate that the mute status of the microphone is obtained ${value}.`); 687} catch (err) { 688 let error = err as BusinessError; 689 console.error(`Failed to obtain the mute status of the microphone, error ${error}.`); 690} 691``` 692 693## on('micStateChange')<sup>9+</sup> 694 695on(type: 'micStateChange', callback: Callback<MicStateChangeEvent>): void 696 697Subscribes to the microphone state change event, which is triggered when the microphone state is changed. This API uses an asynchronous callback to return the result. 698 699Currently, 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. 700 701**System capability**: SystemCapability.Multimedia.Audio.Volume 702 703**Parameters** 704 705| Name | Type | Mandatory| Description | 706| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 707| type | string | Yes | Event type. The event **'micStateChange'** is triggered when the microphone state is changed.| 708| callback | Callback<[MicStateChangeEvent](arkts-apis-audio-i.md#micstatechangeevent9)> | Yes | Callback used to return the changed microphone state.| 709 710**Error codes** 711 712For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 713 714| ID| Error Message| 715| ------- | --------------------------------------------| 716| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 717| 6800101 | Parameter verification failed. | 718 719**Example** 720 721```ts 722audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChangeEvent) => { 723 console.info(`Current microphone status is: ${micStateChange.mute} `); 724}); 725``` 726 727## off('micStateChange')<sup>12+</sup> 728 729off(type: 'micStateChange', callback?: Callback<MicStateChangeEvent>): void 730 731Unsubscribes from the microphone state change event. This API uses an asynchronous callback to return the result. 732 733**System capability**: SystemCapability.Multimedia.Audio.Volume 734 735**Parameters** 736 737| Name | Type | Mandatory| Description | 738| -------- | -------------------------------------- |----| ------------------------------------------------------------ | 739| type | string | Yes | Event type. The event **'micStateChange'** is triggered when the microphone state is changed.| 740| callback | Callback<[MicStateChangeEvent](arkts-apis-audio-i.md#micstatechangeevent9)> | No | Callback used to return the changed microphone state.| 741 742**Error codes** 743 744For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 745 746| ID| Error Message| 747| ------- | --------------------------------------------| 748| 401 | Parameter error. Possible causes: 1.Mandatory parameters missing; 2.Incorrect parameter types. | 749| 6800101 | Parameter verification failed. | 750 751**Example** 752 753```ts 754// Cancel all subscriptions to the event. 755audioVolumeGroupManager.off('micStateChange'); 756 757// For the same event, if the callback parameter passed to the off API is the same as that passed to the on API, the off API cancels the subscription registered with the specified callback parameter. 758let micStateChangeCallback = (micStateChange: audio.MicStateChangeEvent) => { 759 console.info(`Current microphone status is: ${micStateChange.mute} `); 760}; 761 762audioVolumeGroupManager.on('micStateChange', micStateChangeCallback); 763 764audioVolumeGroupManager.off('micStateChange', micStateChangeCallback); 765``` 766 767## isVolumeUnadjustable<sup>10+</sup> 768 769isVolumeUnadjustable(): boolean 770 771Checks whether the fixed volume mode is enabled. When the fixed volume mode is enabled, the volume cannot be adjusted. This API returns the result synchronously. 772 773**System capability**: SystemCapability.Multimedia.Audio.Volume 774 775**Return value** 776 777| Type | Description | 778| ---------------------- | ------------------------------------------------------ | 779| boolean | Check result. The value **true** means that the fixed volume mode is enabled, and **false** means the opposite.| 780 781**Example** 782 783```ts 784let volumeAdjustSwitch: boolean = audioVolumeGroupManager.isVolumeUnadjustable(); 785console.info(`Whether it is volume unadjustable: ${volumeAdjustSwitch}.`); 786``` 787 788## getSystemVolumeInDb<sup>(deprecated)</sup> 789 790getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType, callback: AsyncCallback<number>): void 791 792Obtains the volume gain. This API uses an asynchronous callback to return the result. 793 794> **NOTE** 795> 796> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getVolumeInUnitOfDbByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumeinunitofdbbystream20) instead. 797 798**System capability**: SystemCapability.Multimedia.Audio.Volume 799 800**Parameters** 801 802| Name | Type | Mandatory| Description | 803| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 804| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 805| volumeLevel | number | Yes | Volume level. | 806| device | [DeviceType](arkts-apis-audio-e.md#devicetype) | Yes | Device type. | 807| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the volume gain obtained; otherwise, **err** is an error object.| 808 809**Error codes** 810 811For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 812 813| ID| Error Message| 814| ------- | --------------------------------------------| 815| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 816| 6800101 | Parameter verification failed. Return by callback. | 817| 6800301 | System error. Return by callback. | 818 819**Example** 820 821```ts 822import { BusinessError } from '@kit.BasicServicesKit'; 823 824audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER, (err: BusinessError, dB: number) => { 825 if (err) { 826 console.error(`Failed to get the volume DB. ${err}`); 827 } else { 828 console.info(`Success to get the volume DB. ${dB}`); 829 } 830}); 831``` 832 833## getSystemVolumeInDb<sup>(deprecated)</sup> 834 835getSystemVolumeInDb(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): Promise<number> 836 837Obtains the volume gain. This API uses a promise to return the result. 838 839> **NOTE** 840> 841> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getVolumeInUnitOfDbByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumeinunitofdbbystream20) instead. 842 843**System capability**: SystemCapability.Multimedia.Audio.Volume 844 845**Parameters** 846 847| Name | Type | Mandatory| Description | 848| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 849| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 850| volumeLevel | number | Yes | Volume level. | 851| device | [DeviceType](arkts-apis-audio-e.md#devicetype) | Yes | Device type. | 852 853**Return value** 854 855| Type | Description | 856| --------------------- | ---------------------------------- | 857| Promise<number> | Promise used to return the volume gain (in dB).| 858 859**Error codes** 860 861For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 862 863| ID| Error Message| 864| ------- | --------------------------------------------| 865| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 866| 6800101 | Parameter verification failed. Return by promise. | 867| 6800301 | System error. Return by promise. | 868 869**Example** 870 871```ts 872import { BusinessError } from '@kit.BasicServicesKit'; 873 874audioVolumeGroupManager.getSystemVolumeInDb(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER).then((value: number) => { 875 console.info(`Success to get the volume DB. ${value}`); 876}).catch((error: BusinessError) => { 877 console.error(`Fail to adjust the system volume by step. ${error}`); 878}); 879``` 880 881## getSystemVolumeInDbSync<sup>(deprecated)</sup> 882 883getSystemVolumeInDbSync(volumeType: AudioVolumeType, volumeLevel: number, device: DeviceType): number 884 885Obtains the volume gain. This API returns the result synchronously. 886 887> **NOTE** 888> 889> This API is supported since API version 10 and deprecated since API version 20. You are advised to use [getVolumeInUnitOfDbByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumeinunitofdbbystream20) instead. 890 891**System capability**: SystemCapability.Multimedia.Audio.Volume 892 893**Parameters** 894 895| Name | Type | Mandatory| Description | 896| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 897| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 898| volumeLevel | number | Yes | Volume level. | 899| device | [DeviceType](arkts-apis-audio-e.md#devicetype) | Yes | Device type. | 900 901**Return value** 902 903| Type | Description | 904| --------------------- | ---------------------------------- | 905| number | Volume gain (in dB).| 906 907**Error codes** 908 909For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 910 911| ID| Error Message| 912| ------- | --------------------------------------------| 913| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 914| 6800101 | Parameter verification failed. | 915 916**Example** 917 918```ts 919import { BusinessError } from '@kit.BasicServicesKit'; 920 921try { 922 let value: number = audioVolumeGroupManager.getSystemVolumeInDbSync(audio.AudioVolumeType.MEDIA, 3, audio.DeviceType.SPEAKER); 923 console.info(`Success to get the volume DB. ${value}`); 924} catch (err) { 925 let error = err as BusinessError; 926 console.error(`Fail to adjust the system volume by step. ${error}`); 927} 928``` 929 930## getMaxAmplitudeForInputDevice<sup>12+</sup> 931 932getMaxAmplitudeForInputDevice(inputDevice: AudioDeviceDescriptor): Promise<number> 933 934Obtains the maximum amplitude (in the range [0, 1]) of the audio stream for an input device. This API uses a promise to return the result. 935 936**System capability**: SystemCapability.Multimedia.Audio.Volume 937 938**Parameters** 939 940| Name | Type | Mandatory| Description | 941| ----------- | ------------------------------------- | ---- | --------------------------------------------------- | 942| inputDevice |[AudioDeviceDescriptor](arkts-apis-audio-i.md#audiodevicedescriptor) | Yes | Descriptor of the target device. | 943 944**Return value** 945 946| Type | Description | 947| --------------------- | ---------------------------------- | 948| Promise<number> | Promise used to return the maximum amplitude, which is in the range [0, 1].| 949 950**Error codes** 951 952For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 953 954| ID| Error Message| 955| ------- | --------------------------------------------| 956| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 957| 6800101 | Parameter verification failed. Return by promise. | 958| 6800301 | System error. Return by promise. | 959 960**Example** 961 962```ts 963import { BusinessError } from '@kit.BasicServicesKit'; 964 965let capturerInfo: audio.AudioCapturerInfo = { 966 source: audio.SourceType.SOURCE_TYPE_MIC, // Audio source type: microphone. Set this parameter based on the service scenario. 967 capturerFlags: 0 // AudioCapturer flag. 968}; 969 970audio.getAudioManager().getRoutingManager().getPreferredInputDeviceForCapturerInfo(capturerInfo).then((data) => { 971 audioVolumeGroupManager.getMaxAmplitudeForInputDevice(data[0]).then((value) => { 972 console.info(`mic volatileume amplitude is: ${value}`); 973 }).catch((err: BusinessError) => { 974 console.error("getMaxAmplitudeForInputDevice error" + JSON.stringify(err)); 975 }) 976}).catch((err: BusinessError) => { 977 console.error("get outputDeviceId error" + JSON.stringify(err)); 978}) 979``` 980 981## getMaxAmplitudeForOutputDevice<sup>12+</sup> 982 983getMaxAmplitudeForOutputDevice(outputDevice: AudioDeviceDescriptor): Promise<number> 984 985Obtains the maximum amplitude (in the range [0, 1]) of the audio stream for an output device. This API uses a promise to return the result. 986 987**System capability**: SystemCapability.Multimedia.Audio.Volume 988 989**Parameters** 990 991| Name | Type | Mandatory| Description | 992| ------------ | --------------------------------------- | ---- | -------------------------------------------------------- | 993| outputDevice |[AudioDeviceDescriptor](arkts-apis-audio-i.md#audiodevicedescriptor) | Yes | Descriptor of the target device. | 994 995**Return value** 996 997| Type | Description | 998| --------------------- | ---------------------------------- | 999| Promise<number> | Promise used to return the maximum amplitude, which is in the range [0, 1].| 1000 1001**Error codes** 1002 1003For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Audio Error Codes](errorcode-audio.md). 1004 1005| ID| Error Message| 1006| ------- | --------------------------------------------| 1007| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 1008| 6800101 | Parameter verification failed. Return by promise. | 1009| 6800301 | System error. Return by promise. | 1010 1011**Example** 1012 1013```ts 1014import { BusinessError } from '@kit.BasicServicesKit'; 1015 1016let rendererInfo: audio.AudioRendererInfo = { 1017 usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // Audio stream usage type: music. Set this parameter based on the service scenario. 1018 rendererFlags: 0 // AudioRenderer flag. 1019}; 1020 1021audio.getAudioManager().getRoutingManager().getPreferOutputDeviceForRendererInfo(rendererInfo).then((data) => { 1022 audioVolumeGroupManager.getMaxAmplitudeForOutputDevice(data[0]).then((value) => { 1023 console.info(`mic volatileume amplitude is: ${value}`); 1024 }).catch((err: BusinessError) => { 1025 console.error("getMaxAmplitudeForOutputDevice error" + JSON.stringify(err)); 1026 }) 1027}).catch((err: BusinessError) => { 1028 console.error("getPreferOutputDeviceForRendererInfo error" + JSON.stringify(err)); 1029}) 1030``` 1031## setMicrophoneMute<sup>(deprecated)</sup> 1032 1033setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void 1034 1035Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. 1036 1037> **NOTE** 1038> 1039> This API is supported since API version 9 and deprecated since API version 11. Its substitute is available only to system applications. 1040 1041**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG (available only for system applications) 1042 1043**System capability**: SystemCapability.Multimedia.Audio.Volume 1044 1045**Parameters** 1046 1047| Name | Type | Mandatory| Description | 1048| -------- | ------------------------- | ---- | --------------------------------------------- | 1049| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 1050| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1051 1052**Example** 1053 1054```ts 1055import { BusinessError } from '@kit.BasicServicesKit'; 1056 1057audioVolumeGroupManager.setMicrophoneMute(true, (err: BusinessError) => { 1058 if (err) { 1059 console.error(`Failed to mute the microphone. ${err}`); 1060 return; 1061 } 1062 console.info('Callback invoked to indicate that the microphone is muted.'); 1063}); 1064``` 1065 1066## setMicrophoneMute<sup>(deprecated)</sup> 1067 1068setMicrophoneMute(mute: boolean): Promise<void> 1069 1070Mutes or unmutes the microphone. This API uses a promise to return the result. 1071 1072> **NOTE** 1073> 1074> This API is supported since API version 9 and deprecated since API version 11. Its substitute is available only to system applications. 1075 1076**Required permissions**: ohos.permission.MANAGE_AUDIO_CONFIG (available only for system applications) 1077 1078**System capability**: SystemCapability.Multimedia.Audio.Volume 1079 1080**Parameters** 1081 1082| Name| Type | Mandatory| Description | 1083| ------ | ------- | ---- | --------------------------------------------- | 1084| mute | boolean | Yes | Mute status to set. The value **true** means to the microphone, and **false** means the opposite.| 1085 1086**Return value** 1087 1088| Type | Description | 1089| ------------------- | ------------------------------- | 1090| Promise<void> | Promise that returns no value.| 1091 1092**Example** 1093 1094```ts 1095audioVolumeGroupManager.setMicrophoneMute(true).then(() => { 1096 console.info('Promise returned to indicate that the microphone is muted.'); 1097}); 1098``` 1099