From 10b470bf76b1488c0bbc4625b4648db39486f26e Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Thu, 28 Mar 2024 14:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=AD=E9=9F=B3=E6=94=B6?= =?UTF-8?q?=E6=AC=BE=E6=92=AD=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/App.vue b/App.vue index 1228910..522bbae 100644 --- a/App.vue +++ b/App.vue @@ -25,6 +25,11 @@ import Routine from './libs/routine.js'; import Cache from '@/utils/cache'; export default { + data(){ + return { + audioTeam: [], + } + }, globalData: { spid: 0, code: 0, @@ -131,11 +136,9 @@ if (this.audioTeam.length > 0) { this.audioTeam.push(result.extras.type); } else { - this.audio() + this.audio(result.extras.mp3) this.audioTeam.push(result.extras.type); } - - } // 点击事件 if (notificationEventType == 'notificationOpened') { @@ -201,9 +204,12 @@ } // #endif that.getConfigData(); + // setTimeout(()=>{ + // this.audio('https://lihai001.oss-cn-chengdu.aliyuncs.com/app/out.wav') + // // this.audio() + // }, 1500) }, onShow() { - let that = this that.$store.commit('SETUUID', uni.getStorageSync('uuid') || that.randomString()); // 记录H5和公众号 @@ -292,6 +298,36 @@ }) + }, + /** + * 语音播报 + * + * + */ + async audio(url) { + const innerAudioContext = uni.createInnerAudioContext(); + innerAudioContext.src = url || `/static/audio/order.mp3`; + innerAudioContext.autoplay = true; + innerAudioContext.onPlay(() => { + console.log('开始播放') + }); + innerAudioContext.onEnded(() => { + console.log('语音播报结束') + innerAudioContext.destroy() //销毁 + if (this.audioTeam.length > 1) { + this.audioTeam.splice(0, 1); + console.log('队列中'); + this.audio() + } else { + console.log('队列为零'); + this.audioTeam = [] + } + }); + innerAudioContext.onError((err) => { + console.log('语音播报失败', err) + innerAudioContext.destroy() // 销毁 + }); + }, randomString(len) { //   len = len || 32;