Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

CameraControl.startRecording()

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

Summary

This method is used to start recording a video file on the device; the video is stored as a 3gp file.

Note: Before calling this method, you must call CameraControl.getPreviewStreamVideoMode(); if you don't, this method will fail.

Once the recorder starts running, its state can change asynchronously based on the limits set when you called startRecording(); see Options below. To monitor and react to those changes, you can use the CameraControl.onRecorderStateChange property to define a custom callback function.

Syntax

CameraControl.startRecording(options, storage, filename, onsuccess[, onerror]);

Parameters

options
An object specifying options for the video capture operation; see Options below.
storage
An object of type DeviceStorage that defines where to store the output file.
filename
The name of the output file.
onsuccess
A callback function that is called once the recording has began.
onerror Optional
A callback function that accepts an error string as parameter.

Options

The options object passed to this method has the following properties:

rotation Optional
The degrees clockwise to rotate the recorded video; if this option is not supported by the device, it will be ignored; if this option is missing, the default is 0.
maxFileSizeBytes Optional
The maximum size in bytes to which the recorded video file will be allowed to grow. If this option is missing, zero, or negative no size limit will be applied (up to the physical limits of the device).
maxVideoLengthMs Optional
The maximum length in milliseconds to which the recorded video will be allowed to grow. If this option is missing, zero, or negative no size limit will be applied up to the physical limits of the device.

Example

This example records up to 1 GB or 1 hour of video, storing it in the standard videos store on the device. Note the use of navigator.getDeviceStorage() to determine the storage location for the video.

var storage = navigator.getDeviceStorage('videos');
var cameraOptions = {
  camera: navigator.mozCameras.getListOfCameras()[0]
};
var recordOptions = {
  rotation: 0,
  maxFileSizeBytes: 1024 * 1024 * 1024 // 1 GB
  maxVideoLengthMs: 1000 * 60 * 60     // 1 hour
}

function onRecordStart() {
  console.log("The device is recording the video output from the camera");
}

function onStateChange( newState ) {
  console.log("The recorder state change: " + newState);
}

function onAccessCamera( camera ) {
  camera.startRecording(recordOptions, storage, 'myVideo.3gp', onRecordStart);
  camera.onRecorderStateChange = onStateChange;
};

navigator.mozCameras.getCamera(cameraOptions, 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, getabetterpic, ajaybhat, kscarfone, Sheppy, Jeremie
 Last updated by: chrisdavidmills,