im trying to create a video conference web app..
the problem is im trying to disable my camera on the middle conference, its work but my laptop camera indicator still on (the light is on) but on my web, video show blank screen, is that normal or i miss something?
here what i try
videoAction() {
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then(stream => {
this.myStream = stream
})
this.myStream.getVideoTracks()[0].enabled = !(this.myStream.getVideoTracks()[0].enabled)
this.mediaStatus.video = this.myStream.getVideoTracks()[0].enabled
}
im trying to create a video conference web app..
the problem is im trying to disable my camera on the middle conference, its work but my laptop camera indicator still on (the light is on) but on my web, video show blank screen, is that normal or i miss something?
here what i try
videoAction() {
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then(stream => {
this.myStream = stream
})
this.myStream.getVideoTracks()[0].enabled = !(this.myStream.getVideoTracks()[0].enabled)
this.mediaStatus.video = this.myStream.getVideoTracks()[0].enabled
}
Share
Improve this question
asked Sep 22, 2020 at 15:26
JazulyJazuly
1,4245 gold badges22 silver badges49 bronze badges
2
- This may come down to webcam drivers. It may be that, if some program has the ability to toggle camera visibility, the cam's light turns on. Have you tried with any other cameras? – zero298 Commented Sep 22, 2020 at 15:28
- not try, but the light will off when i close the tab, so i think no problem with drivers.. – Jazuly Commented Sep 22, 2020 at 16:41
3 Answers
Reset to default 10There is also a stop()
method which should do the trick in Chrome and Safari. Firefox should already mark the camera as unused by setting the enabled
property.
this.myStream.getVideoTracks()[0].stop();
We need to assign window.localStream = stream;
inside navigator.mediaDevices.getUserMedia method
For Stop Webcam and LED light off.
localStream.getVideoTracks()[0].stop();
video.src = '';
Firstly, MediaStreamTrack.enabled is a Boolean, so you can simply assign the value false
.
To simplify your code, you might call:
var vidTrack = myStream.getVideoTracks();
vidTrack.forEach(track => track.enabled = false);
When MediaStreamTrack.enabled = false
, the track passes empty frames to the stream, which is why black video is sent. The camera/source itself is not stopped-- I believe the webcam light will turn off on Mac devices, but perhaps not on Windows etc.
.stop()
, on the other hand, completely stops the track and tells the source it is no longer needed. If the source is only connected to this track, the source itself will completely stop. Calling .stop()
will definitely turn off the camera and webcam light, but you won't be able to turn it back on in your stream instance (since its video track was destroyed). Therefore, completely turning off the camera is not what you want to do; just stick to .enabled = false
to temporarily disable video and .enabled = true
to turn it back on.