• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AudioSpatializationManager)
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 18.
7
8This interface implements spatial audio management.
9
10Before calling any API in AudioSpatializationManager, you must use [getSpatializationManager](arkts-apis-audio-AudioManager.md#getspatializationmanager18) to obtain an AudioSpatializationManager instance.
11
12## Modules to Import
13
14```ts
15import { audio } from '@kit.AudioKit';
16```
17
18## isSpatializationEnabledForCurrentDevice<sup>18+</sup>
19
20isSpatializationEnabledForCurrentDevice(): boolean
21
22Checks whether spatial audio rendering is enabled for the current device. This API returns the result synchronously.
23
24**System capability**: SystemCapability.Multimedia.Audio.Spatialization
25
26**Return value**
27
28| Type                  | Description                                                        |
29| ---------------------- | ------------------------------------------------------------ |
30| boolean | Check result. The value **true** means that spatial audio rendering is enabled, and **false** means the opposite.|
31
32**Example**
33
34```ts
35import { audio } from '@kit.AudioKit';
36
37let isSpatializationEnabledForCurrentDevice: boolean = audioSpatializationManager.isSpatializationEnabledForCurrentDevice();
38console.info(`AudioSpatializationManager isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
39```
40
41## on('spatializationEnabledChangeForCurrentDevice')<sup>18+</sup>
42
43on(type: 'spatializationEnabledChangeForCurrentDevice', callback: Callback<boolean\>): void
44
45Subscribes to the spatial audio rendering status change event of the current device. This API uses an asynchronous callback to return the result.
46
47**System capability**: SystemCapability.Multimedia.Audio.Spatialization
48
49**Parameters**
50
51| Name  | Type                                                | Mandatory| Description                                          |
52| :------- | :--------------------------------------------------- | :--- |:---------------------------------------------|
53| type     | string | Yes  | Event type. The event **'spatializationEnabledChangeForCurrentDevice'** is triggered when the spatial audio rendering status is changed.|
54| callback | Callback<boolean\> | Yes  | Callback used to return the result. The value **true** means that spatial audio rendering is enabled, and **false** means the opposite.  |
55
56**Error codes**
57
58For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
59
60| ID| Error Message|
61| ------- | --------------------------------------------|
62| 6800101 | Parameter verification failed. |
63
64**Example**
65
66```ts
67import { audio } from '@kit.AudioKit';
68
69audioSpatializationManager.on('spatializationEnabledChangeForCurrentDevice', (isSpatializationEnabledForCurrentDevice: boolean) => {
70  console.info(`isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
71});
72```
73
74## off('spatializationEnabledChangeForCurrentDevice')<sup>18+</sup>
75
76off(type: 'spatializationEnabledChangeForCurrentDevice', callback?: Callback<boolean\>): void
77
78Unsubscribes from the spatial audio rendering status change event of the current device. This API uses an asynchronous callback to return the result.
79
80**System capability**: SystemCapability.Multimedia.Audio.Spatialization
81
82**Parameters**
83
84| Name  | Type                                               | Mandatory| Description                                      |
85| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
86| type     | string | Yes  | Event type. The event **'spatializationEnabledChangeForCurrentDevice'** is triggered when the spatial audio rendering status is changed.|
87| callback | Callback<boolean\> | No  | Callback used to return the result. The value **true** means that spatial audio rendering is enabled, and **false** means the opposite.  |
88
89**Error codes**
90
91For details about the error codes, see [Audio Error Codes](errorcode-audio.md).
92
93| ID| Error Message|
94| ------- | --------------------------------------------|
95| 6800101 | Parameter verification failed. |
96
97**Example**
98
99```ts
100import { audio } from '@kit.AudioKit';
101audioSpatializationManager.off('spatializationEnabledChangeForCurrentDevice');
102```
103