mobile_scanner
mobile_scanner copied to clipboard
Camera management
I would like to have better management of the cameras available on mobile devices. For example, on Samsungs (S21, S22 and S23) the rear camera that opens when starting is the ultra wide camera, whose focal length has several problems when it comes to reading a barcode. And I can't use the main camera because I don't have that control, since the only change we can make is choose whether to use the front and rear camera. At least as far as I could find.
I do agree that we should allow to select a specific camera for a given camera direction.
We had a similar bug report about focus issues on the web relating to the lack of this control as well.
For web the solution could be quite simple:
First: request permission to access the camera
navigator.mediaDevices.getUserMedia({
video: true,
});
Second (after permission is granted - otherwise will only show one device):
navigator.mediaDevices.enumerateDevices()
This gives a list of all available devices incl. labels and deviceId.
Third use the device specified from the list by id:
navigator.mediaDevices.getUserMedia({
video: { deviceId: { exact: <deviceId> } },
});
I guess a nice way to have this work on cross-plattform is to create a Camera object containing information about the camera such as name, id and info if about facing direction (if available). A list of these camera objects should then be queryable via a getCameras()
in MobileScannerController
. Next, the switchCamera
method could get an optional parameter camera:
that would accept one of the previously retrieved cameras.
From a previous project I also remember that when getting a list of cameras on android, there might be cameras listed that require system permission. those should be filtered from the list because it may lead to permission errors if a user wants to select them.
Please give me some feedback on the proposed solution and let me get started drafting a PR for this.
@mwoelk Thanks for the detailed idea for a solution to this problem.
I agree that your approach can fix this problem. However, I want to land the platform interface rework first, before we add this change, so that it can be added easily for each platform (we could even ship support for this feature in stages)
Hey @navaronbracke,
Sounds great. Let me know if I can support. Got some time and a project where this feature would really help.
If you could test https://github.com/juliansteenbakker/mobile_scanner/pull/916 that would be nice. I plan to put version 5.0.0 in beta for a bit, until we know that it doesn't contain any regressions, and it supports all features that we used to support.
Mainly JSQR
is not included anymore (this is probably intended, as ZXing supports more features?), and we should implement the remaining methods from the platform interface.