Skip to content

声音与振动 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

Released under the MIT License.

本站访客数 人次 本站总访问量