Skip to main content
版本:v3+

SystemSounds

API_LEVEL 3.6 开始支持,API 兼容性请参考 API_LEVEL

系统声音。

方法

getEnabled

获取系统铃声功能是否开启,开启后才可以播放

getEnabled(): boolean

getSourceType

获取内置系统铃声类型

getSourceType(): Type

Type

属性类型必填默认值说明API_LEVEL
ALARMnumber-闹钟提醒3.6
MESSAGEnumber-收到短信、邮件时,消息通知声3.6
REGULARnumber-TingTing 声3.6
ACHIEVEnumber-目标达成3.6
CAMERAnumber-照相机快门3.6
ABN_HIGHnumber-健康数据测量异常(高值)情况3.6
ABN_LOWnumber-健康数据测量异常(低值)情况3.6
SOSnumber-SOS 求救3.6

start

开始播放声音,可以传入 type 指定铃声类型,repeatCount 为音频重复次数,默认 0,不重复播放

start(sourceType: number, repeatCount: 0): void

stop

停止声音播放

stop(): void

代码示例

import { SystemSounds } from '@zos/sensor'

const systemSounds = new SystemSounds()
const alarmType = systemSounds.getSourceType().ALARM

if (systemSounds.getEnabled()) {
systemSounds.start(alarmType)
}