TTMSFMXNativeBarcodeScanner - DevicePosition

Hi


DevicePosition works on my iPhone 5s but not on iPad2.  This happens regardless of how I set it (i.e. in the IDE or via code).

Thanks

Chris

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


It's only the rear camera that is displayed on the iPad, no matter what I do I can't access the front with the TTMSFMXNativeBarcodeScanner.  The front camera works in the standard camera app.

Many thanks

Chris

Hi,


We have investigated this here and are able to access the camera. Have you tried this on another iPad ?

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).


I'm happy to try to investigate this, could you give me some pointers at where the best place to start is?

Thanks

Chris

Can you try forcing the back camera in code:


So change:



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;


to



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.


"Can you try forcing the back camera in code:"

Just to be clear, the back camera works, it's the front camera that I cannot get to work.

Cheers

Chris

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 the problem turns out to be that the iPad 2 is running iOS 9 and the above code only works in iOS10 and greater.

Can you add code to support older iOS devices?

Many thanks

Chris

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;


Probably not the most efficient way but I'll use it until you add support for older devices.

Cheers

Chris

Hi,


We have implemented this tecnique, the next version will address this. Please keep in mind to have full functionality we strongly suggest to upgrade to the latest version of iOS.

Thanks for the update.


The iPad is pretty old and won't update beyond iOS9.

Cheers

Chris