Angular 2 and instantiation of a camera stream with html 5 video

前端 未结 1 891
离开以前
离开以前 2021-02-11 02:41

I\'m new to Angular 2.

If I have a video tag, like :

    

And a javas

1条回答
  •  醉酒成梦
    2021-02-11 03:10

    In your template you can include the video directive like this:

    
    

    then in your component:

    @ViewChild('video') video:any; 
    // note that "#video" is the name of the template variable in the video element
    
    ngAfterViewInit() {
      let _video=this.video.nativeElement;
      if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
        navigator.mediaDevices.getUserMedia({ video: true })
                              .then(stream => {
                                _video.src = window.URL.createObjectURL(stream);
                                _video.play();
                              })
      }
    }
    

    see this on stackblitz: https://stackblitz.com/edit/live-video

    0 讨论(0)
提交回复
热议问题