Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

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

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.

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

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, teoli, ajaybhat, kscarfone, Sheppy, Jeremie
 Last updated by: chrisdavidmills,