zoukankan      html  css  js  c++  java
  • WEBRTC 01

    1.获取本地媒体

    'use strict';
    
    const constraints = window.constraints = {
      audio: false,
      video: true
    };
    
    function handleSuccess(stream) {
      const video = document.querySelector('video');
      window.stream = stream; 
      video.srcObject = stream;
    }
    
    function handleError(error) {
        console.log("error")
    }
    
    async function init(e) {
      try {
        const stream = await navigator.mediaDevices.getUserMedia(constraints);
        handleSuccess(stream);
        e.target.disabled = true;
      } catch (e) {
        handleError(e);
      }
    }
    
    document.querySelector('#showVideo').addEventListener('click', e => init(e));
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>webrtcdemo</title>
        </head>
        <body>
            <div>
                <h1>获取网络摄像头</h1>
                <video autoplay playsinline></video>
                <button id="showVideo">Open camera</button>
            </div>
            <script src="./js/main.js"></script>
        </body>
    </html>

    测试:

  • 相关阅读:
    [转载]我的WafBypass之道(Misc篇)
    7.3 使用while 循环来处理列表和字典
    7-4__7-7练习
    7.2 while 循环
    第 7 章 用户输入和while 循环
    6.字典练习
    6.4 嵌套
    6.3 遍历字典
    6.2练习
    第 6 章 字典
  • 原文地址:https://www.cnblogs.com/setout/p/14037599.html
Copyright © 2011-2022 走看看