openharmony 鸿蒙 js-apis-audioHaptic-sys

2026-08-25 浏览 (1)

@ohos.multimedia.audioHaptic (Audio-Haptic) (System API)

Audio-haptic enables users to get rhythmic auditory and haptic feedback while having incoming calls or messages.

NOTE

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

Device behavior difference: For a device without a vibration component, no vibration effect is generated.

Module to Import

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

AudioHapticPlayer

Implements audio-haptic playback. Before calling any API in AudioHapticPlayer, you must use createPlayer to create an AudioHapticPlayer instance.

isHapticsIntensityAdjustmentSupported20+

isHapticsIntensityAdjustmentSupported(): boolean

Checks whether the device supports adjusting the intensity of haptic feedback.

System API: This is a system API.

System capability: SystemCapability.Multimedia.AudioHaptic.Core

Return value

TypeDescription
booleanCheck result for the support of intensity adjustment. true if supported, false otherwise.

Error codes

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

Error CodeError Message
202Caller is not a system application.

Example

const result: boolean = audioHapticPlayerInstance.isHapticsIntensityAdjustmentSupported();

isHapticsRampSupported20+

isHapticsRampSupported(): boolean

Checks whether the device supports gradually adjusting the intensity of haptic feedback, also known as haptic ramping.

System API: This is a system API.

System capability: SystemCapability.Multimedia.AudioHaptic.Core

Return value

TypeDescription
booleanCheck result for the support of haptic ramping. true if supported, false otherwise.

Error codes

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

Error CodeError Message
202Caller is not a system application.

Example

const result: boolean = audioHapticPlayerInstance.isHapticsRampSupported();

enableHapticsInSilentMode20+

enableHapticsInSilentMode(enable: boolean): void

Enables the audio-haptic player to provide haptic feedback even when the device is in silent mode.

NOTE

This API must be called before the audio-haptic player is released. It cannot be called during playback.

System API: This is a system API.

System capability: SystemCapability.Multimedia.AudioHaptic.Core

Parameters

NameTypeMandatoryDescription
enablebooleanYesWhether to enable haptic feedback in silent mode. true to enable, false otherwise.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

Error CodeError Message
202Caller is not a system application.
5400102Operate not permit in current state.

Example

audioHapticPlayerInstance.enableHapticsInSilentMode(true);

setHapticsIntensity20+

setHapticsIntensity(intensity: number): Promise<void>

Sets the intensity of haptic feedback for this audio-haptic player. This API uses a promise to return the result.

NOTE

This API must be called before the audio-haptic player is released. It can be called only once during a single playback.

System API: This is a system API.

System capability: SystemCapability.Multimedia.AudioHaptic.Core

Parameters

NameTypeMandatoryDescription
intensitynumberYesIntensity, in the range [0.00, 1.00], where 1.00 indicates the maximum intensity (100%).

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

Error CodeError Message
202Caller is not a system application.
801Function is not supported in current device.
5400102Operate not permit in current state.
5400108Parameter out of range.

Example

import { BusinessError } from '@kit.BasicServicesKit';

audioHapticPlayerInstance.setHapticsIntensity(0.5).then(() => {
  console.info('Promise returned to indicate that set intensity successfully.');
}).catch ((err: BusinessError) => {
  console.error(`Failed to set intensity. ${err}`);
});

setHapticsRamp20+

setHapticsRamp(duration: number, startIntensity: number, endIntensity: number): Promise<void>

Sets the haptic ramp for this audio-haptic player. This API uses a promise to return the result.

NOTE

  • This API must be called before and after the audio-haptic player plays and before the player is released.
  • This API can be called only once.

System API: This is a system API.

System capability: SystemCapability.Multimedia.AudioHaptic.Core

Parameters

NameTypeMandatoryDescription
durationnumberYesDuration of the ramp, in ms. The value must be an integer and cannot be less than 100 ms.
startIntensitynumberYesStart intensity. The value is in the range [0.00, 1.00], where 1.00 indicates the maximum intensity (100%).
endIntensitynumberYesEnd intensity. The value is in the range [0.00, 1.00], where 1.00 indicates the maximum intensity (100%).

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and Media Error Codes.

Error CodeError Message
202Caller is not a system application.
801Function is not supported in current device.
5400102Operate not permit in current state.
5400108Parameter out of range.

Example

import { BusinessError } from '@kit.BasicServicesKit';

const duration = 10000;
const startIntensity = 0.5;
const endIntensity = 1;

audioHapticPlayerInstance.setHapticsRamp(duration, startIntensity, endIntensity).then(() => {
  console.info('Promise returned to indicate that set haptics ramp successfully.');
}).catch ((err: BusinessError) => {
  console.error(`Failed to set haptics ramp. ${err}`);
});

你可能感兴趣的鸿蒙文章

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/3zhSqieT