ngx网络摄像头在移动设备中默认打开前置摄像头

00jrzges  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(409)
<webcam (imageCapture)="imageCaptured($event)" [trigger]="capture$" (initError)="handleInitError($event)">

默认情况下,手机上的real camera处于打开状态。我想在默认情况下设置前置摄像头。

olmpazwi

olmpazwi1#

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">

相关问题