我是Angular 2的新手.
如果我有视频标签,例如:
<video width="480" height="480" autoplay></video>
Run Code Online (Sandbox Code Playgroud)
以及用于打开相机流的javascript示例代码段:
var video = document.getElementById('video');
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
});
}
Run Code Online (Sandbox Code Playgroud)
在Angular 2 + Typescript中,我想我可以访问视频标签,如:
@Component({
selector: 'video-component',
template: `
<video #videoplayer autoplay></video>
`
})
export class Video {
@ViewChild('videoplayer') videoPlayer;
ngAfterViewInit() {
let video = document.getElementById('video');
// How to access the mediadevice ??
}
}
Run Code Online (Sandbox Code Playgroud)
如何访问媒体设备并实例化流,如javascript片段中所示?