<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<video id="video" controls autoplay></video>
</body>
</html>
<script>
// getUserMedia 可以传其他参数
window.navigator.mediaDevices.getUserMedia({
audio:true, // 获取音频
video:{ // 获取视频 并设置宽高
width:400,
height:300
}
})
.then(mediaStream =>{
const oVideo = document.getElementById('video');
// 把媒体流放到 video 上
oVideo.srcObject = mediaStream;
})
</script>