这两天碰到一个奇怪的问题,通过 wx.createCameraContext(); 拿到的cameraContext对象,
执行cameraContext.startRecord没有问题,
但是执行cameraContext.stopRecord不报错也无响应,
很是头疼,微信这方面的资料又很少,研究半天,发现是this.setData影响的。
不论是在cameraContext.stopRecord之前执行了setData,
还是在setData的回调函数中执行cameraContext.stopRecord,
都不可以。
若真的需要setData,只能放在cameraContext.stopRecord成功后的回调函数中。
stopRecord() {
console.log("stopRecord, this.data.num ="+this.data.num);
if (this.data.isStop){ //说明已结束
return;
}
wx.showLoading({
title: '视频处理中',
mask: true
});
this.end(this);
},
end(that) {
console.log("that",that);
console.log("that.cameraContext.webviewId="+that.cameraContext.webviewId);
console.log("that.cameraContext._isRecording2="+that.cameraContext._isRecording);
that.cameraContext.stopRecord({
compressed: true, //压缩视频
success: (res) => {
console.log("stopRecord success", res);
that.setData({
src: res.tempThumbPath,
videoSrc: res.tempVideoPath,
num: 0,
isStart: false,
isStop: true,
});
wx.hideLoading();
},
fail: (e) => {
console.log("stopRecord fail", e);
wx.showLoading({
title: '异常请重试',
})
},
complete: (res) => {
console.log("stopRecord complete", res);
}
});
},