Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
ahretour
Posts: 27
Registered: ‎12-03-2013
My Device: BlackBerry Z10

Turning on/off Flashlight, when having an instance of Camera opened.

Hi!

 

Is there any way to turn on/off the flashlight (the light should stay on until it is turned off), when already having an instance opened of the Camera like:

 

Camera {
    id: camera
}

I might want to explain where i will need this:

 

Im working on a QR-Code app, where you can scan QR-Codes. What i wanted to do is, when the camera is opened, there will be a button to turn on the light (or turn off). 

 

What i have already tried:

 

The first thing i have tried is using the CameraFlashMode enum, as shown in this example:

 

qmlCameraObj.getSettings(camSettings);
                camSettings.flashMode = CameraFlashMode.On;
                qmlCameraObj.applySettings(camSettings);

 Unfortunately, this was not, what i wanted, because the flashMode is used, when taking a picture.

 

After this, i have tried the following:

 

https://github.com/blackberry/Cascades-Samples/blob/master/SensorDemo/src/Flashlight.cpp

 

This actually working pretty good, you can turn on/off the flashlight, whenever you want.

But now heres the problem:

 

When instantiating camera_handle_t i need to call the method camera_open(), which opens a new instance of the logical camera unit.

 

When this has happened, i cant open any other instances of the Camera. So when im triggering the flashlight, i can only see a black screen, when opening my camera view.

 

I thought of something like: extracting the camera instance from the Camera object itself (which i created in QML), and giving the instance to the camera_handle_t instantiation.

 

If there is any other way to achieve this, please let me know.

 

Thanks in advance!

 

 

Please use plain text.
Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: Turning on/off Flashlight, when having an instance of Camera opened.

You don't actually want the flash, what you want is called the video light. You need to be in video mode and set the CameraFlashMode to Light. You can see it being done in QML here:

 

https://github.com/blackberry/Presentations/tree/master/2012-BlackBerryJam-Asia/JAM815/CascadesStobe

 

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.
Developer
ahretour
Posts: 27
Registered: ‎12-03-2013
My Device: BlackBerry Z10

Re: Turning on/off Flashlight, when having an instance of Camera opened.

Will it still be possible to scan Barcodes via BarcodeDetector? I have tried this some minutes ago, i wasnt able to scan any qr codes, after changing the Mode to Video. Is the BarcodeDetector working in Video Mode?

Please use plain text.
Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: Turning on/off Flashlight, when having an instance of Camera opened.

Hmmm, perhaps not. That would be a good feature request, I think: DIT

 

The problem is that you need a Preview Frame to be made available to you, which you don't get in video mode in the Cascades camera control.

 

So.. for now you could either not use the light, or drop down to the C Camera API and build your own barcode decoder. The ZXing libraries are on the device, so you could do it, but it would be quite a bit of work, I expect. If you're interested in that, try BestCamera for using the C Camera in Cascades, and CustomBarcodeScanner for building your own barcode detector (though that uses the Cascades Camera API).

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.