消息提醒
This commit is contained in:
parent
78f3270dc5
commit
d0eedf37dc
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user