How To Check With Javascript That Webcam Is Being Used In Chrome
If webcam is being used in Chrome, there will be a red dot on the tab for that page. And if other pages try to access webcam will get black for video. My question is, is it able to
Solution 1:
Try instead using the enabled
and readyState
properties of the MediaStreamTrack
object. You can then use a JavaScript array function such as some()
to iterate through the tracks and check if any have enabled
set to true and && readyState
equal to string 'live":
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({
audio: true,
video: true
},
function(stream) {
// returns true if any tracks have active state of truevar result = stream.getVideoTracks().some(function(track) {
return track.enabled && track.readyState === 'live';
});
if (result) {
alert('Your webcam is busy!');
} else {
alert('Not busy');
}
},
function(e) {
alert("Error: " + e.name);
});
}
Hopefully that helps!
Post a Comment for "How To Check With Javascript That Webcam Is Being Used In Chrome"