代码如上,每次超过 5 分钟,只能有 5 分钟,模拟器正常,录到10分钟会自动停止。
用了四部真机测试,录制到 9 分多钟会手动停止,都是只能显示 5 分钟。
录音的前一个页面是video组件在播放视频,点击视频下面的发送语音按钮,到新页面录制。
// 开始录制
start: function (e) {
const that = this;
console.log(e);
that.setData({
JGH_recording1: false
})
recorderManager.onStart(() => {
that.isrecordering = true;
})
recorderManager.onStop(function (res) {
let _new_count = formatTime(res.duration / 1000);
let audioData = {};
audioData.audio_url = res.tempFilePath;
audioData.duration = res.duration;
audioData.playstate = ‘pause’;
audioData.new_duration = _new_count;
that.subaudio(res.tempFilePath, res.duration, audioData);
});
const options = {
duration: 600000,
sampleRate: 44100,
numberOfChannels: 1,
encodeBitRate: 192000,
format: ‘mp3’,
frameSize: 50
};
recorderManager.start(options);
//时间统计
var totalSecond = 0;
interval = setInterval(function () {
// 秒数
var second = totalSecond;
// 分钟位
var min = Math.floor((second) / 60);
var minStr = min.toString();
if (minStr.length == 1) minStr = ‘0’ + minStr;
// 秒位
var sec = second - min * 60;
var secStr = sec.toString();
if (secStr.length == 1) secStr = ‘0’ + secStr;
that.setData({
totalSecond: totalSecond,
countDownMinute: minStr,
countDownSecond: secStr
});
totalSecond++;
if (totalSecond < 0) {
clearInterval(interval);
//设置结束
that.setData({
totalSecond: totalSecond,
countDownMinute: ‘00’,
countDownSecond: ‘00’
});
}
}.bind(this), 1000);
},
// 停止录音
stop: function (e) {
const that = this;
recorderManager.stop();
clearInterval(interval);
that.isrecordering = false;
that.setData({
state: ‘stop’,
countDownMinute: ‘00’,
countDownSecond: ‘00’
})
that.setData({
JGH_recording1: true
})
},