wx.playVoice api 的 success 函数在音频开始播放后就调用
发布于 6 年前 作者 bgong 6670 次浏览 来自 问答

这样导致回显给用户的播放时间计时器 Interval 无法在音频播放完成后清除,体验上有些不足。

playVoice:function (idx) {

let that = this;
   this.data.playTime = 0;

   playInterval = setInterval(function () {
that.data.playTime ++;
       that.data.playTimeFormat = Utils.formatTime(that.data.playTime);
       that.setData(that.data)
},1000);

   wx.playVoice({
filePath:that.data.voiceList[idx].voice,
       success:function () {
that.setData({playing:false,playIdx:-1});
           clearInterval(playInterval);
       },
       complete:function () {
clearInterval(playInterval);
       }
})
},
回到顶部