How does Camera Access work in HTML and JS?
The code you show is simply implementing backward compatibility for older browsers.
Before the navigator.getUserMedia()
function was standardized, each of the major browsers had their own function, and it was conventional for them to name their extension functions with a browser prefix: webkit
for WebKit-based browsers (Chrome and Safari), moz
for Mozilla Firefox, and ms
for Microsoft browsers.
The logical-OR operator ||
evaluates its operands from left to right, returning the first one that has a truthy value.
So what this code does is try to use navigator.getUserMedia()
if it exists (which it would in a modern browser). If not, it then tries each of the older browser-specific functions as a fallback.
How to allow Chrome to access my camera on localhost?
Are you accessing the webpage that is served over HTTP, on localhost? If you are accessing it from http://localhost/...
, Chrome will ask for your permission to use the camera.
If you are opening the web page directly, i.e. /Users/Methuz/Documents/index.html then it will not work, even if you explicitly allows it permission
In this case, the workaround I use is to host the HTML file on a webserver. A quick hack is to use python, in the folder where the HTML page is lcoated: python -m SimpleHTTPServer
Related Topics
How to Remove Constraints Programmatically That Is Added from Storyboard
How to Do Base64 Encoding on Ios
Check For Internet Connection With Swift
Uiview With Rounded Corners and Drop Shadow
Starting Iphone App Development in Linux
How to Convert a Swift Array to a String
How to Record a Conversation/Phone Call on Ios
Request Failed: Unacceptable Content-Type: Text/Html Using Afnetworking 2.0
Swift Tableview in a Uiview Not Displaying Data
The Simplest Way to Resize an Uiimage
How to Debug Memory Leaks When Leaks Instrument Does Not Show Them
Getting Current Device Language in Ios
Detect If the Device Is Iphone X
How to Intercept Touches Events on a Mkmapview or Uiwebview Objects