CameraControl.getPreviewStreamVideoMode()

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

Summary

This method is used to configure and access a MediaStream from the camera. You use the resulting MediaStream object to record video.

Note: You must use this method to get a MediaStream suitable for recording video. If you want to capture still images, you need to call CameraControl.getPreviewStream() instead.

Syntax

JavaScript
CameraControl.getPreviewStreamVideoMode(options, onsuccess[, onerror]);

Parameters

options
An object defining the video mode to use. This object must be equal to one of the objects available through CameraCapabilities.videoSizes
onsuccess
A callback function that will accept one parameter. This parameter is a MediaStream object.
onerror Optional
A callback function that accepts an error string as parameter. This is called if an error occurs while attempting to get the MediaStream.

Example

This example gets the preview stream and starts playing it.

JavaScript
var display = document.getElementsByTagName('video')[0];
var options = {
  camera: navigator.mozCameras.getListOfCameras()[0]
};

function onStreamReady( stream ) {
  display.mozSrcObject = stream;
  display.play();
}

function onAccessCamera( camera ) {
  var size = camera.capabilities.videoSizes[0];

  camera.getPreviewStreamVideoMode(size, onStreamReady);
};

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

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/cameracontrol/getpreviewstreamvideomode

API B2G camera Camera DOM DOM Reference Firefox OS Graphics Method Reference Référence WebAPI