wx.playVoice api 的 success 函数在音频开始播放后就调用
这样导致回显给用户的播放时间计时器 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);
}
})
},