liming 2 minggu lalu
induk
melakukan
05d954c336
2 mengubah file dengan 19 tambahan dan 5 penghapusan
  1. 3 0
      src/App.vue
  2. 16 5
      src/utils/notifications.js

+ 3 - 0
src/App.vue

@@ -78,6 +78,9 @@ onMounted(() => {
    setTimeout(() => {
      setupNotifications(5);
   }, 2500);
+   setTimeout(() => {
+     setupNotifications(15);
+  }, 1500);
   setupNotifications(5);
   setupNotifications(6); 
 });

+ 16 - 5
src/utils/notifications.js

@@ -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 }) => {