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

JavaScript
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.

JavaScript
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

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/startrecording

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