CameraControl.release Redirect 1

by 1 contributor:

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Summary

Releases the camera so that other applications can use it. You should call this whenever the camera is not actively being used by your application.

Warning: If you fail to call this method, other applications will never be able to access the camera.

After calling this method, your CameraControl object is defunct; you will need to call CameraManager.getCamera() to get a new one if you want to use the camera again.

Syntax

CameraControl.release([onsuccess[, onerror]]);

Parameters

onsuccess Optional
A callback function which is called once the hardware has actually been released.
onerror Optional
A callback function that accepts an error string; this is called if an error occurs while releasing the camera.

Note: Both callbacks are optional; unless you really need to know when the hardware has actually been released for use by other applications, you probably won't need to use them.

Example

This example sets up an unload event handler that will automatically release the camera when the document is unloaded (such as when the app exits).

var myCamera = null;
var options  = {
  camera: navigator.mozCameras.getListOfCameras()[0]
};

function onAccessCamera( camera ) {
  myCamera = camera;

  console.log("The camera is now used by this Apps")
};

function onReleasedCamera() {
  console.log("The camera is now free to be used by another Apps");
}

function releaseCamera() {
  if (myCamera) {
    myCamera.release(onReleasedCamera);
  }
}

navigator.mozCameras.getCamera(options, onAccessCamera);

window.addEventListener('unload', releaseCamera);

Specification

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

See also

Document Tags and Contributors

Contributors to this page: Sheppy
Last updated by: Sheppy,