3

I am using ngx-webcam package in angular to display webcam. They have not provided any way to stop the camera it just stop when component is destroyed. I have hidden webcam component so that user can't see the webcam. I have tried to stop the webcam using javascript with following code

if (this.mediaStream && this.mediaStream.getTracks) {
  this.mediaStream.getTracks().forEach((track: MediaStreamTrack) => {
    track.stop()
  })
}

But the indicator light for the webcam does not switch off.

The ngx-webcam package code is as follow

component.html

<div class="hidden">
  <webcam [height]="400" [width]="400" [trigger]="triggerObservable" (imageCapture)="handleImage($event)"
    *ngIf="showWebcam" [allowCameraSwitch]="allowCameraSwitch" 
    [switchCamera]="nextWebcamObservable" [imageQuality]="1"
    (initError)="handleInitError($event)" mirrorImage="never">
  </webcam>
</div>
component.css

.hidden {
  display: none;
}

I have used showWebcam flag to destroy the component.

I am not able to understand if I have done something wrong in the code.

Thank you!

The ngx-webcam package does not have anything specified to stop the webcam. It stops when the component is destroyed. I have used showWebCam flag to destroy the component but it doesn't work. I have also tried by not hidding the component but got same result. I have also tried using javascript and even that didn't work for me.

1
  • Any answer for this question, I also has the same problem Commented Feb 20, 2023 at 4:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.