Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Media Capture API vs. getUserMedia()

currently, I'm trying to do some really simple thing (well, actually I thought it is simple...): I want to take a photo from the web-cam in a web-application.

I stumbled over two possibilities:

1. The HTML Media Capture API which looks really easy:

<input type="file" accept="image/*" capture="camera">

2. JavaScript media streams, which also look pretty easy:

navigator.getUserMedia()

And here comes my question:

The HTML Media Capture API is not working in desktop browsers and the JavaScript media streams are not working on iOS. So which one should I take? Both? Which one will be developed in the future? Which one is the preferred way? Which one do you prefer? Are there any drawbacks in one solutions that I don't see so fare (except of the compatibility?).

Thanks.

BTW: I'm not an experienced HTML/JavaScript developer, so please be kind ;)

like image 742
Thomas Uhrig Avatar asked May 02 '13 13:05

Thomas Uhrig


People also ask

Is getUserMedia deprecated?

getUserMedia() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.

What is getUserMedia API?

getUserMedia API This API is used for accessing and controlling the media devices like the camera in our device. It is available in the navigator. mediaDevices object.

Is getUserMedia a part of webRTC?

getUserMedia() is a part of the webRTC media capture API and is used to get access to the camera and the microphone connected to the user device (user computer, smartphone, etc.) from the browser.

What does getUserMedia return?

It returns a Promise that resolves to a MediaStream object. If the user denies permission, or matching media is not available, then the promise is rejected with NotAllowedError or NotFoundError DOMException respectively.


1 Answers

Mobile browsers

Use HTML Media Capture to capture an image directly from the camera:

<input type="file" accept="image/*" capture >

Android (3.0+) will jump straight to the camera. Here's how it will look after some CSS styling:

Pipe Video Recorder on Android

iOS (6-10) will still give you the option to select an existing photo since it doesn't support capture. See Correct Syntax for HTML Media Capture for details.

Desktop browsers:

1) Access the webcam: use MediaStream API's getUserMedia:

navigator.getUserMedia or the newer promise based navigator.mediaDevices.getUserMedia

2) Use the canvas to take a snapshot

David Walsh's example covers both steps on desktop.

like image 93
Octavian Naicu Avatar answered Sep 28 '22 06:09

Octavian Naicu