一个汉字发音微信小程序,每次播放到第21个字时,在开发者工具上会有如下提示(在真机上运行会比较卡顿):
[Event] 21 listeners of event 15484096367270.5245944830972495_onAudioStateChange_play have been added, possibly causing memory leak.
主要代码如下
const n = wx.createInnerAudioContext();
....
voice2: function() {
if (this.hasShowSound && this.data.hasEnded){
this.playSoundQues();
}else if(this.data.hasEnded && this.hasShowSound == !1){
this.showMo();
}else{
this.voiceStop();
}
},
voiceStop: function() {
n.stop();
},
playSoundQues: function() {
let that = this;
let t = getApp(), a = this.data.answer, e = a.qa;
//n.autoplay = !0,
n.src = "https://tsn.baidu.com/text2audio?tex=" + encodeURI(e) + "***此处省略***" + t.globalData.token + "&per=0&spd=5&pit=5&vol=5", n.play(),
n.onPlay(function() {
that.setData({ hasEnded : !1 });
nextEnable = !1;
}),n.onEnded(function() {
that.setData({ hasEnded : !0 });
nextEnable = !0;
}), n.onStop(function() {
that.setData({ hasEnded : !0 });
nextEnable = !0;
}),n.onError(function(t) {
nextEnable = !0,
console.log("error1---",t.errMsg), console.log("errorcode==",t.errCode);
});
},
微信小程序开发问题解答
微信小程序开发者回答:
麻烦提供下代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
本文网址:http://www.91bianli.com/weixinxiaochengxu/23244.html