mozilla
Your Search Results

    CameraControl.getPreviewStream()

    Non-standard
    This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

    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. The resulting stream is ready for you to use to capture still photos.

    Note: The stream you get using this method is only suitable for capturing still photos. If you want to record video, you must call CameraControl.getPreviewStreamVideoMode() instead.

    Syntax

    CameraControl.getPreviewStream(options, onsuccess[, onerror]);

    Parameters

    options
    An object containing two properties: width and height. This object must be equal to one of the objects available through CameraCapabilities.previewSizes
    onsuccess
    A callback function that accepts one parameter. This parameter is a MediaStream object, ready for use in capturing still images.
    onerror Optional
    A callback function that accepts an error string as parameter; it's called if an error occurs while attempting to obtain the MediaStream.

    Example

    This example gets a MediaStream suitable for capturing stills and begins playing the preview stream.

    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.previewSizes[0];
    
      camera.getPreviewStream(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: Sheppy, Jeremie, teoli, chrisdavidmills, kscarfone, ajaybhat
    Last updated by: chrisdavidmills,