我也出现了同样的问题,请问现在解决了嘛?
CameraContext.onCameraFrame回调时闪退此问题在真机调试及模拟器运行时表现有所不同。简单地说,就是CameraContext.onCameraFrame的回调函数无法被调用,一旦调用就会闪退。 在iPhone X 上是整个微信退出,在Android机(已在一加及OPPO上测试过)上是退出小程序。期间有log而无error信息(见下方截图)。 在模拟器上则是报thirdScriptError错误(见下方截图。本人以createObjectURL为关键词搜索过后,初步怀疑是模拟器环境所使用的Chrome内核的问题),小程序不闪退。 代码见下方。如是本人调用过程中有所遗漏,烦请指正。如是API本身的BUG,请尽快修复并告知。谢谢! WXML: [代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"view_container"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]camera[代码] [代码]device-position[代码][代码]=[代码][代码]"back"[代码] [代码]mode[代码][代码]=[代码][代码]"normal"[代码] [代码]frame-size[代码][代码]=[代码][代码]"medium"[代码] [代码]flash[代码][代码]=[代码][代码]"off"[代码] [代码]class[代码][代码]=[代码][代码]"view_camera"[代码][代码]></[代码][代码]camera[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]type[代码][代码]=[代码][代码]"primary"[代码] [代码]bindtap[代码][代码]=[代码][代码]"scan"[代码][代码]>扫描</[代码][代码]button[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"view_container"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]wx:if[代码][代码]=[代码][代码]"{{src}}"[代码] [代码]mode[代码][代码]=[代码][代码]"widthFix"[代码] [代码]src[代码][代码]=[代码][代码]"{{src}}"[代码][代码]></[代码][代码]image[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码] WXSS: [代码].view_container{[代码][代码] [代码][代码]width[代码][代码]: [代码][代码]100%[代码][代码];[代码][代码] [代码][代码]height[代码][代码]: [代码][代码]100%[代码][代码];[代码][代码] [代码][代码]background-color[代码][代码]: [代码][代码]#c1c1c1[代码][代码];[代码][代码] [代码][代码]text-align[代码][代码]: [代码][代码]center[代码][代码];[代码][代码] [代码][代码]display[代码][代码]: flex;[代码][代码] [代码][代码]justify-[代码][代码]content[代码][代码]: [代码][代码]center[代码][代码];[代码][代码] [代码][代码]flex-[代码][代码]direction[代码][代码]: row;[代码][代码]}[代码][代码].view_camera{[代码][代码] [代码][代码]width[代码][代码]: [代码][代码]500[代码][代码]rpx;[代码][代码] [代码][代码]height[代码][代码]: [代码][代码]500[代码][代码]rpx;[代码][代码]}[代码] JS: [代码]// pages/scan/scan.js[代码][代码]Page({[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面的初始数据[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]data: {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面加载[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onLoad: [代码][代码]function[代码] [代码](options) {[代码][代码] [代码][代码]console.log([代码][代码]"loaded scan"[代码][代码]);[代码][代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面初次渲染完成[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onReady: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面显示[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onShow: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]scan: [代码][代码]function[代码] [代码](){[代码][代码] [代码][代码]console.log([代码][代码]'start scan'[代码][代码])[代码][代码] [代码][代码]const context = wx.createCameraContext()[代码][代码] [代码][代码]console.log([代码][代码]'created context'[代码][代码])[代码][代码] [代码][代码]context.takePhoto({ // 这是后来为了测试cameraContext是不是真的能运行而加上的,实际运行确实能拍照[代码][代码] [代码][代码]quality: [代码][代码]'high'[代码][代码],[代码][代码] [代码][代码]success: (res) => {[代码][代码] [代码][代码]console.log(res.tempImagePath)[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]src: res.tempImagePath[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]if[代码] [代码](context.onCameraFrame) {[代码][代码] [代码][代码]console.log([代码][代码]'onCameraFrame is available'[代码][代码]) // 这一句log每次都能顺利打出来[代码][代码] [代码][代码]const listener = context.onCameraFrame((frame) => {[代码][代码] [代码][代码]console.log([代码][代码]'fetch camera'[代码][代码]) // 这一句log从来没有打出来过[代码][代码] [代码][代码]// console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]if[代码] [代码](listener.start) {[代码][代码] [代码][代码]listener.start()[代码][代码] [代码][代码]console.log([代码][代码]'listener start'[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]} [代码][代码]else[代码] [代码]{[代码][代码] [代码][代码]console.log([代码][代码]'onCameraFrame is not available'[代码][代码])[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面隐藏[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onHide: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 生命周期函数--监听页面卸载[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onUnload: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面相关事件处理函数--监听用户下拉动作[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onPullDownRefresh: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 页面上拉触底事件的处理函数[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onReachBottom: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 用户点击右上角分享[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]onShareAppMessage: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]}[代码][代码]})[代码] 真机调试日志输出窗口: [图片] 模拟器日志输出窗口: [图片]
2019-07-31