消息提醒

This commit is contained in:
Vinjor 2024-10-03 00:38:43 +08:00
parent 78f3270dc5
commit d0eedf37dc

View File

@ -52,7 +52,7 @@
import {
getToken
} from '@/utils/auth'
const innerAudioContext = uni.createInnerAudioContext();
let innerAudioContext ='';
// #ifdef APP || H5
const jyJPush = uni.requireNativePlugin('JY-JPush');
// #endif
@ -60,6 +60,8 @@
data() {
return {
msgSocket: this.$msgSocket,
//
ifPlay:false,
aindex: 1,
msgNum: null,
identity: 'user',
@ -124,7 +126,20 @@
methods: {
dianyidain() {
console.log('执行了dianyidain');
if(!this.ifPlay){
console.log('执行了dianyidain');
if(innerAudioContext!=""){
try {
console.log('调用前先销毁');
innerAudioContext.stop();
innerAudioContext.destroy();
innerAudioContext="";
}catch (e){
console.log('销毁出错');
}
}
innerAudioContext = uni.createInnerAudioContext();
this.ifPlay=true
// #ifdef APP-PLUS
innerAudioContext.src = '../../static/msgV.mp3';
// #endif
@ -134,12 +149,18 @@ console.log('执行了dianyidain');
//
const playCount = 5;
let currentCount = 0;
//
innerAudioContext.play();
innerAudioContext.onError((err) => {
console.error('播放错误', err);
this.ifPlay=false
innerAudioContext.stop();
innerAudioContext.destroy(); //
});
//
innerAudioContext.onEnded(() => {
//
currentCount++;
//
if (currentCount < playCount) {
//
@ -147,16 +168,15 @@ console.log('执行了dianyidain');
} else {
//
console.log('播放完成');
this.ifPlay=false
//
innerAudioContext.stop();
innerAudioContext.destroy();
}
});
//
innerAudioContext.play();
}else{
console.log('正在播放音频,拒绝播放请求');
}
},
msgInfo() {
console.log(this.msgSocket, 'msgSocket')
@ -165,7 +185,7 @@ console.log('执行了dianyidain');
this.msgSocket.onMessage(res => {
console.log("发出提示音", res);
this.getbottom();
// this.dianyidain()
this.dianyidain()
})
}