Hi
Chris
Hi
The code is written in this way, that it always returns the front camera if the back camera is not accessible. Is the back camera working correctly?
Hi
Hi,
Unfortunately I only have the one but I have tried another vendor's camera component and it works (though I'd prefer to stick with yours).
Can you try forcing the back camera in code:
if isIOS10 then
begin
case DevicePosition of
dpCameraViewControllerDevicePositionFront: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInDuoCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
dpCameraViewControllerDevicePositionBack: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInDuoCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack);
end;
if not Assigned(vd) then
begin
case DevicePosition of
dpCameraViewControllerDevicePositionFront: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
dpCameraViewControllerDevicePositionBack: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack);
end;
if not Assigned(vd) then
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
end;
end;
if isIOS10 then
begin
case DevicePosition of
dpCameraViewControllerDevicePositionFront: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
dpCameraViewControllerDevicePositionBack: vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack);
end;
end;
end;
Pieter Scheldeman2018-08-30 13:04:36
Okay, I'll give that a go and get back to you.
OK, that was a misunderstanding from my part. But the changed code is identical, only you have to set the DevicePosition to use the front camera. Can you try this?
Sorry for delay, I've been busy on something else.
So I've just played with the code and the below appears to work (though it's still mirrored, but that's another issue).
if isIOS10 then
begin
case DevicePosition of
dpCameraViewControllerDevicePositionFront:
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInDuoCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
dpCameraViewControllerDevicePositionBack:
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInDuoCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack);
end;
if not Assigned(vd) then
begin
case DevicePosition of
dpCameraViewControllerDevicePositionFront:
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
dpCameraViewControllerDevicePositionBack:
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionBack);
end;
if not Assigned(vd) then
vd := TAVCaptureDevice.OCClass.defaultDeviceWithDeviceType(AVCaptureDeviceTypeBuiltInWideAngleCamera, AVMediaTypeVideo, AVCaptureDevicePositionFront);
end;
end
else
begin
for idx := 0 to Pred(TAVCaptureDevice.OCClass.devices().count) do
begin
vd := TAVCaptureDevice.OCClass.devices().objectAtIndex(IDX);
if Assigned(vd) then
begin
videodevice := TAVCaptureDevice.Wrap(vd);
if videoDevice.position = AVCaptureDevicePositionFront then
break;
end;
end;
end;
Hi,
Thanks for the update.