收藏
回答

小程序每次播放到第21回时出现内存泄漏提示

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.createInnerAudioContext() 工具 v7.0 2.4.0

一个汉字发音小程序,每次播放到第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);


        });

    },


最后一次编辑于  2019-01-25
回答关注问题邀请回答
收藏

2 个回答

  • 理理
    理理
    2020-03-20

    这个问题,最后怎么解决了?

    2020-03-20
    有用 1
    回复
  • 是小白啊
    是小白啊
    2019-01-25

    麻烦提供下代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-01-25
    有用
    回复 5
    • 2019-01-25

      https://developers.weixin.qq.com/s/EqOitGmw7v5A

      2019-01-25
      回复
    • 是小白啊
      是小白啊
      2019-01-28回复

      返回的文件的格式是什么呢?是连续点击21次就报错还是闪退?

      2019-01-28
      回复
    • 2019-01-28回复是小白啊

      调用百度的免费语音接口,返回的格式你可以打印出来看,要连续点击21次,不闪退

      2019-01-28
      回复
    • 是小白啊
      是小白啊
      2019-01-28回复

      具体是什么机型?

      2019-01-28
      回复
    • 2019-01-28回复是小白啊

      跟机型没有关系吧,在开发者工具上就有提示啊,我用lenovo z5

      2019-01-28
      回复
登录 后发表内容