第二次创建相机后onCameraFrame回调函数不执行
startShowCamera() {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
var size = "small"
if (hf.dataMgr.gameRecordQuality === hf.constants.GAME_RECORD_QUALITY.MID) {
size = "medium"
}
else if (hf.dataMgr.gameRecordQuality === hf.constants.GAME_RECORD_QUALITY.HIGH) {
size = "large"
}
var camera = wx.createCamera({
x: 0,
y: 0,
width: 1,
height: 1,
devicePosition: "front",
size: size,
success: () => {
cc.log("CameraDisplay startShowCamera Success")
this.startListener()
this.m_openCb && this.m_openCb()
},
fail: (err) => {
cc.log("CameraDisplay startShowCamera Fail", err)
}
})
this.m_camera = camera
}
},
closeCamera() {
if (this.m_camera) {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
this.m_camera.destroy()
this.m_camera = undefined
}
}
this.fullSp.node.active = false
this.quarterSp.node.active = false
this.m_tex = undefined
},
startListener() {
var camera = this.m_camera
camera.onCameraFrame((frameObj) => {
if (this.m_tex) {
var data = new Uint8Array(frameObj.data)
this.m_tex.initWithData(data, cc.Texture2D.PixelFormat.RGBA8888, frameObj.width, frameObj.height)
this.m_tex.handleLoadedTexture()
}
})
camera.listenFrameChange()
}
代码如上图所示,我每次调用startShowCamera开启相机后,使用完成会destroy销毁,中间需要调用onCameraFrame监听帧变化。
只有第一次调用后,能监听到onCameraFrame回调函数帧变化,之后创建的相机再也无法监听到帧数据。
我这边能确认的是,wx.createCamera函数调用后,每次都有success回调,也就是我的startListener函数里面的listenFrameChange这些都是执行了。但是不起作用。而且我能确认摄像头确实是打开的。