How can I detect if user has blocked camera in browser?
I have tried this:
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
console.log(stream)
})
.catch(function(err) {
console.log(error)
});
But I get
VM1267:1 Uncaught ReferenceError: constraints is not defined
https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
I am assuming I should target this exception NotAllowedError
.
Thanks.
You need to actually specify the constraints
:
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(function(stream) {
console.log(stream)
})
.catch(function(err) {
console.log(error)
});
The MDN page you linked to in your question has more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.