-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Add support for Torch and Auto Exposure (#19845) #1969
Conversation
* new callable methods torchOn and torchOff * new callable methods aeOn and aeOff * Torch and AE mode could be activated at initialize
… Exposure settings
To reviewers, sorry for the quantity of commits to review. I don't have a macbook to validate the iOS part and flutter_plugin_tools doesn't works on my windows. I used the CI to fix iOS code and code format. This feature works pretty well on android so I hope it will works also without any issues on iOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! I didn't thoroughly review the whole PR, but I gave this an initial pass with some first feedback. Thanks for the heads up about the iOS part needing additional testing and for doing as much as you could.
I'm following the initial PR review policy.I'm labeling this with "backlog" for now because this PR isn't trivial to review. We'll prioritize reviewing it according to the issue's priority.
Relevant issues:
flutter/flutter#19845
packages/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java
Outdated
Show resolved
Hide resolved
packages/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java
Outdated
Show resolved
Hide resolved
packages/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java
Outdated
Show resolved
Hide resolved
@mikerockett, thanks for your feedbacks. The flash turns on momentarily because the auto exposure mode is set to CONTROL_AE_MODE_ON_ALWAYS_FLASH. With this mode, auto exposure controls the flash and use it once immediately to adjust colors and light. Without this AE setting, I have no flash at all when I take a picture. It simply doesn't works on my phone without this AE mode and I have tested a lot of combinations. 😞 I also saw one mistake with the continuous autofocus mode so I have fixed it. For now, I finally have an old macbook so I can work on the iOS version more easily. 😋 |
I tried iPhone 6-7-8( and plus) with iOS 12 and 13. It's working no problem :) I'm using this repo https://gitlab.com/mikerockett/flutter-camera . Can you give me recently updated repo (git link) |
…ter-master # Conflicts: # packages/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java # packages/camera/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java
# Conflicts: # packages/camera/CHANGELOG.md # packages/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java # packages/camera/android/src/main/java/io/flutter/plugins/camera/CameraPlugin.java # packages/camera/pubspec.yaml
@NeKoFu – You’re most welcome. I do understand it can be quite difficult to get the right combination; I battled with this myself, which was extraordinarily frustrating given that I have very limited knowledge of how it all works. Thanks for working so hard on this. @malikdoksoz – my repo is out of date, given the changes made here. I'm not going to be updating the repo at this point, as there is a commercial app in circulation that relies on it, and the flash behaviour used (always on / always off) is perfect for our needs at the moment. |
Any idea when this feature is gonna be merged into master? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've forked the camera plugin and applied your PR changes and tested them out. The android code seems to be working fine, however your iOS implementation is broken.
I don't have much experience with Objective C code but I got it to work by doing some changes.
Essentially on the handleMethodCallAsync
you're checking for the invoking methods "flashOn" and "flashOff" but the method you really added was "setFlash", so there's really no bridge to access those methods from the dart code.
I've changed the code and got it running with a couple file changes.
Notice the changes I've done are molded towards my team needs:
in the Camera.java
file:
public void turnFlashOn(@NonNull final Result result){
setFlash(result, 3);
}
public void turnFlashOff(@NonNull final Result result){
setFlash(result, 0);
}
in the MethodCallHandlerImpl.java
:
case "turnFlashOn":
{
camera.turnFlashOn(result);
break;
}
case "turnFlashOff":
{
camera.turnFlashOff(result);
break;
}
in the CameraPlugin.m
:
} else if ([@"turnFlashOn" isEqualToString:call.method]) {
[_camera setFlashMode:true];
result(nil);
} else if ([@"turnFlashOff" isEqualToString:call.method]) {
[_camera setFlashMode:false];
result(nil);
}
lastly in the camera.dart
:
/// Turn flash light off
/// See [FlashMode] enum for available options
Future<void> turnFlashOff() async {
if (!value.isInitialized || _isDisposed) {
throw CameraException(
'Uninitialized CameraController.',
'flashMode was called on uninitialized CameraController',
);
}
try {
await _channel.invokeMethod<void>('turnFlashOff');
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
}
/// Turn flash light on
/// See [FlashMode] enum for available options
Future<void> turnFlashOn() async {
if (!value.isInitialized || _isDisposed) {
throw CameraException(
'Uninitialized CameraController.',
'flashMode was called on uninitialized CameraController',
);
}
try {
await _channel.invokeMethod<void>('turnFlashOn');
} on PlatformException catch (e) {
throw CameraException(e.code, e.message);
}
}
Echoing @LeonardoDavila, this is a high priority feature for many ongoing initiatives. Can this feature be prioritized? It seems as though only small tweaks and a re-base are necessary. |
Cant wait for a working flash solution :) |
@NeKoFu any updates? |
Is this code working for android and ios? Can i copy it? |
Hi everyone, I was very busy at the end of the year but I didn't forgot this package. At my company, I work now to porting our application to iOS and obviously, I need to finish the iOS part of this feature. I come back very soon with an update. |
Can you give us time to finish? Lack of flash is a big problem. Thank you |
Hi, @NeKoFu! Do you have any updates on this PR? It's been 2 months since your last reply. We really need the flash feature ASAP 😄 |
Hi @NeKoFu! Would be great to have this feature incorporated soon! My company needs tha flash function in our camera app. Thanks in advance. |
Conflicts: packages/camera/CHANGELOG.md packages/camera/lib/camera.dart packages/camera/pubspec.yaml packages/google_sign_in/lib/google_sign_in.dart packages/google_sign_in/pubspec.yaml
It seems like the title of the PR should include Auto Focus not Auto Exposure |
|
||
try { | ||
await _channel.invokeMethod<void>( | ||
'setAutoFocus', <String, dynamic>{'mode': mode.index}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called setAutoExposureMode:enableAutoExposure
in iOS project
The name is right according to this commit (sorry I am noob in iOS): 1d8d34a |
@NeKoFu When will I be able to use this? |
I just tried this out - it seems it is broken in iOS and a bit buggy:
I made a new PR before finding this one where I only implemented torch mode. It is working in iOS and Android and works with photos/video recording. I suggest anyone who needs the torch functionality now please try mine here: #2837 |
Description
Related Issues
Camera flash functionality during image and/or video capture #19845
Future of the Camera Plugin (Refactor/Rework) #31225
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?