微信小程序 cameraContext.stopRecord 不报错也无响应

在微信小程序中使用wx.createCameraContext进行视频录制时,遇到stopRecord方法无响应的bug。问题根源在于同时调用setData影响了相机上下文的操作。解决方案是确保在stopRecord的成功回调中执行setData,以避免操作冲突。
摘要由CSDN通过智能技术生成

这两天碰到一个奇怪的问题,通过 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);
      }
    });
  },

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学编程的司马光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值