user8779678
user8779678

Reputation:

ngx-webcam open front camera by default in mobile

<webcam (imageCapture)="imageCaptured($event)" [trigger]="capture$" (initError)="handleInitError($event)">

On mobile real camera open by default. I want to set front camera by default.

Upvotes: 1

Views: 3441

Answers (1)

Mohd Yasin
Mohd Yasin

Reputation: 483

https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/facingMode

camera.component.ts

//facingMode: string = 'environment'; Set rear camera 
facingMode: string = 'user';  //Set front camera
allowCameraSwitch = false;


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

camera.component.html

<webcam (imageCapture)="imageCaptured($event)" [trigger]="capture$" (initError)="handleInitError($event)" [videoOptions]="videoOptions" [allowCameraSwitch]="allowCameraSwitch">

Upvotes: 1

Related Questions