New feature: Camera support for iOS and Android

android
ios

#1

With commit 772185f we have added support for camera device on iOS (iOS 7+) and Android (API 21+). To enable camera support, switch JUCE_USE_CAMERA to Enabled in juce_video module:

The DemoRunner app now enables camera by default, so you can play with it on Mac, Windows, iOS and Android.

As for other mobile features, you need to request permission from a user to access the camera. On Android you need to specify camera permission in Projucer setting:

Similarly on iOS, you need to enable the Camera Access Projucer option. There is an optional description you can set describing why you need a camera permission with a default text:

On top of Projucer settings above, JUCE will automatically request permissions from a user at runtime (you still need to enable the permissions in Projucer).

To make an existing code to work on iOS and Android, there are minimal changes required on your end:

  • use openDeviceAsync() instead of openDevice() on all platforms. Async opening is required on iOS/Android and it will just call openDevice() for Mac/Windows. You can still use openDevice() on desktop but that will not work on iOS/Android
  • use takeStillPicture() to capture photos passing a lambda that will be called to notify you when the photo has been taken, the old CameraDevice::Listener class has been removed
  • provide CameraDevice::onErrorOccurred lambda to be notified if any error occurs in a device. Usually when an error occurs, the device will have to be closed and reopened.

In case you encounter any issues, you can set JUCE_CAMERA_LOG_ENABLED flag to get a lot of debug information as well as info on camera capabilities.

Finally, we realise that modern mobile devices support tons of features like capturing raw images and that the devices allow to fine control various settings e.g. focus, exposure, white balance and so on. Time permitting, we will add support for these, but we can’t promise any timeline at this point. With this increment we made iOS and Android implementations use the same capabilities as Mac and Windows ones, which is already a big chunk of work and a step towards further improvements and features.


#2

Ohno!
We are using CameraListener to capture all frames and cannot sit and wait for them to get over to the message thread.
Please keep a version of the callback that is called for all images as an option for us doing video editing.


#3

Ok, I have resurrected CameraDevice::Listener so that you can still use it to process individual frames and you will get callbacks on whichever thread the processing is done, so same as it used to be.

For people wanting to just take a picture, takeStillPicture() is a preferred method, which will always call your callback on the message thread.

The relevant change is now pushed to develop in commit 2dd1a80


#4

Thank you, Lukasz!


#5

Lukasz, the continues capture doesnt work. The CameraDevice::Listener isnt called! Only on the very first picture.
Tested on Mac.


#6

ah, school boy error, apologies! I will push a fix shortly.


#7

Ok, the fix was pushed and it should appear on develop and master branches shortly.