We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesMediaAudio KitArkTS APIs@ohos.multimedia.audio (Audio Management)Interface (AudioSpatializationManager)

Interface (AudioSpatializationManager)

This interface implements spatial audio management.

Before calling any API in AudioSpatializationManager, you must use getSpatializationManager to obtain an AudioSpatializationManager instance.

NOTE
  • The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The initial APIs of this interface are supported since API version 18.

Modules to Import

PhonePC/2in1TabletTV
Collapse
Word wrap
Dark theme
Copy code
  1. import { audio } from '@kit.AudioKit';

isSpatializationEnabledForCurrentDevice18+

PhonePC/2in1TabletTV

isSpatializationEnabledForCurrentDevice(): boolean

Checks whether spatial audio rendering is enabled for the current device. This API returns the result synchronously.

System capability: SystemCapability.Multimedia.Audio.Spatialization

Return value

Expand
Type Description
boolean Check result for whether spatial audio rendering is enabled. true if enabled, false otherwise.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { audio } from '@kit.AudioKit';
  2. let isSpatializationEnabledForCurrentDevice: boolean = audioSpatializationManager.isSpatializationEnabledForCurrentDevice();
  3. console.info(`AudioSpatializationManager isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);

on('spatializationEnabledChangeForCurrentDevice')18+

PhonePC/2in1TabletTV

on(type: 'spatializationEnabledChangeForCurrentDevice', callback: Callback<boolean>): void

Subscribes to the spatial audio rendering status change event of the current device. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Multimedia.Audio.Spatialization

Parameters

Expand
Name Type Mandatory Description
type string Yes Event type. The event 'spatializationEnabledChangeForCurrentDevice' is triggered when the spatial audio rendering status is changed.
callback Callback<boolean> Yes Callback used to return the result, indicating whether spatial audio rendering is enabled. true if enabled, false otherwise.

Error codes

For details about the error codes, see Audio Error Codes.

Expand
ID Error Message
6800101 Parameter verification failed.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { audio } from '@kit.AudioKit';
  2. audioSpatializationManager.on('spatializationEnabledChangeForCurrentDevice', (isSpatializationEnabledForCurrentDevice: boolean) => {
  3. console.info(`isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
  4. });

off('spatializationEnabledChangeForCurrentDevice')18+

PhonePC/2in1TabletTV

off(type: 'spatializationEnabledChangeForCurrentDevice', callback?: Callback<boolean>): void

Unsubscribes from the spatial audio rendering status change event of the current device. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Multimedia.Audio.Spatialization

Parameters

Expand
Name Type Mandatory Description
type string Yes Event type. The event 'spatializationEnabledChangeForCurrentDevice' is triggered when the spatial audio rendering status is changed.
callback Callback<boolean> No Callback used to return the result, indicating whether spatial audio rendering is enabled. true if enabled, false otherwise.

Error codes

For details about the error codes, see Audio Error Codes.

Expand
ID Error Message
6800101 Parameter verification failed.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { audio } from '@kit.AudioKit';
  2. audioSpatializationManager.off('spatializationEnabledChangeForCurrentDevice');
Search in References
Enter a keyword.