@ohos.multimedia.systemSoundManager (System Sound Management)
This module provides basic capabilities for managing system sound effects, including defining system sound effect types and obtaining system sound effect players.
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';
SystemSoundType
Enumerates the system sound effect types.
Model constraint: This API can be used only in the stage model.
System capability: SystemCapability.Multimedia.SystemSound.Core
| Name | Value | Description |
|---|---|---|
| PHOTO_SHUTTER | 0 | Camera shutter sound. |
| VIDEO_RECORDING_BEGIN | 1 | Video recording start sound. |
| VIDEO_RECORDING_END | 2 | Video recording end sound. |
systemSoundManager.createSystemSoundPlayer
createSystemSoundPlayer(): Promise<SystemSoundPlayer | null>
Creates a SystemSoundPlayer object. This API uses a promise to return the result.
System capability: SystemCapability.Multimedia.SystemSound.Core
Return value
| Type | Description |
|---|---|
| Promise<SystemSoundPlayer | null> | Returns the SystemSoundPlayer object on success, null on failure. |
Error codes
For details about the error codes, see Media Error Codes.
| ID | Error Message |
|---|---|
| 5400101 | No memory. Return by promise. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let systemSoundPlayer: systemSoundManager.SystemSoundPlayer | null = null;
systemSoundManager.createSystemSoundPlayer().then((systemSoundPlayerInstance) => {
console.info('Succeeded in creating the system sound player.');
systemSoundPlayer = systemSoundPlayerInstance;
}).catch((err: BusinessError) => {
console.error(`Failed to create the system sound player. Code: ${err.code}, message: ${err.message}`);
});
SystemSoundPlayer
type SystemSoundPlayer = _SystemSoundPlayer
Represents the system sound effect player object.
System capability: SystemCapability.Multimedia.SystemSound.Core
| Type | Description |
|---|---|
| _SystemSoundPlayer | System sound effect player object. |