openharmony 鸿蒙 arkts-apis-audio-AudioSpatializationManager

2026-08-25 浏览 (1)

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

import { audio } from '@kit.AudioKit';

isSpatializationEnabledForCurrentDevice18+

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

TypeDescription
booleanCheck result for whether spatial audio rendering is enabled. true if enabled, false otherwise.

Example

import { audio } from '@kit.AudioKit';

let isSpatializationEnabledForCurrentDevice: boolean = audioSpatializationManager.isSpatializationEnabledForCurrentDevice();
console.info(`AudioSpatializationManager isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);

on('spatializationEnabledChangeForCurrentDevice')18+

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

NameTypeMandatoryDescription
typestringYesEvent type. The event 'spatializationEnabledChangeForCurrentDevice' is triggered when the spatial audio rendering status is changed.
callbackCallback<boolean>YesCallback 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.

IDError Message
6800101Parameter verification failed.

Example

import { audio } from '@kit.AudioKit';

audioSpatializationManager.on('spatializationEnabledChangeForCurrentDevice', (isSpatializationEnabledForCurrentDevice: boolean) => {
  console.info(`isSpatializationEnabledForCurrentDevice: ${isSpatializationEnabledForCurrentDevice}`);
});

off('spatializationEnabledChangeForCurrentDevice')18+

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

NameTypeMandatoryDescription
typestringYesEvent type. The event 'spatializationEnabledChangeForCurrentDevice' is triggered when the spatial audio rendering status is changed.
callbackCallback<boolean>NoCallback 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.

IDError Message
6800101Parameter verification failed.

Example

import { audio } from '@kit.AudioKit';
audioSpatializationManager.off('spatializationEnabledChangeForCurrentDevice');

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-audiostreambuilder-h

openharmony 鸿蒙 capi-ohaudiosuite

openharmony 鸿蒙 js-apis-inner-multimedia-systemSoundPlayer

openharmony 鸿蒙 arkts-apis-audio-i

openharmony 鸿蒙 capi-ohaudio

openharmony 鸿蒙 capi-ohmidi

openharmony 鸿蒙 arkts-apis-audio-AudioManager

openharmony 鸿蒙 capi-ohaudiosuite-oh-audiosuite-spacerenderpositionparams

openharmony 鸿蒙 capi-ohaudio-oh-audiostreaminfo

openharmony 鸿蒙 errorcode-ringtone

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/fkIQJW9N