basst314 / ngx-webcam

A simple Angular webcam component / pure & minimal, no flash-fallback
https://basst314.github.io/ngx-webcam/?
MIT License
231 stars 104 forks source link

Can't set default camera to rear camera #151

Open RuledesignerSRL opened 2 years ago

RuledesignerSRL commented 2 years ago

I have the same problem as described in issue #59, I followed the directions for using MediaTrackConstraints and set the facingMode, but nothing happen. In order to write my code I took as a reference the example provided by you here

`<webcam [height]="500" [width]="500" [trigger]="triggerObservable" (imageCapture)="handleImage($event)" [allowCameraSwitch]="true" [switchCamera]="nextWebcamObservable" [videoOptions]="videoOptions" [imageQuality]="1" (cameraSwitched)="cameraWasSwitched($event)" (initError)="handleInitError($event)"

`

public facingMode: string = 'environment'; public get videoOptions(): MediaTrackConstraints { const result: MediaTrackConstraints = {}; if (this.facingMode && this.facingMode !== '') { result.facingMode = { ideal: this.facingMode }; } return result; }

I use:

NajibIbrahim commented 2 years ago

// 'user' = front camera || 'environment' = rear camera facingMode = 'environment';

public get videoOptions(): MediaTrackConstraints {
    const result: MediaTrackConstraints = {};
    if (this.facingMode && this.facingMode !== '') {
        result.facingMode = { ideal: this.facingMode };
    }
    return result;
}