-
微信调用stopReord是异步操作,太快调用该接口,fail都不会执行,会导致录音无法结束
-
wx.startRecord 安卓端不会进入该方法回调,但是可以成功唤起录音,参数也无效,该问题微信一直没有修复
-
开始说话
/** * 开始录音 */ startVoice = () => { wx.ready(() => { wx.stopRecord({ fail: function (res) { }, success: function (res) { var localId = res.localId; console.log('----结束说话成功--', localId) } }); this.recordTimeout = setTimeout(() => { this.isStart = true; nowTime = new Date().getTime(); console.log('-----开始录音---') wx.startRecord({ maxDuration: 300, }); }, 500) // 最低按500ms }) }
- 松开按钮
/** * 结束录音 */ endVoice = () => { clearTimeout(this.recordTimeout) if (this.isStart) { setTimeout(() => { wx.stopRecord({ success: (res) => { lastTime = new Date().getTime(); let diff = lastTime - nowTime; let seconds = diff % (60 * 1000) / 1000 console.log('-=-=-=-=-=-', this.isStart, seconds) console.log('----结束说话成功--') this.refs.recordVoice.className = 'action-record'; this.refs.inputVoice.className = ''; this.sendVioceMsg(res.localId); }, fail: function (err) { console.log('结束说话失败1') // alert("结束说话失败"); Toast.fail('说话时间太短!') setTimeout(() => { wx.stopRecord({ success: (res) => { }, fail: function (err) { Toast.fail('结束说话失败') console.log('结束说话失败2') } }); }, 500) } }); this.isStart = false; startRecord = false; }, 500) } else { this.isStart = false; startRecord = false; Toast.fail('说话时间太短!') } }
模拟微信按住说话功能
最新推荐文章于 2024-03-30 10:30:42 发布