by in Blog

Post tags: camera getusermedia odin opera operanext webapi

This post is licensed under a Creative Commons Attribution 3.0 Unported license.

Camera access from a web page in Opera Next

In 1969, we were told that someday, you'll be a star, and after great efforts from the open web community, that time has come! Access to the camera from a web page through JavaScript (getUserMedia) is possible. Grab the latest Opera Next version from the desktop team blog!

Let's rewind a bit. On October 2011 and January 2012, we released desktop Labs builds for testing getUserMedia. Your feedback has been valuable and helped fixed issues.

The first time you access a web page that requests access to the camera, you will get a notification requesting you to authorize it. It's time to rush to the bathroom, fix your hair, make up, change your shirt and smile. If you are not satisfied, you can deny right away.

Then you might want to change these settings later on - perhaps your image on the camera was not what you were expecting. Just click on the icon on the address bar and a menu pops up.

Good! Now you have the choice in between a few options: Always, Allow once or Deny.

There will always be an icon in the toolbar or the tab to tell you that the camera access is ongoing in case you had forgotten. It's worth noting that we do something similar for sites that request access to your geolocation.

The API for accessing the camera is fairly simple.

navigator.getUserMedia({audio: true, video: true}, success, error);

 function success(stream) {
  // ... use 'stream' ...
  }

  function error(){
  //display fallback content
  }

You can find more code samples and advanced examples in Daniel Davis' Dev.Opera article about getUserMedia.

And because we all need a moustache to be a star:

Time for you to code your project and share with us.