我如何强制应用程序询问用户相机许可?

时间:2019-05-07 08:35:36

标签: angular typescript angular7

我需要征得允许才能在Angle Web应用程序中使用Camera。当我切换cameraId以开始新的呼叫(与其他摄像机)时,它在Windows上工作正常,但在Andoroid上却出现此错误: 媒体访问NotReadableError:无法启动视频源。 这似乎是由于摄像机的权限。

谢谢

  switchCamera() {
    for (let id of this.ids) {
      if (id != this.cameraId) {
        this.cameraId = id;
        break;
      }
    }
    this.dossierService.cameraId = this.cameraId;
    this.dossierService.fromClient = true;
    this.router.navigate(['videoperizia']);
  }

此方法将照相机的新ID保存在this.dossierService.cameraId中, 然后我导航到其他组件“ videoperizia”。 因此,如果VideoPerizia的fromClient == true,则导航回Client.component(代码中的这个),并使用新ID开始新的调用:

        ngOnInit() {
    this.canvas = <HTMLCanvasElement>document.getElementById('canvas');
    if (this.dossierService.cameraId) {
      this.startCall(this.dossierService.cameraId);
    }
  }


startCall(cameraId?: string) {
        try {
          this.agoraService.client.getCameras(_ => {
            if (_.length > 1) {
              this.enableSwitchCamera = true   
              this.cameraId = cameraId || _[1].deviceId;
              this.ids = _.map(device => device.deviceId);
            }
            else {
              this.enableSwitchCamera = false;
              this.cameraId = _[0].deviceId;
            }
        this.joinClient();
      })
    } catch (error) {
      this.toastr.error("errore nell'acquisizione video")
    }
  }

加入客户

 joinClient() {

        this.agoraService.client.join(null, this.dossierId, null, (uid) => {
          this.streamSpec = { streamID: uid, audio: true, cameraId: this.cameraId, microphoneId: null, video: true, screen: false }
          this.localStream = this.agoraService.createStream(this.streamSpec);
          this.localStream.setVideoProfile('720p_3');
          this.subscribeToStreams();
          this.callIsStarted = true;
        });
      }

当我从头开始拨打电话时,它在Android上也可以正常工作,但是当我切换电话时,它仅在Windows和MacO上工作

很明显,当我导航到“ videoperizia”时,我的组件将通过ngOnDestroy:

  ngOnDestroy() {
    if (this.localStream) {
      this.localStream.stop();
      this.agoraService.client.unpublish(this.localStream);
    }    
    this.agoraService.client.leave();
  }

html:

<div id="agora_local_client" [style.height.px]="screenHeight" [style.width.px]="screenWidth" #clientVideo>  
</div>

然后在ts内使用@ViewChild:

 @ViewChild("clientVideo") clientVideo

0 个答案:

没有答案