angular camera directive

阅读更多
import { Directive, ElementRef, Renderer } from '@angular/core';
@Directive({
    selector: '[camera]'
})
export class CameraDirective {
    private video: HTMLVideoElement;
    constructor(private elem: ElementRef, private renderer: Renderer) {
        this.video = elem.nativeElement;
        // renderer.setElementStyle(video, 'backgroundColor', 'red');
}
    public ngAfterViewInit() {
        if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia({ video: true })
                .then((stream) => {
                    this.video.src = window.URL.createObjectURL(stream);
                    this.video.play();
                });
        }

    }
}

你可能感兴趣的:(angular camera directive)