Problem Switching Cameras


#1

I am using an iPhone SE, and the function useFrontCamera is not working. My phone does have a front camera, and the rear camera and default camera functions do work, as I can test the function by switching cameras using the Zappar UI header, and then switch back to the back camera with either of those functions, but not the front facing camera.

Sorry if this is the wrong board for this, but I was not able to find anything mentioning this problem, and could not find a report bug board.


#2

Hi @bradleycox255

Thanks for the report. This should work, but you need to make sure not to call the Z.CameraManager() part in the very first frame the javascript is loaded, as the front-facing camera capability isn’t passed through in time for that.

That means if you have the useFrontCamera() call (or just the CameraManager constructor) loose in a script node it won’t work. If you want to jump straight to the front camera, go for this:

parent.one("ready", () => {
   Z.CameraManager().useFrontCamera(); 
});

If you want to do it later (on the user pressing a button for example) then I’d just construct a camera manager in-line within the event callback, as above.


#3

That worked.
thank you.

I was originally calling the camera functions from a camera manager object that I had created in the hierarchy and set a reference to in my code. The code calling it is in response to user input, so I hadn’t even considered that it might be an order of operations problem, from loading.