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 ;)
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.
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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With