js 将摄像头录制播放成视频

第一步 创建 video 标签

第二步将浏览器视频媒体通道播放至video标签

			let constraints = {
				video: true,
				audio: false,
			};
			//获得video摄像头区域
			let video = document.getElementById("user-avatar");
			try {
				navigator.mediaDevices.getUserMedia(constraints)
					.then((stream) => {
						this.videoTrack = stream.getTracks()[0]
						video.srcObject = stream
						video.play()
					})
			} catch (e) {
				//TODO handle the exception
			}

你可能感兴趣的:(javascript,音视频,前端)