iOS下,微信公众号jssdk的接口wx.onVoiceRecordEnd并不生效,导致在iOS录音中,一旦超过1分钟就会录音失败。
另外在iOS下,使用checkJsApi检查onVoiceRecordEnd和onVoicePlayEnd均显示为false。
Android无此故障,怀疑是微信iOS版本的专有bug。
iOS版本:13.6;微信 8.0.18
测试页面:https://z.timedg.com/2022/01weixin-jssdk-demo/audio-wx-share.html
我这边真机测试苹果和安卓微信onVoiceRecordEnd是正常的苹果是iphone15pro ios18.1.1,安卓是红米note12t hyperos1.0.12
// wx.checkJsApi({ // jsApiList: wx_api, // 需要检测的JS接口列表,所有JS接口列表见附录2, // success: function (res) { // // 以键值对的形式返回,可用的api值true,不可用为false // // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"} // console.log("录音权限", res); // }, // }); function up_voice(local_id) { wx.uploadVoice({ localId: local_id, // 需要上传的音频的本地ID,由stopRecord接口获得 isShowProgressTips: 1, // 默认为1,显示进度提示 success: function (res2) { // var serverId = res2.serverId; // 返回音频的服务器端ID app.wxRequest( "POST", app.globalData.url + "/index/wechat/get_media", { serverId: res2.serverId, }, function (res3) { console.log(res3); } ); }, }); } wx.onVoiceRecordEnd({ // 录音时间超过一分钟没有停止的时候会执行 complete 回调 complete: function (res) { console.log("录音结束", res); that.ons_records = false; var localId = res.localId; // alert("录音结束" + localId); //上传录音 up_voice(localId); }, }); if (that.ons_records) { uni.showModal({ title: "温馨提示", content: "确定停止录音并上传吗?", complete: function (res) { if (res.cancel) { } if (res.confirm) { wx.stopRecord({ complete: function (res1) { console.log("录音结束", 1, res1); that.ons_records = false; if (!res1.errMsg.includes("fail")) { var localId = res1.localId; up_voice(localId); // end } else { return uni.showToast({ title: "失败:录音时长超过60秒", icon: "none", }); } }, }); } }, }); // end } else { uni.showModal({ title: "温馨提示", content: "录音时长为一分钟", complete: function (res) { if (res.cancel) { } if (res.confirm) { wx.startRecord({ success: function (res1) { console.log("录音开始", res1); that.ons_records = true; var tempFilePath = res1.tempFilePath; // 录制成功后,可以保存录制的音频文件 }, }); // end } }, }); // end }
这个是部分代码
同问,离谱24年也还有这问题
另附上checkJsApi结果:
iOS:
{ "checkResult": { "stopVoice": true, "onVoicePlayEnd": false, "uploadVoice": true, "playVoice": true, "stopRecord": true, "pauseVoice": true, "checkJsApi": true, "onVoiceRecordEnd": false, "startRecord": true, "downloadVoice": true }, "errMsg": "checkJsApi:ok" }
Android:
{ "checkResult": { "checkJsApi": true, "startRecord": true, "stopRecord": true, "onVoiceRecordEnd": true, "playVoice": true, "pauseVoice": true, "stopVoice": true, "onVoicePlayEnd": true, "uploadVoice": true, "downloadVoice": true }, "errMsg": "checkJsApi:ok" }