This article needs a technical review. How you can help.
This API is available on Firefox OS for privileged or certified applications only.
Summary
This method is used to access to one of the cameras available on the device based on its identifier. You can get a list of the available cameras by calling the CameraManager.getListOfCameras()
method.
Syntax (pre Firefox OS 2.2)
CameraManager.getCamera(camera, cameraConfiguration, onsuccess[, onerror]);
Parameters
camera
- Specify the camera you want to use (the device may have more than one camera).
cameraConfiguration
- An object allowing you to set camera options for this camera:
mode
,previewSize
andrecorderProfile
. onsuccess
- A callback function that take a
CameraControl
object as parameter. onerror
- An optional callback function that accepts an error string as a parameter.
Example
var options = { mode: 'picture', recorderProfile: 'jpg', previewSize: { width: 352, height: 288 } }; var camera = navigator.mozCameras.getListOfCameras()[0]; function onSuccess(camera) { // Do stuff with the camera }; function onError(error) { console.warn(error); }; navigator.mozCameras.getCamera(camera, options, onSuccess, onError);
Syntax (Firefox OS 2.2+)
Promise CameraManager.getCamera(camera, cameraConfiguration);
Parameters
camera
- Specify the camera you want to use (the device may have more than one camera).
cameraConfiguration
- An object allowing you to set camera options for this camera:
mode
,previewSize
andrecorderProfile
.
Return Value
Returns a Promise
. The Promise's .then()
function accepts two function arguments:
onsuccess
- A callback function that take an object as parameter. This object has the
camera
property asCameraControl
object and theconfiguration
property as actual cameraConfiguration of device. onerror
- An optional callback function that accepts an error string as a parameter.
Example
var options = { mode: 'picture', recorderProfile: 'jpg', previewSize: { width: 352, height: 288 } }; var camera = navigator.mozCameras.getListOfCameras()[0]; function onSuccess(cameraObj) { var cameraControl = cameraObj.camera; // Do stuff with the cameraControl }; function onError(error) { console.warn(error); }; navigator.mozCameras.getCamera(camera, options).then(onSuccess, onError);
Specification
Not part of any specification as yet; this will probably be replaced by WebRTC when it gains more widespread support on mobile devices.
Permissions
Up until Firefox OS 1.4, The Camera API was a certified API, so not accessible to third party apps. From Firefox OS 2.0 onwards, the permission level has been downgraded to privileged, so it is now available for developers to use in their apps.
"type": "privileged"
"permissions": { "camera": { "description": "Required for accessing cameras on the device." } }