小程序recorderManager.stop()发生延迟停止,求解?
发布于 5 年前 作者 wliao 6959 次浏览 来自 问答

<button class=“talk_button” hidden="{{!keyboard}}" bindtouchstart=“touchdown” bindtouchend=“touchup”>按住 说话button>

// 按钮松开

touchup:function(){

const recorderManager = that.data.recorderManager;

recorderManager.stop();

recorderManager.onStop((res) => {

const { tempFilePath } = res

that.data.filePath = res.tempFilePath;

that.voiceToChar();

})

按钮快速点击,然后释放,录音停止不了?touchup事件是没有问题的,录音启动录制也可以执行,就是stop事件在快速按住释放之后停止不了录音,而按住一段时间在释放就可以触发stop事件,这是为什么?求解?

4 回复

同问?   是什么原因?

可以把上方的html中 bind:touchstart事件换成bind:longpress 就可以解决了

这个问题之前在某帖子里见到过。

分析的结果是:

由于小程序启动录音需要一定的准备时间,也就是小程序录音是由延迟的。(1-2秒)

而如果录音时间很短,小于这个延迟时间,就松开了录音按钮,那么执行【recorderManager.stop();】这行代码的时候录音还没有启动。

而执行完recorderManager.stop();】后,录音启动了。

就这样,这次录音就关闭不了了~~~~

原因就是这样,解决方案:

1、关闭的调用可以延迟1-2秒。settimeout

2、等待官方改善该接口效率~~~~~~~~基本上等于不要有太大指望

遇到同样问题!

回到顶部