1# Interface (AudioManager) 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 7This interface implements audio volume and device management. 8 9Before calling any API in AudioManager, you must use [getAudioManager](arkts-apis-audio-f.md#audiogetaudiomanager) to obtain an AudioManager instance. 10 11## Modules to Import 12 13```ts 14import { audio } from '@kit.AudioKit'; 15``` 16 17## getAudioScene<sup>8+</sup> 18 19getAudioScene\(callback: AsyncCallback<AudioScene\>\): void 20 21Obtains the audio scene. This API uses an asynchronous callback to return the result. 22 23**System capability**: SystemCapability.Multimedia.Audio.Communication 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28| :------- | :-------------------------------------------------- | :--- | :--------------------------- | 29| callback | AsyncCallback<[AudioScene](arkts-apis-audio-e.md#audioscene8)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio scene obtained; otherwise, **err** is an error object.| 30 31**Example** 32 33```ts 34import { BusinessError } from '@kit.BasicServicesKit'; 35 36audioManager.getAudioScene((err: BusinessError, value: audio.AudioScene) => { 37 if (err) { 38 console.error(`Failed to obtain the audio scene mode. ${err}`); 39 return; 40 } 41 console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`); 42}); 43``` 44 45## getAudioScene<sup>8+</sup> 46 47getAudioScene\(\): Promise<AudioScene\> 48 49Obtains the audio scene. This API uses a promise to return the result. 50 51**System capability**: SystemCapability.Multimedia.Audio.Communication 52 53**Return value** 54 55| Type | Description | 56| :-------------------------------------------- | :--------------------------- | 57| Promise<[AudioScene](arkts-apis-audio-e.md#audioscene8)> | Promise used to return the audio scene.| 58 59**Example** 60 61```ts 62import { BusinessError } from '@kit.BasicServicesKit'; 63 64audioManager.getAudioScene().then((value: audio.AudioScene) => { 65 console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`); 66}).catch ((err: BusinessError) => { 67 console.error(`Failed to obtain the audio scene mode ${err}`); 68}); 69``` 70 71## getAudioSceneSync<sup>10+</sup> 72 73getAudioSceneSync\(\): AudioScene 74 75Obtains the audio scene. This API returns the result synchronously. 76 77**System capability**: SystemCapability.Multimedia.Audio.Communication 78 79**Return value** 80 81| Type | Description | 82| :-------------------------------------------- | :--------------------------- | 83| [AudioScene](arkts-apis-audio-e.md#audioscene8) | Audio scene.| 84 85**Example** 86 87```ts 88import { BusinessError } from '@kit.BasicServicesKit'; 89 90try { 91 let value: audio.AudioScene = audioManager.getAudioSceneSync(); 92 console.info(`indicate that the audio scene mode is obtained ${value}.`); 93} catch (err) { 94 let error = err as BusinessError; 95 console.error(`Failed to obtain the audio scene mode ${error}`); 96} 97``` 98 99## on('audioSceneChange')<sup>20+</sup> 100 101on(type: 'audioSceneChange', callback: Callback\<AudioScene\>): void 102 103Subscribes to the audio scene change event. This API uses an asynchronous callback to return the result. 104 105**System capability**: SystemCapability.Multimedia.Audio.Communication 106 107**Parameters** 108 109| Name | Type | Mandatory| Description | 110| :------- | :------------------------- | :--- | :------------------------------------------ | 111| type | string | Yes | Event type. The event **'audioSceneChange'** is triggered when the audio scene is changed.| 112| callback | Callback\<[AudioScene](arkts-apis-audio-e.md#audioscene8)> | Yes | Callback used to return the current audio scene.| 113 114**Example** 115 116```ts 117audioManager.on('audioSceneChange', (audioScene: audio.AudioScene) => { 118 console.info(`audio scene : ${audioScene}.`); 119}); 120``` 121 122## off('audioSceneChange')<sup>20+</sup> 123 124off(type: 'audioSceneChange', callback?: Callback\<AudioScene\>): void 125 126Unsubscribes from the audio scene change event. This API uses an asynchronous callback to return the result. 127 128**System capability**: SystemCapability.Multimedia.Audio.Communication 129 130**Parameters** 131 132| Name | Type | Mandatory| Description | 133| :------- | :------------------------- | :--- | :------------------------------------------ | 134| type | string | Yes | Event type. The event **'audioSceneChange'** is triggered when the audio scene is changed.| 135| callback | Callback\<[AudioScene](arkts-apis-audio-e.md#audioscene8)> | No| Callback used to return the current audio scene.| 136 137**Example** 138 139```ts 140// Cancel all subscriptions to the event. 141audioManager.off('audioSceneChange'); 142 143// 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. 144let audioSceneChangeCallback = (audioScene: audio.AudioScene) => { 145 console.info(`audio scene : ${audioScene}.`); 146}; 147 148audioManager.on('audioSceneChange', audioSceneChangeCallback); 149 150audioManager.off('audioSceneChange', audioSceneChangeCallback); 151``` 152 153## getVolumeManager<sup>9+</sup> 154 155getVolumeManager(): AudioVolumeManager 156 157Obtains an AudioVolumeManager instance. 158 159**System capability**: SystemCapability.Multimedia.Audio.Volume 160 161**Return value** 162 163| Type | Description | 164|-----------------------------------------| ----------------------------- | 165| [AudioVolumeManager](arkts-apis-audio-AudioVolumeManager.md) | AudioVolumeManager instance.| 166 167**Example** 168 169```ts 170import { audio } from '@kit.AudioKit'; 171 172let audioVolumeManager: audio.AudioVolumeManager = audioManager.getVolumeManager(); 173``` 174 175## getStreamManager<sup>9+</sup> 176 177getStreamManager(): AudioStreamManager 178 179Obtains an AudioStreamManager instance. 180 181**System capability**: SystemCapability.Multimedia.Audio.Core 182 183**Return value** 184 185| Type | Description | 186|--------------------------------------------| ----------------------------- | 187| [AudioStreamManager](arkts-apis-audio-AudioStreamManager.md) | AudioStreamManager instance.| 188 189**Example** 190 191```ts 192import { audio } from '@kit.AudioKit'; 193 194let audioStreamManager: audio.AudioStreamManager = audioManager.getStreamManager(); 195``` 196 197## getRoutingManager<sup>9+</sup> 198 199getRoutingManager(): AudioRoutingManager 200 201Obtains an AudioRoutingManager instance. 202 203**System capability**: SystemCapability.Multimedia.Audio.Device 204 205**Return value** 206 207| Type | Description | 208|------------------------------------------| ----------------------------- | 209| [AudioRoutingManager](arkts-apis-audio-AudioRoutingManager.md) | AudioRoutingManager instance.| 210 211**Example** 212 213```ts 214import { audio } from '@kit.AudioKit'; 215 216let audioRoutingManager: audio.AudioRoutingManager = audioManager.getRoutingManager(); 217``` 218 219## getSessionManager<sup>12+</sup> 220 221getSessionManager(): AudioSessionManager 222 223Obtains an AudioSessionManager instance. 224 225**System capability**: SystemCapability.Multimedia.Audio.Core 226 227**Return value** 228 229| Type | Description | 230|----------------------------------------------| ----------------------------- | 231| [AudioSessionManager](arkts-apis-audio-AudioSessionManager.md) | AudioSessionManager instance.| 232 233**Example** 234 235```ts 236import { audio } from '@kit.AudioKit'; 237 238let audioSessionManager: audio.AudioSessionManager = audioManager.getSessionManager(); 239``` 240 241## getSpatializationManager<sup>18+</sup> 242 243getSpatializationManager(): AudioSpatializationManager 244 245Obtains an AudioSpatializationManager instance. 246 247**System capability**: SystemCapability.Multimedia.Audio.Spatialization 248 249**Return value** 250 251| Type | Description | 252|------------------------------------------| ----------------------------- | 253| [AudioSpatializationManager](arkts-apis-audio-AudioSpatializationManager.md) | AudioSpatializationManager instance.| 254 255**Example** 256 257```ts 258import { audio } from '@kit.AudioKit'; 259let audioSpatializationManager: audio.AudioSpatializationManager = audioManager.getSpatializationManager(); 260``` 261 262## setAudioParameter<sup>(deprecated)</sup> 263 264setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void 265 266Sets an audio parameter. This API uses an asynchronous callback to return the result. 267 268This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and are not common parameters. Sample parameters are used in the sample code below. 269 270> **NOTE** 271> 272> This API is supported since API version 7 and deprecated since API version 11. Its substitute is available only to system applications. 273 274**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS 275 276**System capability**: SystemCapability.Multimedia.Audio.Core 277 278**Parameters** 279 280| Name | Type | Mandatory| Description | 281| -------- | ------------------------- | ---- | ------------------------ | 282| key | string | Yes | Key of the audio parameter to set. | 283| value | string | Yes | Value of the audio parameter to set. | 284| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 285 286**Example** 287 288```ts 289import { BusinessError } from '@kit.BasicServicesKit'; 290 291audioManager.setAudioParameter('key_example', 'value_example', (err: BusinessError) => { 292 if (err) { 293 console.error(`Failed to set the audio parameter. ${err}`); 294 return; 295 } 296 console.info('Callback invoked to indicate a successful setting of the audio parameter.'); 297}); 298``` 299 300## setAudioParameter<sup>(deprecated)</sup> 301 302setAudioParameter(key: string, value: string): Promise<void> 303 304Sets an audio parameter. This API uses a promise to return the result. 305 306This API is used to extend the audio configuration based on the hardware capability. The supported audio parameters vary according to the device and are not common parameters. Sample parameters are used in the sample code below. 307 308> **NOTE** 309> 310> This API is supported since API version 7 and deprecated since API version 11. Its substitute is available only to system applications. 311 312**Required permissions**: ohos.permission.MODIFY_AUDIO_SETTINGS 313 314**System capability**: SystemCapability.Multimedia.Audio.Core 315 316**Parameters** 317 318| Name| Type | Mandatory| Description | 319| ------ | ------ | ---- | ---------------------- | 320| key | string | Yes | Key of the audio parameter to set.| 321| value | string | Yes | Value of the audio parameter to set.| 322 323**Return value** 324 325| Type | Description | 326| ------------------- | ------------------------------- | 327| Promise<void> | Promise that returns no value.| 328 329**Example** 330 331```ts 332audioManager.setAudioParameter('key_example', 'value_example').then(() => { 333 console.info('Promise returned to indicate a successful setting of the audio parameter.'); 334}); 335``` 336 337## getAudioParameter<sup>(deprecated)</sup> 338 339getAudioParameter(key: string, callback: AsyncCallback<string>): void 340 341Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result. 342 343This 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. 344 345> **NOTE** 346> 347> This API is supported since API version 7 and deprecated since API version 11. Its substitute is available only to system applications. 348 349**System capability**: SystemCapability.Multimedia.Audio.Core 350 351**Parameters** 352 353| Name | Type | Mandatory| Description | 354| -------- | --------------------------- | ---- | ---------------------------- | 355| key | string | Yes | Key of the audio parameter whose value is to be obtained. | 356| callback | AsyncCallback<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio parameter value obtained; otherwise, **err** is an error object.| 357 358**Example** 359 360```ts 361import { BusinessError } from '@kit.BasicServicesKit'; 362 363audioManager.getAudioParameter('key_example', (err: BusinessError, value: string) => { 364 if (err) { 365 console.error(`Failed to obtain the value of the audio parameter. ${err}`); 366 return; 367 } 368 console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`); 369}); 370``` 371 372## getAudioParameter<sup>(deprecated)</sup> 373 374getAudioParameter(key: string): Promise<string> 375 376Obtains the value of an audio parameter. This API uses a promise to return the result. 377 378This 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. 379 380> **NOTE** 381> 382> This API is supported since API version 7 and deprecated since API version 11. Its substitute is available only to system applications. 383 384**System capability**: SystemCapability.Multimedia.Audio.Core 385 386**Parameters** 387 388| Name| Type | Mandatory| Description | 389| ------ | ------ | ---- | ---------------------- | 390| key | string | Yes | Key of the audio parameter whose value is to be obtained.| 391 392**Return value** 393 394| Type | Description | 395| --------------------- | ----------------------------------- | 396| Promise<string> | Promise used to return the value of the audio parameter.| 397 398**Example** 399 400```ts 401audioManager.getAudioParameter('key_example').then((value: string) => { 402 console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`); 403}); 404``` 405 406## setVolume<sup>(deprecated)</sup> 407 408setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void 409 410Sets the volume for a stream. This API uses an asynchronous callback to return the result. 411 412> **NOTE** 413> 414> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 415> 416> Applications cannot directly adjust the system volume. They can use the system volume panel to control the volume. For details about the samples and introduction, see [AVVolumePanel Reference](ohos-multimedia-avvolumepanel.md). 417 418**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 419 420This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 421 422**System capability**: SystemCapability.Multimedia.Audio.Volume 423 424**Parameters** 425 426| Name | Type | Mandatory| Description | 427| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 428| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 429| volume | number | Yes | Volume to set. The value range can be obtained by calling [getMinVolume](#getminvolumedeprecated) and [getMaxVolume](#getmaxvolumedeprecated).| 430| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 431 432**Example** 433 434```ts 435import { BusinessError } from '@kit.BasicServicesKit'; 436 437audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err: BusinessError) => { 438 if (err) { 439 console.error(`Failed to set the volume. ${err}`); 440 return; 441 } 442 console.info('Callback invoked to indicate a successful volume setting.'); 443}); 444``` 445 446## setVolume<sup>(deprecated)</sup> 447 448setVolume(volumeType: AudioVolumeType, volume: number): Promise<void> 449 450Sets the volume for a stream. This API uses a promise to return the result. 451 452> **NOTE** 453> 454> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 455> 456> Applications cannot directly adjust the system volume. They can use the system volume panel to control the volume. For details about the samples and introduction, see [AVVolumePanel Reference](ohos-multimedia-avvolumepanel.md). 457 458**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 459 460This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. 461 462**System capability**: SystemCapability.Multimedia.Audio.Volume 463 464**Parameters** 465 466| Name | Type | Mandatory| Description | 467| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | 468| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 469| volume | number | Yes | Volume to set. The value range can be obtained by calling [getMinVolume](#getminvolumedeprecated) and [getMaxVolume](#getmaxvolumedeprecated).| 470 471**Return value** 472 473| Type | Description | 474| ------------------- | ----------------------------- | 475| Promise<void> | Promise that returns no value.| 476 477**Example** 478 479```ts 480audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { 481 console.info('Promise returned to indicate a successful volume setting.'); 482}); 483``` 484 485## getVolume<sup>(deprecated)</sup> 486 487getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 488 489Obtains the volume of a stream. This API uses an asynchronous callback to return the result. 490 491> **NOTE** 492> 493> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getvolumedeprecated) instead. For API version 20 and later, you are advised to use [getVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumebystream20) instead. 494 495**System capability**: SystemCapability.Multimedia.Audio.Volume 496 497**Parameters** 498 499| Name | Type | Mandatory| Description | 500| ---------- | ----------------------------------- | ---- | ------------------ | 501| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 502| 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).| 503 504**Example** 505 506```ts 507import { BusinessError } from '@kit.BasicServicesKit'; 508 509audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 510 if (err) { 511 console.error(`Failed to obtain the volume. ${err}`); 512 return; 513 } 514 console.info('Callback invoked to indicate that the volume is obtained.'); 515}); 516``` 517 518## getVolume<sup>(deprecated)</sup> 519 520getVolume(volumeType: AudioVolumeType): Promise<number> 521 522Obtains the volume of a stream. This API uses a promise to return the result. 523 524> **NOTE** 525> 526> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getvolumedeprecated) instead. For API version 20 and later, you are advised to use [getVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getvolumebystream20) instead. 527 528**System capability**: SystemCapability.Multimedia.Audio.Volume 529 530**Parameters** 531 532| Name | Type | Mandatory| Description | 533| ---------- | ----------------------------------- | ---- | ------------ | 534| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 535 536**Return value** 537 538| Type | Description | 539| --------------------- | ------------------------- | 540| 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).| 541 542**Example** 543 544```ts 545audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value: number) => { 546 console.info(`Promise returned to indicate that the volume is obtained ${value} .`); 547}); 548``` 549 550## getMinVolume<sup>(deprecated)</sup> 551 552getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 553 554Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result. 555 556> **NOTE** 557> 558> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getMinVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getminvolumedeprecated) instead. For API version 20 and later, you are advised to use [getMinVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getminvolumebystream20) instead. 559 560**System capability**: SystemCapability.Multimedia.Audio.Volume 561 562**Parameters** 563 564| Name | Type | Mandatory| Description | 565| ---------- | ----------------------------------- | ---- | ------------------ | 566| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 567| 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.| 568 569**Example** 570 571```ts 572import { BusinessError } from '@kit.BasicServicesKit'; 573 574audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 575 if (err) { 576 console.error(`Failed to obtain the minimum volume. ${err}`); 577 return; 578 } 579 console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`); 580}); 581``` 582 583## getMinVolume<sup>(deprecated)</sup> 584 585getMinVolume(volumeType: AudioVolumeType): Promise<number> 586 587Obtains the minimum volume allowed for a stream. This API uses a promise to return the result. 588 589> **NOTE** 590> 591> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getMinVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getminvolumedeprecated) instead. For API version 20 and later, you are advised to use [getMinVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getminvolumebystream20) instead. 592 593**System capability**: SystemCapability.Multimedia.Audio.Volume 594 595**Parameters** 596 597| Name | Type | Mandatory| Description | 598| ---------- | ----------------------------------- | ---- | ------------ | 599| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 600 601**Return value** 602 603| Type | Description | 604| --------------------- | ------------------------- | 605| Promise<number> | Promise used to return the minimum volume.| 606 607**Example** 608 609```ts 610audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value: number) => { 611 console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`); 612}); 613``` 614 615## getMaxVolume<sup>(deprecated)</sup> 616 617getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void 618 619Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result. 620 621> **NOTE** 622> 623> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getMaxVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getmaxvolumedeprecated) instead. For API version 20 and later, you are advised to use [getMaxVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getmaxvolumebystream20) instead. 624 625**System capability**: SystemCapability.Multimedia.Audio.Volume 626 627**Parameters** 628 629| Name | Type | Mandatory| Description | 630| ---------- | ----------------------------------- | ---- | ---------------------- | 631| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 632| 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.| 633 634**Example** 635 636```ts 637import { BusinessError } from '@kit.BasicServicesKit'; 638 639audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: number) => { 640 if (err) { 641 console.error(`Failed to obtain the maximum volume. ${err}`); 642 return; 643 } 644 console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`); 645}); 646``` 647 648## getMaxVolume<sup>(deprecated)</sup> 649 650getMaxVolume(volumeType: AudioVolumeType): Promise<number> 651 652Obtains the maximum volume allowed for a stream. This API uses a promise to return the result. 653 654> **NOTE** 655> 656> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [getMaxVolume](arkts-apis-audio-AudioVolumeGroupManager.md#getmaxvolumedeprecated) instead. For API version 20 and later, you are advised to use [getMaxVolumeByStream](arkts-apis-audio-AudioVolumeManager.md#getmaxvolumebystream20) instead. 657 658**System capability**: SystemCapability.Multimedia.Audio.Volume 659 660**Parameters** 661 662| Name | Type | Mandatory| Description | 663| ---------- | ----------------------------------- | ---- | ------------ | 664| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 665 666**Return value** 667 668| Type | Description | 669| --------------------- | ----------------------------- | 670| Promise<number> | Promise used to return the maximum volume.| 671 672**Example** 673 674```ts 675audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data: number) => { 676 console.info('Promised returned to indicate that the maximum volume is obtained.'); 677}); 678``` 679 680## mute<sup>(deprecated)</sup> 681 682mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void 683 684Mutes or unmutes a stream. This API uses an asynchronous callback to return the result. 685 686When the minimum volume of a stream cannot be set to 0, muting the stream is not supported. Example scenarios: alarms or phone calls. 687 688> **NOTE** 689> 690> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 691 692**System capability**: SystemCapability.Multimedia.Audio.Volume 693 694**Parameters** 695 696| Name | Type | Mandatory| Description | 697| ---------- | ----------------------------------- | ---- | ------------------------------------- | 698| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 699| mute | boolean | Yes | Whether to mute the stream. The value **true** means to mute the stream, and **false** means the opposite.| 700| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 701 702**Example** 703 704```ts 705import { BusinessError } from '@kit.BasicServicesKit'; 706 707audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err: BusinessError) => { 708 if (err) { 709 console.error(`Failed to mute the stream. ${err}`); 710 return; 711 } 712 console.info('Callback invoked to indicate that the stream is muted.'); 713}); 714``` 715 716## mute<sup>(deprecated)</sup> 717 718mute(volumeType: AudioVolumeType, mute: boolean): Promise<void> 719 720Mutes or unmutes a stream. This API uses a promise to return the result. 721 722When the minimum volume of a stream cannot be set to 0, muting the stream is not supported. Example scenarios: alarms or phone calls. 723 724> **NOTE** 725> 726> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 727 728**System capability**: SystemCapability.Multimedia.Audio.Volume 729 730**Parameters** 731 732| Name | Type | Mandatory| Description | 733| ---------- | ----------------------------------- | ---- | ------------------------------------- | 734| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 735| mute | boolean | Yes | Whether to mute the stream. The value **true** means to mute the stream, and **false** means the opposite.| 736 737**Return value** 738 739| Type | Description | 740| ------------------- | ----------------------------- | 741| Promise<void> | Promise that returns no value.| 742 743**Example** 744 745 746```ts 747audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { 748 console.info('Promise returned to indicate that the stream is muted.'); 749}); 750``` 751 752## isMute<sup>(deprecated)</sup> 753 754isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 755 756Checks whether a stream is muted. This API uses an asynchronous callback to return the result. 757 758> **NOTE** 759> 760> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [isMute](arkts-apis-audio-AudioVolumeGroupManager.md#ismutedeprecated) instead. For API version 20 and later, you are advised to use [isSystemMutedForStream](arkts-apis-audio-AudioVolumeManager.md#issystemmutedforstream20) instead. 761 762**System capability**: SystemCapability.Multimedia.Audio.Volume 763 764**Parameters** 765 766| Name | Type | Mandatory| Description | 767| ---------- | ----------------------------------- | ---- | ----------------------------------------------- | 768| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 769| 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.| 770 771**Example** 772 773```ts 774import { BusinessError } from '@kit.BasicServicesKit'; 775 776audioManager.isMute(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => { 777 if (err) { 778 console.error(`Failed to obtain the mute status. ${err}`); 779 return; 780 } 781 console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`); 782}); 783``` 784 785## isMute<sup>(deprecated)</sup> 786 787isMute(volumeType: AudioVolumeType): Promise<boolean> 788 789Checks whether a stream is muted. This API uses a promise to return the result. 790 791> **NOTE** 792> 793> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [isMute](arkts-apis-audio-AudioVolumeGroupManager.md#ismutedeprecated) instead. For API version 20 and later, you are advised to use [isSystemMutedForStream](arkts-apis-audio-AudioVolumeManager.md#issystemmutedforstream20) instead. 794 795**System capability**: SystemCapability.Multimedia.Audio.Volume 796 797**Parameters** 798 799| Name | Type | Mandatory| Description | 800| ---------- | ----------------------------------- | ---- | ------------ | 801| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 802 803**Return value** 804 805| Type | Description | 806| ---------------------- | ------------------------------------------------------ | 807| Promise<boolean> | Promise used to return the result. The value **true** means that the stream is muted, and **false** means the opposite.| 808 809**Example** 810 811```ts 812audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value: boolean) => { 813 console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`); 814}); 815``` 816 817## isActive<sup>(deprecated)</sup> 818 819isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void 820 821Checks whether a stream is active. This API uses an asynchronous callback to return the result. 822 823> **NOTE** 824> 825> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [isActive](arkts-apis-audio-AudioStreamManager.md#isactivedeprecated) instead. For API version 20 and later, you are advised to use [isStreamActive](arkts-apis-audio-AudioStreamManager.md#isstreamactive20) instead. 826 827**System capability**: SystemCapability.Multimedia.Audio.Volume 828 829**Parameters** 830 831| Name | Type | Mandatory| Description | 832| ---------- | ----------------------------------- | ---- | ------------------------------------------------- | 833| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type. | 834| 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 active or **false** if not active; otherwise, **err** is an error object.| 835 836**Example** 837 838```ts 839import { BusinessError } from '@kit.BasicServicesKit'; 840 841audioManager.isActive(audio.AudioVolumeType.MEDIA, (err: BusinessError, value: boolean) => { 842 if (err) { 843 console.error(`Failed to obtain the active status of the stream. ${err}`); 844 return; 845 } 846 console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`); 847}); 848``` 849 850## isActive<sup>(deprecated)</sup> 851 852isActive(volumeType: AudioVolumeType): Promise<boolean> 853 854Checks whether a stream is active. This API uses a promise to return the result. 855 856> **NOTE** 857> 858> This API is supported since API version 7 and deprecated since API version 9. From API version 9 to 19, you are advised to use [isActive](arkts-apis-audio-AudioStreamManager.md#isactivedeprecated) instead. For API version 20 and later, you are advised to use [isStreamActive](arkts-apis-audio-AudioStreamManager.md#isstreamactive20) instead. 859 860**System capability**: SystemCapability.Multimedia.Audio.Volume 861 862**Parameters** 863 864| Name | Type | Mandatory| Description | 865| ---------- | ----------------------------------- | ---- | ------------ | 866| volumeType | [AudioVolumeType](arkts-apis-audio-e.md#audiovolumetype) | Yes | Audio stream type.| 867 868**Return value** 869 870| Type | Description | 871| ---------------------- | -------------------------------------------------------- | 872| Promise<boolean> | Promise used to return the result. The value **true** means that the stream is active, and **false** means the opposite.| 873 874**Example** 875 876```ts 877audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value: boolean) => { 878 console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`); 879}); 880``` 881 882## setRingerMode<sup>(deprecated)</sup> 883 884setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void 885 886Sets the ringer mode. This API uses an asynchronous callback to return the result. 887 888> **NOTE** 889> 890> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 891 892**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 893 894This permission is required only for muting or unmuting the ringer. 895 896**System capability**: SystemCapability.Multimedia.Audio.Communication 897 898**Parameters** 899 900| Name | Type | Mandatory| Description | 901| -------- | ------------------------------- | ---- | ------------------------ | 902| mode | [AudioRingMode](arkts-apis-audio-e.md#audioringmode) | Yes | Ringer mode. | 903| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 904 905**Example** 906 907```ts 908import { BusinessError } from '@kit.BasicServicesKit'; 909 910audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err: BusinessError) => { 911 if (err) { 912 console.error(`Failed to set the ringer mode. ${err}`); 913 return; 914 } 915 console.info('Callback invoked to indicate a successful setting of the ringer mode.'); 916}); 917``` 918 919## setRingerMode<sup>(deprecated)</sup> 920 921setRingerMode(mode: AudioRingMode): Promise<void> 922 923Sets the ringer mode. This API uses a promise to return the result. 924 925> **NOTE** 926> 927> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 928 929 930**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY 931 932This permission is required only for muting or unmuting the ringer. 933 934**System capability**: SystemCapability.Multimedia.Audio.Communication 935 936**Parameters** 937 938| Name| Type | Mandatory| Description | 939| ------ | ------------------------------- | ---- | -------------- | 940| mode | [AudioRingMode](arkts-apis-audio-e.md#audioringmode) | Yes | Ringer mode.| 941 942**Return value** 943 944| Type | Description | 945| ------------------- | ------------------------------- | 946| Promise<void> | Promise that returns no value.| 947 948**Example** 949 950```ts 951audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { 952 console.info('Promise returned to indicate a successful setting of the ringer mode.'); 953}); 954``` 955 956## getRingerMode<sup>(deprecated)</sup> 957 958getRingerMode(callback: AsyncCallback<AudioRingMode>): void 959 960Obtains the ringer mode. This API uses an asynchronous callback to return the result. 961 962> **NOTE** 963> 964> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](arkts-apis-audio-AudioVolumeGroupManager.md#getringermode9) instead. 965 966**System capability**: SystemCapability.Multimedia.Audio.Communication 967 968**Parameters** 969 970| Name | Type | Mandatory| Description | 971| -------- | ---------------------------------------------------- | ---- | ------------------------ | 972| 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.| 973 974**Example** 975 976```ts 977import { BusinessError } from '@kit.BasicServicesKit'; 978 979audioManager.getRingerMode((err: BusinessError, value: audio.AudioRingMode) => { 980 if (err) { 981 console.error(`Failed to obtain the ringer mode. ${err}`); 982 return; 983 } 984 console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`); 985}); 986``` 987 988## getRingerMode<sup>(deprecated)</sup> 989 990getRingerMode(): Promise<AudioRingMode> 991 992Obtains the ringer mode. This API uses a promise to return the result. 993 994> **NOTE** 995> 996> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRingerMode](arkts-apis-audio-AudioVolumeGroupManager.md#getringermode9) instead. 997 998**System capability**: SystemCapability.Multimedia.Audio.Communication 999 1000**Return value** 1001 1002| Type | Description | 1003| ---------------------------------------------- | ------------------------------- | 1004| Promise<[AudioRingMode](arkts-apis-audio-e.md#audioringmode)> | Promise used to return the ringer mode.| 1005 1006**Example** 1007 1008```ts 1009audioManager.getRingerMode().then((value: audio.AudioRingMode) => { 1010 console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`); 1011}); 1012``` 1013 1014## getDevices<sup>(deprecated)</sup> 1015 1016getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void 1017 1018Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result. 1019 1020> **NOTE** 1021> 1022> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](arkts-apis-audio-AudioRoutingManager.md#getdevices9) instead. 1023 1024**System capability**: SystemCapability.Multimedia.Audio.Device 1025 1026**Parameters** 1027 1028| Name | Type | Mandatory| Description | 1029| ---------- | ------------------------------------------------------------ | ---- | -------------------- | 1030| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag) | Yes | Audio device flag. | 1031| callback | AsyncCallback<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the audio devices obtained; otherwise, **err** is an error object.| 1032 1033**Example** 1034```ts 1035import { BusinessError } from '@kit.BasicServicesKit'; 1036 1037audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err: BusinessError, value: audio.AudioDeviceDescriptors) => { 1038 if (err) { 1039 console.error(`Failed to obtain the device list. ${err}`); 1040 return; 1041 } 1042 console.info('Callback invoked to indicate that the device list is obtained.'); 1043}); 1044``` 1045 1046## getDevices<sup>(deprecated)</sup> 1047 1048getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors> 1049 1050Obtains the audio devices with a specific flag. This API uses a promise to return the result. 1051 1052> **NOTE** 1053> 1054> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getDevices](arkts-apis-audio-AudioRoutingManager.md#getdevices9) instead. 1055 1056**System capability**: SystemCapability.Multimedia.Audio.Device 1057 1058**Parameters** 1059 1060| Name | Type | Mandatory| Description | 1061| ---------- | ------------------------- | ---- | ---------------- | 1062| deviceFlag | [DeviceFlag](arkts-apis-audio-e.md#deviceflag) | Yes | Audio device flag.| 1063 1064**Return value** 1065 1066| Type | Description | 1067| ------------------------------------------------------------ | ------------------------- | 1068| Promise<[AudioDeviceDescriptors](arkts-apis-audio-t.md#audiodevicedescriptors)> | Promise used to return the device list.| 1069 1070**Example** 1071 1072```ts 1073audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data: audio.AudioDeviceDescriptors) => { 1074 console.info('Promise returned to indicate that the device list is obtained.'); 1075}); 1076``` 1077 1078## setDeviceActive<sup>(deprecated)</sup> 1079 1080setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void 1081 1082Sets a device to the active state. This API uses an asynchronous callback to return the result. 1083 1084> **NOTE** 1085> 1086> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](arkts-apis-audio-AudioRoutingManager.md#setcommunicationdevice9) instead. 1087 1088**System capability**: SystemCapability.Multimedia.Audio.Device 1089 1090**Parameters** 1091 1092| Name | Type | Mandatory| Description | 1093| ---------- | ------------------------------------- | ---- |-------------| 1094| deviceType | [ActiveDeviceType](arkts-apis-audio-e.md#activedevicetypedeprecated) | Yes | Active audio device type. | 1095| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.| 1096| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1097 1098**Example** 1099 1100```ts 1101import { BusinessError } from '@kit.BasicServicesKit'; 1102 1103audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err: BusinessError) => { 1104 if (err) { 1105 console.error(`Failed to set the active status of the device. ${err}`); 1106 return; 1107 } 1108 console.info('Callback invoked to indicate that the device is set to the active status.'); 1109}); 1110``` 1111 1112## setDeviceActive<sup>(deprecated)</sup> 1113 1114setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void> 1115 1116Sets a device to the active state. This API uses a promise to return the result. 1117 1118> **NOTE** 1119> 1120> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCommunicationDevice](arkts-apis-audio-AudioRoutingManager.md#setcommunicationdevice9) instead. 1121 1122**System capability**: SystemCapability.Multimedia.Audio.Device 1123 1124**Parameters** 1125 1126| Name | Type | Mandatory| Description | 1127| ---------- | ------------------------------------- | ---- | ------------------ | 1128| deviceType | [ActiveDeviceType](arkts-apis-audio-e.md#activedevicetypedeprecated) | Yes | Active audio device type.| 1129| active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite.| 1130 1131**Return value** 1132 1133| Type | Description | 1134| ------------------- | ------------------------------- | 1135| Promise<void> | Promise that returns no value.| 1136 1137**Example** 1138 1139 1140```ts 1141audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => { 1142 console.info('Promise returned to indicate that the device is set to the active status.'); 1143}); 1144``` 1145 1146## isDeviceActive<sup>(deprecated)</sup> 1147 1148isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): void 1149 1150Checks whether a device is active. This API uses an asynchronous callback to return the result. 1151 1152> **NOTE** 1153> 1154> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](arkts-apis-audio-AudioRoutingManager.md#iscommunicationdeviceactive9) instead. 1155 1156**System capability**: SystemCapability.Multimedia.Audio.Device 1157 1158**Parameters** 1159 1160| Name | Type | Mandatory| Description | 1161| ---------- | ------------------------------------- | ---- | ------------------------ | 1162| deviceType | [ActiveDeviceType](arkts-apis-audio-e.md#activedevicetypedeprecated) | Yes | Active audio device type. | 1163| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true** if the device is active or **false** if not active; otherwise, **err** is an error object.| 1164 1165**Example** 1166 1167```ts 1168import { BusinessError } from '@kit.BasicServicesKit'; 1169 1170audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err: BusinessError, value: boolean) => { 1171 if (err) { 1172 console.error(`Failed to obtain the active status of the device. ${err}`); 1173 return; 1174 } 1175 console.info('Callback invoked to indicate that the active status of the device is obtained.'); 1176}); 1177``` 1178 1179## isDeviceActive<sup>(deprecated)</sup> 1180 1181isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean> 1182 1183Checks whether a device is active. This API uses a promise to return the result. 1184 1185> **NOTE** 1186> 1187> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isCommunicationDeviceActive](arkts-apis-audio-AudioRoutingManager.md#iscommunicationdeviceactive9) instead. 1188 1189**System capability**: SystemCapability.Multimedia.Audio.Device 1190 1191**Parameters** 1192 1193| Name | Type | Mandatory| Description | 1194| ---------- | ------------------------------------- | ---- | ------------------ | 1195| deviceType | [ActiveDeviceType](arkts-apis-audio-e.md#activedevicetypedeprecated) | Yes | Active audio device type.| 1196 1197**Return value** 1198 1199| Type | Description | 1200| ---------------------- |---------------------------------------| 1201| Promise<boolean> | Promise used to return the result. The value **true** means that the device is active, and **false** means the opposite.| 1202 1203**Example** 1204 1205```ts 1206audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value: boolean) => { 1207 console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`); 1208}); 1209``` 1210 1211## setMicrophoneMute<sup>(deprecated)</sup> 1212 1213setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void 1214 1215Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. 1216 1217> **NOTE** 1218> 1219> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 1220 1221**Required permissions**: ohos.permission.MICROPHONE 1222 1223**System capability**: SystemCapability.Multimedia.Audio.Device 1224 1225**Parameters** 1226 1227| Name | Type | Mandatory| Description | 1228| -------- | ------------------------- | ---- | --------------------------------------------- | 1229| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 1230| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1231 1232**Example** 1233 1234```ts 1235import { BusinessError } from '@kit.BasicServicesKit'; 1236 1237audioManager.setMicrophoneMute(true, (err: BusinessError) => { 1238 if (err) { 1239 console.error(`Failed to mute the microphone. ${err}`); 1240 return; 1241 } 1242 console.info('Callback invoked to indicate that the microphone is muted.'); 1243}); 1244``` 1245 1246## setMicrophoneMute<sup>(deprecated)</sup> 1247 1248setMicrophoneMute(mute: boolean): Promise<void> 1249 1250Mutes or unmutes the microphone. This API uses a promise to return the result. 1251 1252> **NOTE** 1253> 1254> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 1255 1256**Required permissions**: ohos.permission.MICROPHONE 1257 1258**System capability**: SystemCapability.Multimedia.Audio.Device 1259 1260**Parameters** 1261 1262| Name| Type | Mandatory| Description | 1263| ------ | ------- | ---- | --------------------------------------------- | 1264| mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.| 1265 1266**Return value** 1267 1268| Type | Description | 1269| ------------------- | ------------------------------- | 1270| Promise<void> | Promise that returns no value.| 1271 1272**Example** 1273 1274```ts 1275audioManager.setMicrophoneMute(true).then(() => { 1276 console.info('Promise returned to indicate that the microphone is muted.'); 1277}); 1278``` 1279 1280## isMicrophoneMute<sup>(deprecated)</sup> 1281 1282isMicrophoneMute(callback: AsyncCallback<boolean>): void 1283 1284Checks whether the microphone is muted. This API uses an asynchronous callback to return the result. 1285 1286> **NOTE** 1287> 1288> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](arkts-apis-audio-AudioVolumeGroupManager.md#ismicrophonemute9) instead. 1289 1290**Required permissions**: ohos.permission.MICROPHONE 1291 1292**System capability**: SystemCapability.Multimedia.Audio.Device 1293 1294**Parameters** 1295 1296| Name | Type | Mandatory| Description | 1297| -------- | ---------------------------- | ---- | ------------------------------------------------------- | 1298| 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.| 1299 1300**Example** 1301 1302```ts 1303import { BusinessError } from '@kit.BasicServicesKit'; 1304 1305audioManager.isMicrophoneMute((err: BusinessError, value: boolean) => { 1306 if (err) { 1307 console.error(`Failed to obtain the mute status of the microphone. ${err}`); 1308 return; 1309 } 1310 console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`); 1311}); 1312``` 1313 1314## isMicrophoneMute<sup>(deprecated)</sup> 1315 1316isMicrophoneMute(): Promise<boolean> 1317 1318Checks whether the microphone is muted. This API uses a promise to return the result. 1319 1320> **NOTE** 1321> 1322> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [isMicrophoneMute](arkts-apis-audio-AudioVolumeGroupManager.md#ismicrophonemute9) instead. 1323 1324**Required permissions**: ohos.permission.MICROPHONE 1325 1326**System capability**: SystemCapability.Multimedia.Audio.Device 1327 1328**Return value** 1329 1330| Type | Description | 1331| ---------------------- | ------------------------------------------------------------ | 1332| Promise<boolean> | Promise used to return the result. The value **true** means that the microphone is muted, and **false** means the opposite.| 1333 1334**Example** 1335 1336```ts 1337audioManager.isMicrophoneMute().then((value: boolean) => { 1338 console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`); 1339}); 1340``` 1341 1342## on('deviceChange')<sup>(deprecated)</sup> 1343 1344on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void 1345 1346Subscribes to the event indicating that the connection status of an audio device is changed. This API uses an asynchronous callback to return the result. 1347 1348> **NOTE** 1349> 1350> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('deviceChange')](arkts-apis-audio-AudioRoutingManager.md#ondevicechange9) instead. 1351 1352**System capability**: SystemCapability.Multimedia.Audio.Device 1353 1354**Parameters** 1355 1356| Name | Type | Mandatory| Description | 1357| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- | 1358| type | string | Yes | Event type. The event **'deviceChange'** is triggered when the connection status of an audio device is changed.| 1359| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)\> | Yes | Callback used to return the device change details.| 1360 1361**Example** 1362 1363```ts 1364audioManager.on('deviceChange', (deviceChanged: audio.DeviceChangeAction) => { 1365 console.info(`device change type : ${deviceChanged.type} `); 1366 console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `); 1367 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `); 1368 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `); 1369}); 1370``` 1371 1372## off('deviceChange')<sup>(deprecated)</sup> 1373 1374off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void 1375 1376Unsubscribes from the audio device change event. This API uses an asynchronous callback to return the result. 1377 1378> **NOTE** 1379> 1380> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('deviceChange')](arkts-apis-audio-AudioRoutingManager.md#offdevicechange9) instead. 1381 1382**System capability**: SystemCapability.Multimedia.Audio.Device 1383 1384**Parameters** 1385 1386| Name | Type | Mandatory| Description | 1387| -------- | --------------------------------------------------- | ---- | ------------------------------------------ | 1388| type | string | Yes | Event type. The event **'deviceChange'** is triggered when the connection status of an audio device is changed.| 1389| callback | Callback<[DeviceChangeAction](arkts-apis-audio-i.md#devicechangeaction)> | No | Callback used to return the device change details.| 1390 1391**Example** 1392 1393```ts 1394// Cancel all subscriptions to the event. 1395audioManager.off('deviceChange'); 1396 1397// 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. 1398let deviceChangeCallback = (deviceChanged: audio.DeviceChangeAction) => { 1399 console.info(`device change type : ${deviceChanged.type} `); 1400 console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `); 1401 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `); 1402 console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `); 1403}; 1404 1405audioManager.on('deviceChange', deviceChangeCallback); 1406 1407audioManager.off('deviceChange', deviceChangeCallback); 1408``` 1409 1410## on('interrupt')<sup>(deprecated)</sup> 1411 1412on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void 1413 1414Subscribes to the audio interruption event, which is triggered when the audio focus is changed. This API uses an asynchronous callback to return the result. 1415 1416Same as [on('audioInterrupt')](arkts-apis-audio-AudioRenderer.md#onaudiointerrupt9), this API is used to listen for focus is changed. However, this API is used in scenarios without audio streams (no AudioRenderer instance is created), such as frequency modulation (FM) and voice wakeup. 1417 1418> **NOTE** 1419> 1420> This API is supported since API version 7 and deprecated since API version 11. You are advised to use [on('audioInterrupt')](arkts-apis-audio-AudioCapturer.md#onaudiointerrupt10) instead. 1421 1422**System capability**: SystemCapability.Multimedia.Audio.Renderer 1423 1424**Parameters** 1425 1426| Name | Type | Mandatory| Description | 1427| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ | 1428| type | string | Yes | Event type. The event **'interrupt'** is triggered when the audio focus is changed.| 1429| interrupt | [AudioInterrupt](arkts-apis-audio-i.md#audiointerruptdeprecated) | Yes | Audio interruption event type. | 1430| callback | Callback<[InterruptAction](arkts-apis-audio-i.md#interruptactiondeprecated)> | Yes | Callback used to return the event information.| 1431 1432**Example** 1433 1434```ts 1435import { audio } from '@kit.AudioKit'; 1436 1437let interAudioInterrupt: audio.AudioInterrupt = { 1438 streamUsage:2, 1439 contentType:0, 1440 pauseWhenDucked:true 1441}; 1442 1443audioManager.on('interrupt', interAudioInterrupt, (interruptAction: audio.InterruptAction) => { 1444 if (interruptAction.actionType === 0) { 1445 console.info('An event to gain the audio focus starts.'); 1446 console.info(`Focus gain event: ${interruptAction} `); 1447 } 1448 if (interruptAction.actionType === 1) { 1449 console.info('An audio interruption event starts.'); 1450 console.info(`Audio interruption event: ${interruptAction} `); 1451 } 1452}); 1453``` 1454 1455## off('interrupt')<sup>(deprecated)</sup> 1456 1457off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void 1458 1459Unsubscribes from the audio interruption event. This API uses an asynchronous callback to return the result. 1460 1461> **NOTE** 1462> 1463> This API is supported since API version 7 and deprecated since API version 11. You are advised to use [off('audioInterrupt')](arkts-apis-audio-AudioCapturer.md#offaudiointerrupt10) instead. 1464 1465**System capability**: SystemCapability.Multimedia.Audio.Renderer 1466 1467**Parameters** 1468 1469| Name | Type | Mandatory| Description | 1470| --------- |---------------------------------------------------------| ---- | ------------------------------------------------------------ | 1471| type | string | Yes | Event type. The event **'interrupt'** is triggered when the audio focus is changed.| 1472| interrupt | [AudioInterrupt](arkts-apis-audio-i.md#audiointerruptdeprecated) | Yes | Audio interruption event type. | 1473| callback | Callback<[InterruptAction](arkts-apis-audio-i.md#interruptactiondeprecated)> | No | Callback used to return the event information.| 1474 1475**Example** 1476 1477```ts 1478import { audio } from '@kit.AudioKit'; 1479 1480let interAudioInterrupt: audio.AudioInterrupt = { 1481 streamUsage:2, 1482 contentType:0, 1483 pauseWhenDucked:true 1484}; 1485 1486// Cancel all subscriptions to the event. 1487audioManager.off('interrupt', interAudioInterrupt); 1488 1489// 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. 1490let interruptCallback = (interruptAction: audio.InterruptAction) => { 1491 if (interruptAction.actionType === 0) { 1492 console.info('An event to gain the audio focus starts.'); 1493 console.info(`Focus gain event: ${interruptAction} `); 1494 } 1495 if (interruptAction.actionType === 1) { 1496 console.info('An audio interruption event starts.'); 1497 console.info(`Audio interruption event: ${interruptAction} `); 1498 } 1499}; 1500 1501audioManager.on('interrupt', interAudioInterrupt, interruptCallback); 1502 1503audioManager.off('interrupt', interAudioInterrupt, interruptCallback); 1504``` 1505