时间:2019-05-04 来源:小程序工厂
用了个土方法,监听到 onPlay 事件 同时写个setttimeout 事件 时间是当前播放音乐时长+1秒 回调如果检测没进行播放下一个,执行下一个声音播放
我也遇到同样的问题了,楼主的问题解决了吗?
//监听玩家发送的语音消息onPlayerWsAudioMessage:function (o) { cc.xdConst.HALL_VOICE[cc.xdConst.HALL_VOICE.length] = o; this.playerPlayVoice(cc.xdConst.HALL_VOICE[0]);},playerPlayVoice:function (voiceData) { let seat = voiceData.seat; let audioPath = voiceData.audioPath; if(this.playerScripts[seat]!=null){ this.playerScripts[seat].showAudioMessage(audioPath, ()=>{ //开始播放 cc.xdConst.HALL_VOICE.splice(0,1); }, (len)=>{ //播放中 }, ()=>{ //播放完成 if(cc.xdConst.HALL_VOICE.length > 0){ this.playerPlayVoice(cc.xdConst.HALL_VOICE[0]); } }); }},//展示语音消息showAudioMessage:function (o, startPlay, playing, playEnd) { let anim = this.audioMessage.node.getChildByName("audioplay").getComponent(cc.Animation); cc.xdSdk.playVoiceFile(o, ()=>{ //开始播放 cc.xdSdk.log('开始播放语音'); startPlay(); }, (len)=>{ //播放中 playing(); cc.xdSdk.log('播放语音ing ' + + len + '秒'); this.audioMessage.node.active = true; this.audioMessage.node.getChildByName("audiolength").getComponent(cc.Label).string = len+"\""; anim.play(); cc.xdAudioManager.pauseMusic(); }, ()=>{ //播放完成 playEnd(); // cc.xdConst.HALL_VOICE.splice(0,1); cc.xdSdk.log('停止语音'); this.audioMessage.node.active = false; anim.stop(); cc.xdAudioManager.resumeMusic(); });},//小游戏播放语音playVoiceFile:function (audioPath, callStarPlay, callbackPlaying, callbackEnd) { if(window.wx){ let flag = true; let innerAudioContext = wx.createInnerAudioContext(); innerAudioContext.src = audioPath; //播放语音 innerAudioContext.play(); innerAudioContext.onPlay(() => { console.log('开始播放'); callStarPlay(); }); innerAudioContext.onTimeUpdate(res=>{ if(flag){ callbackPlaying(innerAudioContext.duration.toFixed(2)); flag = false; } }); innerAudioContext.onEnded(()=>{ console.log('播放完成'); callbackEnd(); }); innerAudioContext.onError((res) => { console.log(res.errMsg); console.log(res.errCode); }); }},收到多条语音时,采用逐条播放,第一条语音可以正常播放,正常走onEnded(), 但第二条语音播放完成后不回调onEnded(),是因为什么原因呢?
你好,请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。