function showTime(){
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '{$sign['appId']}', // 必填,公众号的唯一标识
timestamp: '{$sign['timestamp']}', // 必填,生成签名的时间戳
nonceStr: '{$sign['nonceStr']}', // 必填,生成签名的随机串
signature: '{$sign['signature']}',// 必填,签名,见附录1
jsApiList: [
// 所有要调用的 API 都要加到这个列表中
'startRecord',
'translateVoice',
'playVoice',
'stopRecord',
'onVoiceRecordEnd',
'onVoicePlayEnd',
'uploadVoice',
'downloadVoice'
]
});
wx.ready(function () {
// 1 判断当前版本是否支持指定 JS 接口,支持批量判断
wx.checkJsApi({
jsApiList: [
'startRecord',
'translateVoice',
'stopRecord',
'playVoice',
'onVoiceRecordEnd',
'onVoicePlayEnd',
'uploadVoice',
'downloadVoice'
],
// 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
var voice = {
localId: '',
serverId: ''
};
// 4.2 开始录音
wx.startRecord();
// 4.3 停止录音
document.querySelector('#stopRecord').on
wx.stopRecord({
success: function (res) {
voice.localId = res.localId;
}
}); //stopRecord END
}; //querySelector('#stopRecord') END
// 4.4 监听录音自动停止
wx.onVoiceRecordEnd({
// 录音时间超过一分钟没有停止的时候会执行 complete 回调
complete: function (res) {
voice.localId = res.localId;
alert('录音时间(' + voice.localId + ')已超过一分钟');
}
});
// 4.5 播放音频
document.querySelector('#playVoice').on
if (voice.localId == '') {
alert('请先使用 startRecord 接口录制一段声音');
return;
}
wx.playVoice({
localId: voice.localId
});
};
// 4.8 监听录音播放停止
wx.onVoicePlayEnd({
complete: function (res) {
alert('录音(' + res.localId + ')播放结束');
}
});
}// checkJsApi success END
});
});
wx.error(function (res) {
alert(res.errMsg);
});
}
</sc
</head>
<body on
<div id ="pagewrap" class ="main">
<h3 id="menu-voice">请手动停止录音</h3>
<button class="btn btn_primary" id="stopRecord">stopRecord</button>
<button class="btn btn_primary" id="playVoice">playVoice</button>
</div>
</body>
</html>
不按停止录音按钮,一分钟之后监听不到录音停止,请各位大虾帮忙看看,急急急!谢谢~
另外监听录音播放停止成功了的,就是监听录音停止不了,不知道怎么回事!
最佳答案