Does changing camera type work on iPhone?
So, what i'm basicly doing, changing camera type when user presses the button:
AbstractConfigurationScriptableObject conf = ConfigurationScriptableObject.GetInstance();
conf.CameraType = (imgSwchr.State == 0) ? CameraDevice.CameraType.Rear : CameraDevice.CameraType.Face;
And then i flip the image verticaly if it's phone on portrait mode, and horizontaly, if its tablet and it's landscape mode:
if (imgSwchr.State == 1)
{
if(phone)
cameraDevice.FlipVideo(CameraDevice.FlipDirection.VERTICAL, true);
else
cameraDevice.FlipVideo(CameraDevice.FlipDirection.HORIZONTAL, true);
}
else
{
if (phone)
cameraDevice.FlipVideo(CameraDevice.FlipDirection.VERTICAL, false);
else
cameraDevice.FlipVideo(CameraDevice.FlipDirection.HORIZONTAL, false);
}
Everything works find on android devices and iPad, but iPhone 5 crashes when i press change camera type button. Can you assist me in what i'm doing wrong?
It is probably because you did not stop the camera when you changed the camera position.
Try the code below.
AbstractConfigurationScriptableObject conf = ConfigurationScriptableObject.GetInstance();
if(conf.CameraType == CameraDevice.CameraType.Face) {
conf.CameraType = CameraDevice.CameraType.Rear;
CameraDevice.GetInstance().Stop();
CameraDevice.GetInstance().Start();
} else {
conf.CameraType = CameraDevice.CameraType.Face;
CameraDevice.GetInstance().Stop();
CameraDevice.GetInstance().Start();
}
But i do stop() and start() camera when doing it. In order:
1. Stop()
2. Change configuration
3. Start().
Is it wrong order? Here is full method code:
void CameraBtnClick()
{
bool phone = ApplicationSettings.AppType == ApplicationSettings.AppicationType.Phone;
ImageSwitcher imgSwchr = cameraBtn.GetComponent<ImageSwitcher>();
imgSwchr.SwitchNext(false);
CameraDevice cameraDevice = CameraDevice.GetInstance();
cameraDevice.Stop();
AbstractConfigurationScriptableObject conf = ConfigurationScriptableObject.GetInstance();
conf.CameraType = (imgSwchr.State == 0) ? CameraDevice.CameraType.Rear : CameraDevice.CameraType.Face;
if (imgSwchr.State == 1)
{
if(phone)
cameraDevice.FlipVideo(CameraDevice.FlipDirection.VERTICAL, true);
else
cameraDevice.FlipVideo(CameraDevice.FlipDirection.HORIZONTAL, true);
}
else
{
if (phone)
cameraDevice.FlipVideo(CameraDevice.FlipDirection.VERTICAL, false);
else
cameraDevice.FlipVideo(CameraDevice.FlipDirection.HORIZONTAL, false);
}
cameraDevice.Start();
}
P.S. it's no way problem occurs on ImageSwitcher.
Here what logs on Xcode say:
"AVCaptureFocusModeContinuousAutoFocus And AVCaptureFocusModeAutoFocus not support"
Any idea?
Does iPad and iPhone5 is die with the above code?
"AVCaptureFocusModeContinuousAutoFocus And AVCaptureFocusModeAutoFocus not support" code is show because front camera is not support AutoFocus.