ngx-webcam 手机默认开启前置摄像头
ngx-webcam open front camera by default in mobile
<webcam (imageCapture)="imageCaptured($event)" [trigger]="capture$" (initError)="handleInitError($event)">
手机端真实相机默认开启。我想默认设置前置摄像头。
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">
<webcam (imageCapture)="imageCaptured($event)" [trigger]="capture$" (initError)="handleInitError($event)">
手机端真实相机默认开启。我想默认设置前置摄像头。
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">