|
@@ -2,7 +2,7 @@ import { LocalNotifications } from "@capacitor/local-notifications";
|
|
|
import { App } from "@capacitor/app";
|
|
|
import { Howl } from "howler";
|
|
|
|
|
|
-const sound = new Howl({
|
|
|
+const soundIm = new Howl({
|
|
|
src: ["src/assets/mp3/im.mp3"],
|
|
|
html5: false, // 强制使用HTML5 Audio
|
|
|
format: ["mp3"], // 指定格式
|
|
@@ -12,7 +12,19 @@ const sound = new Howl({
|
|
|
onloaderror: (id, error) => {
|
|
|
console.error("加载失败:", error);
|
|
|
},
|
|
|
-});
|
|
|
+});
|
|
|
+
|
|
|
+const soundVoice = new Howl({
|
|
|
+ src: ["src/assets/mp3/voice.mp3"],
|
|
|
+ html5: false, // 强制使用HTML5 Audio
|
|
|
+ format: ["mp3"], // 指定格式
|
|
|
+ preload: true, // 预加载
|
|
|
+ volume: 0.6, // 音量
|
|
|
+ pool: 16, // 可以同时播放3个实例
|
|
|
+ onloaderror: (id, error) => {
|
|
|
+ console.error("加载失败:", error);
|
|
|
+ },
|
|
|
+});
|
|
|
// 初始化通知监听
|
|
|
export async function setupNotifications(id) {
|
|
|
// 检查权限
|
|
@@ -28,10 +40,9 @@ export async function setupNotifications(id) {
|
|
|
extra: { messageId: "123" },
|
|
|
},
|
|
|
],
|
|
|
- });
|
|
|
-
|
|
|
+ });
|
|
|
// 播放自定义声音
|
|
|
- sound.play();
|
|
|
+ soundIm.play();
|
|
|
}
|
|
|
// App 状态变化时处理
|
|
|
App.addListener("appStateChange", ({ isActive }) => {
|