• Skip to main content
  • Select language
  • Skip to search
MDN Web Docs
  • Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs / DOM
    • WebExtensions
    • MathML
  • References & Guides
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
B2G OS
  1. MDN
  2. Archive of obsolete content
  3. B2G OS
  4. B2G OS APIs
  5. CameraControl
  6. CameraControl.autoFocus()

CameraControl.autoFocus()

In This Article
  1. Summary
  2. Syntax
    1. Parameters
  3. Example
  4. Specification
  5. See also

This API is available on Firefox OS for privileged or certified applications only.

Summary

This method attempts to focus the camera. If the camera is able to attempt to focus, a success callback is issued, regardless of whether or not the focusing attempt succeeds. If unable to attempt to focus, an error callback is performed instead.

The success or failure of the focus operation is indicated by the value of a parameter passed into the callback function.

Syntax

CameraControl.autoFocus(onsuccess[, onerror]);

Parameters

onsuccess
A callback function called when a focus attempt is made
onerror Optional
An optional callback function that accepts an error string as an input parameter; this is called if it's not possible to attempt to focus the camera.

Example

function onFocusPossible( success ) {
  if ( success ) {
    console.log("The image has been focused");
  } else {
    console.log("The image has not been focused");
  }
}
function onFocusNotPossible( error ) {
  console.log("The camera is not able to focus anything");
  console.log( error );
}
function onAccessCamera( camera ) {
  camera.autoFocus(onFocusPossible, onFocusNotPossible);
};
var options = {
  camera: navigator.mozCameras.getListOfCameras()[0]
};
navigator.mozCameras.getCamera(options, onAccessCamera)

Specification

Not part of any specification; however, this API should be removed when the WebRTC Capture and Stream API has been implemented.

See also

  • CameraControl

Document Tags and Contributors

Tags: 
  • API
  • B2G
  • camera
  • Firefox OS
  • Graphics
  • JavaScript
  • Method
  • Non Standard
  • Reference
  • Référence
  • WebAPI
 Contributors to this page: chrisdavidmills, teoli, SunboX, ajaybhat, kscarfone, Sheppy, Jeremie
 Last updated by: chrisdavidmills, Feb 27, 2017, 2:07:20 AM
See also
  1. Camera API
  2. Archive
  3. Related pages for Camera API
    1. CameraCapabilities
    2. CameraControl
    3. CameraManager