I am looking forward Capture API to become part of Firefox soon. It’s really cool if I have the opportunity to capture my camera and my microphone.

function success(data) {
  var container = document.createElement("div");
  document.body.appendChild(container);
  
  for (var i in data) {
    var img = document.createElement("img");
    img.src = data[i].uri;
    container.appendChild(img);
  }
}
 
function error(err) {
  alert(err.message + " (" + err.code + ")"); 
}
 
navigator.device.captureImage(success, error, { maxNumberOfMediaFiles: 1 });

This is already implemented here and it’s really useful if you want to work on mobile devices:

// capture callback
var captureSuccess = function(mediaFiles) {
    var i, path, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        path = mediaFiles[i].fullPath;
        // do something interesting with the file
    }
};

// capture error callback
var captureError = function(error) {
    navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};

// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});

2 thoughts on “Capture API

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.