|
@@ -1,9 +1,11 @@
|
|
|
import { LocalNotifications } from "@capacitor/local-notifications";
|
|
|
import { App } from "@capacitor/app";
|
|
|
import { Howl } from "howler";
|
|
|
+import txtNotify from "@/assets/mp3/im.mp3"
|
|
|
+import voiceNotify from "@/assets/mp3/voice.mp3"
|
|
|
|
|
|
const soundIm = new Howl({
|
|
|
- src: ["src/assets/mp3/im.mp3"],
|
|
|
+ src: [txtNotify],
|
|
|
html5: false, // 强制使用HTML5 Audio
|
|
|
format: ["mp3"], // 指定格式
|
|
|
preload: true, // 预加载
|
|
@@ -14,24 +16,27 @@ const soundIm = new Howl({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
-const soundVoice = new Howl({
|
|
|
- src: ["src/assets/mp3/voice.mp3"],
|
|
|
+export const soundVoice = new Howl({
|
|
|
+ src: [voiceNotify],
|
|
|
html5: false, // 强制使用HTML5 Audio
|
|
|
format: ["mp3"], // 指定格式
|
|
|
preload: true, // 预加载
|
|
|
volume: 0.6, // 音量
|
|
|
- pool: 16, // 可以同时播放3个实例
|
|
|
+ pool: 3, // 可以同时播放3个实例
|
|
|
+ loop: true,
|
|
|
onloaderror: (id, error) => {
|
|
|
console.error("加载失败:", error);
|
|
|
},
|
|
|
});
|
|
|
let id = 1
|
|
|
// 初始化通知监听
|
|
|
-export async function setupNotifications(msgType) {
|
|
|
+export async function setupNotifications() {
|
|
|
// 检查权限
|
|
|
const granted = await LocalNotifications.requestPermissions();
|
|
|
+ console.log('权限:', granted,msgType );
|
|
|
if (!granted) return;
|
|
|
id += 1
|
|
|
+ console.log('id:', id);
|
|
|
await LocalNotifications.schedule({
|
|
|
notifications: [
|
|
|
{
|
|
@@ -42,13 +47,10 @@ export async function setupNotifications(msgType) {
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
- if(msgType == 1){
|
|
|
- return soundIm.play();
|
|
|
- }
|
|
|
- if(msgType == 2){
|
|
|
- return soundVoice.play();
|
|
|
- }
|
|
|
+ soundIm.play();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
// App 状态变化时处理
|
|
|
App.addListener("appStateChange", ({ isActive }) => {
|
|
|
console.log("App active:", isActive);
|