声音与振动 useRingtone
更新: 2025/1/15 字数: 0 字 时长: 0 分钟
基础使用
useRingtone
用于控制设备的振动、铃声、提示音,使用时需开启设备音量。
振动
playVibration
方法用于开启振动,stopVibration
方法用于关闭振动。
ts
import useRingtone from "@/hooks/useRingtone";
const { playVibration, stopVibration } = useRingtone();
铃声
playRingtone
方法用于播放铃声,stopRingtone
方法用于关闭铃声。
ts
import useRingtone from "@/hooks/useRingtone";
const { playRingtone, stopRingtone } = useRingtone();
提示音
playNotificationSound
方法用于播放提示音,提示音只持续几秒就自动停止,常用于消息提示。
ts
import useRingtone from "@/hooks/useRingtone";
const { playNotificationSound } = useRingtone();
API
方法
方法名 | 说明 | 类型 |
---|---|---|
playVibration | 播放振动 | () => void |
stopVibration | 停止振动 | () => void |
playRingtone | 播放铃声 | () => void |
stopRingtone | 停止铃声 | () => void |
playNotificationSound | 播放提示音 | () => void |