via
请问公众号onVoiceRecordEnd后,为何localId是undefined?代码如下: wx.config({ debug : false, appId : data.appid, timestamp : data.timestamp, nonceStr : data.noncestr, signature : data.signature, jsApiList : [ "startRecord", "stopRecord","onVoiceRecordEnd","uploadVoice","downloadVoice","getLocation" ] }); wx.ready(function() { startRecord(); wx.onVoiceRecordEnd({ // 录音时间超过一分钟没有停止的时候会执行 complete 回调 complete: function (res) { var localId = res.localId; uploadVoice(localId); setTimeout(function () { // 这里就是处理的事件 startRecord(); }, 2000); }, fail : function(res) { console.log(JSON.stringify(res)); } }); }); function startRecord() { wx.startRecord({ success: function(res){ localStorage.rainAllowRecord = 'true'; }, cancel: function () { saveLog("用户拒绝授权录音"); }, fail : function(res) { var content=JSON.stringify(res); saveLog(content); } }) // } } function uploadVoice(localId) { wx.uploadVoice({ localId: localId, // 需要上传的音频的本地ID,由stopRecord接口获得 isShowProgressTips: 1, // 默认为1,显示进度提示 success: function (res) { var mediaId=res.serverId; //把录音在微信服务器上的id(res.serverId)发送到自己的服务器供下载。 $.ajax({ url: '/wx/savefile', type: 'post', data: {mediaId:mediaId}, dataType: "json", success: function (data) { console.log("文件已保存"); }, error: function (xhr, errorType, error) { } }); }, fail : function(res) { var content=JSON.stringify(res); saveLog(content); } }); } 加载config后,启动录音,onVoiceRecordEnd监听录音时间超过一分钟没有停止的时候,执行 complete 回调。但是localId获取有时候会存在undefined。 一般是什么情况会造成这种问题。要如何解决。
2021-10-27