消息提醒

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