CameraManager.getCamera()

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)

JavaScript
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 and recorderProfile.
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

JavaScript
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+)

JavaScript
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 and recorderProfile.

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 as CameraControl object and the configuration property as actual cameraConfiguration of device.
onerror
An optional callback function that accepts an error string as a parameter.

Example

JavaScript
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.

JavaScript
"type": "privileged"
JavaScript
"permissions": {
  "camera": {
    "description": "Required for accessing cameras on the device."
  }
}

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/cameramanager/getcamera

API Firefox OS Graphics JavaScript Method Reference Référence WebAPI