Capture API

Categories Kindle, Mozilla, Open Technologies

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 Comments

  • Philipp von Weitershausen
    June 9, 2011

    This is awesome! Will there be a way to listen to the incoming audio stream as it’s being recorded? Or should I resort to Rainbow for that?

    • Bogo
      June 9, 2011

      Of course it will be :)

Leave a Reply

Your email address will not be published.

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