Class: Camera

Camera

Camera class is used for representing cameras plugged in to the computer (each instance represents a single camera). The list of all available cameras can be got with getCameras method of MindSDK class. Camera class implements MediaStreamVideoSupplier interface, so it can be used as a source of video for local MediaStream.

let camera = MindSDK.getCameras()[0];
if (camera) {
    camera.setResolution(1280, 720);
    camera.setFps(25);
    let myStream = MindSDK.createMediaStream(null, camera);
    me.setMediaStream(myStream);
    camera.acquire().catch(function(error) {
        alert("Camera can't be acquired: " + error);
    });
} else {
    alert("Camera isn't plugged in");
}

Classes

Camera

Methods

acquire() → {Promise}

Starts camera capturing. This is an asynchronous operation which assumes acquiring the underlying camera device and distributing camera's video among all consumers. This method returns a Promise that resolves with no value (if the camera capturing starts successfully) or rejects with an Error (if there is no permission to access the camera or if the camera was unplugged). If the camera capturing has been already started, this method returns resolved Promise.

Returns:

The promise that either resolves with no value or rejects with an Error.

Type
Promise

getId() → {String}

Returns the ID of the camera. The ID is unique among all cameras and never changes.

Returns:

The ID of the camera.

Type
String

getLabel() → {String}

Returns the label of the camera.

Returns:

The label of the camera.

Type
String

isOperational()

Deprecated:
  • To check if the camera is operational or not, look at the list of the available cameras — if the camera is there, then it is operational, otherwise it isn't.

release()

Stops camera capturing. This is a synchronous operation which assumes revoking the previously distributed camera's video and releasing the underlying camera device. The stopping is idempotent: the method does nothing if the camera is not acquired.

setFps(fps)

Sets frame rate which the camera should use for capturing video. The frame rate can be set at any moment regardless whether the camera is acquired or not.

Parameters:
Name Type Description
fps Number

The frame rate which the camera should use for capturing video.

setListener(listener)

Sets the listener which should be notified of all events related to the camera.

Parameters:
Name Type Description
listener CameraListener

The listener which should be notified of all events related to the camera.

setResolution(width, height)

Sets resolution which the camera should use for capturing video. The resolution can be set at any moment regardless whether the camera is acquired or not.

Parameters:
Name Type Description
width Number

The width which the camera should use for capturing video.

height Number

The height which the camera should use for capturing video.