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

2026-08-25 浏览 (1)

SystemSoundPlayer (Sound Effect Player)

The sound effect player provides functions for loading, unloading, and playing system sounds.

SystemSoundPlayer needs to be used with @ohos.multimedia.systemSoundManager to complete the function of managing system sounds.

NOTE

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

Modules to Import

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

SystemSoundPlayer

SystemSoundPlayer provides playback functions for camera shutter and video recording sounds. Before calling the APIs of SystemSoundPlayer, you need to create a SystemSoundPlayer object through createSystemSoundPlayer.

load

load(soundType: systemSoundManager.SystemSoundType): Promise<void>

Loads the system sound effect. This API uses a promise to return the result.

Model constraint: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

NameTypeMandatoryDescription
soundTypesystemSoundManager.SystemSoundTypeYesSystem sound effect type.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

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

IDError Message
5400103I/O error.
5400105Crash or blocking occurs in system process.
5400108Parameter check failed. Returned by promise.

Example

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

systemSoundPlayer?.load(systemSoundManager.SystemSoundType.PHOTO_SHUTTER).then(() => {
  console.info('Succeeded in calling the load method.');
}).catch((err: BusinessError) => {
  console.error(`Failed to call the load method. Code: ${err.code}, message: ${err.message}`);
});

play

play(soundType: systemSoundManager.SystemSoundType): Promise<void>

Plays the system sound effect. This API uses a promise to return the result.

Model constraint: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

NameTypeMandatoryDescription
soundTypesystemSoundManager.SystemSoundTypeYesSystem sound effect type.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

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

IDError Message
5400103I/O error.
5400105Crash or blocking occurs in system process.
5400108Parameter check failed. Returned by promise.

Example

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

systemSoundPlayer?.play(systemSoundManager.SystemSoundType.PHOTO_SHUTTER).then(() => {
  console.info('Succeeded in calling the play method.');
}).catch((err: BusinessError) => {
  console.error(`Failed to call the play method. Code: ${err.code}, message: ${err.message}`);
});

unload

unload(soundType: systemSoundManager.SystemSoundType): Promise<void>

Unloads the system sound effect that has been loaded. This API uses a promise to return the result.

Model constraint: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.SystemSound.Core

Parameters

NameTypeMandatoryDescription
soundTypesystemSoundManager.SystemSoundTypeYesSystem sound effect type.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

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

IDError Message
5400105Crash or blocking occurs in system process.
5400108Parameter check failed. Returned by promise.

Example

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

systemSoundPlayer?.unload(systemSoundManager.SystemSoundType.PHOTO_SHUTTER).then(() => {
  console.info('Succeeded in calling the unload method.');
}).catch((err: BusinessError) => {
  console.error(`Failed to call the unload method. Code: ${err.code}, message: ${err.message}`);
});

release

release(): Promise<void>

Releases the system sound effect player. This API uses a promise to return the result.

Model constraint: This API can be used only in the stage model.

System capability: SystemCapability.Multimedia.SystemSound.Core

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

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

IDError Message
5400105Crash or blocking occurs in system process.

Example

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

systemSoundPlayer?.release().then(() => {
  console.info('Succeeded in calling the release method.');
}).catch((err: BusinessError) => {
  console.error(`Failed to call the release method. Code: ${err.code}, message: ${err.message}`);
});

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-audiostreambuilder-h

openharmony 鸿蒙 capi-ohaudiosuite

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

openharmony 鸿蒙 capi-ohmidi-oh-midideviceinformation

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