Fancy writing code for Obama this summer? Luke and Darth talk past each other on language debate
Jun 03

Gears Future APIs: Camera API

Gears, Tech Add comments

A core vision of Gears is that the same APIs are available on the desktop, and mobile versions.

That being said, there are APIs that will potentially make more sense on one platform or another. One of those that has garnered excitement on the mobile platform is the Location API.

Another is the newly proposed Camera API that “enables a script to trigger the camera viewfinder and allow a picture or video to be captured using the device’s onboard camera.”

That being said, this could still tie into a computers webcam.

Summary

The goal of this API is to allow a Web application to launch the native camera application and obtain the resulting media file.

On devices with built-in camera, all of the UI interaction is left to the corresponding native camera application, not Gears.

On devices that do not have a built-in camera (e.g. laptop or desktop computers), Gears will scan for attached Web cameras and will provide a basic viewport that allows the users to grab a picture or record a movie. If several cameras are attached, Gears will provide a way for the users to select the device they want to use.

This API is based on the “action-driven permission model” – the user is involved in the action and hence a separate permission prompt is not required.

You would use the API like this:

// Create a camera object
var camera = google.gears.factory.create("beta.camera");
 
// Capture an image.
var image = camera.captureImage(function(media) {
    uploadImage(media.content);
});
 
// Capture of a video, specifying a desired resolution and duration.
var video = camera.captureVideo(function(media) {
    uploadVideo(media.content);
}, 5000);

The full API proposal is:

interface Camera {
  // Acquisition methods
 
  // Triggers the camera viewfinder and invokes the callback after the user
  // has either captured the image or canceled the operation.
  void captureImage(CaptureCallback callback, optional CaptureOptions options);
  // Triggers the camera viewfinder and invokes the callback after the user
  // has either captured the video, canceled the operation or maxDuration milliseconds
  // have elapsed.
  void captureVideo(CaptureCallback callback, double maxDuration, optional CaptureOptions options);
 
  // Query methods
 
  Array availableImageFormats();   
  Array availableVideoFormats();   
};
 
void CaptureCallback(Media media);
 
interface CaptureOptions {
  string format;  // MIME type
  double width;   // desired image or video frame width
  double height;  // desired image or video frame height
};
 
interface Media {
  readonly string format;  // MIME type
  readonly double width;   
  readonly double height;
  readonly Blob content;   // reference to captured media
};

What do you think? What haven’t we thought about yet?

Other Future APIs

Disclaimer: These APIs are being discussed by the Gears community and do not represent live products. Do you have ideas for cool Gears that make the Web better? Let us know!.

8 Responses to “Gears Future APIs: Camera API”

  1. C. Enrique Ortiz Says:

    Nice, awesome! Right path!

    ceo

  2. Chris Broadfoot Says:

    Why is height and width a double?

  3. eynob Says:

    HI, do you know if gears will be available for firefox3 sometime?

  4. Anne van Kesteren Says:

    Why not use input type=file for this? If some attribute is specified, say type=image/*, user agents could present that input field as [[Make Photo] [Select Photo]] to users. The Web Forms 2.0 proposals for getting the file data out of input type=file could be used for the rest.

  5. video conferencing Says:

    This is the greatest post I have come across so far.I am really pleased to post my comment on this blog .I love your blog by the way, I am gonna have to add you to my list of watched blogs .Thank you for this very useful information. stored it.Thanks again and keep up the good work.

  6. Video Chat Says:

    “Video conferencing is great way to protect the environment by cutting down business trips as traveling does harm the air in some ways. Video conferencing to day is recognized as one of the approaches for a green environment.

  7. Jens Says:

    “What do you think? What haven’t we thought about yet?”

    You should provide a callback when the picture-taking is triggered by the camera application, e.g. by pressing the camera button.

  8. Prem Says:

    How can I use this in my code? I mean to say… I want to make a web page that records users live web cam video on my server.What steps I should follow??

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?