HTML版WebRTC,可本地运行。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebRTC</title>
</head>
<body>
<video autoplay playsinline></video>
<div>
<button id="capture">capture</button>
</div>
<div>
<canvas id="canvas"></canvas>
</div>
<div id="errorMessage"></div>
</body>
<script type="text/javascript">
var video = document.querySelector('video');
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
console.log("your browser doesn't support getUserMedia");
alert("your browser doesn't support getUserMedia");
} else {
var constraints = {
audio: true,
video: true
}
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream){
video.srcObject = stream;
})
.catch(function(err) {
console.log(err);
alert(err);
});
}
var capture = document.getElementById('capture');
var canvas = document.getElementById('canvas');
capture.onclick = function() {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
}
</script>
</html>
标签:capture,canvas,demo,video,getUserMedia,var,WebRTC
From: https://www.cnblogs.com/xzs603/p/17855581.html