js实现获取本机的摄像头和麦克风的视频流和音频流并显示

很简单,几行代码,直接cv后Chrome浏览器打开即可查看效果,不过多赘述。

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
head>

<body>
    <video autoplay>video>
    <script>
        const video = document.querySelector('video');
        // 注意:navigator.getUserMedia语法已废弃,此处使用最新语法:navigator.mediaDevices.getUserMedia
        navigator.mediaDevices.getUserMedia({ audio: true, video: true })
            .then(stream => video.srcObject = stream)
            .catch(err => console.log(err));
    script>
body>

html>

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