zoukankan      html  css  js  c++  java
  • Web RTC录视频

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Document</title>
      <script>
        let recorder
        function start() {
          let videoTarget = document.getElementById('audio');
          // navigator.mediaDevices.getUserMedia({audio: true, video: { 400, height: 600}})
          //getDisplayMedia 录屏
          navigator.mediaDevices.getUserMedia({audio: true, video: { 400, height: 600}})
            .then((stream) => {
              recorder = new MediaRecorder(stream);
              console.log(recorder,'recorder');
              console.log(stream,'stream');
              
              videoTarget.srcObject = stream;
              videoTarget = (...arg) => {
                console.log(arg);
              }
              recorder.ondataavailable = (event) => {
                
                let url = URL.createObjectURL(event.data);
                let link = document.createElement("a");
                console.log(url,event,'event')
                window.location.href = url
                link.target = "_blank";
                link.href = url;
                link.click();
    
              }
              recorder.start();
            });
        }
    
        function stop() {
          console.log('结束录像');
          
          recorder.stop();
        }
      </script>
    </head>
    
    <body>
      <video id="audio" width="400" height="600" controls autoplay></video>
      <input onclick="start()" type="button" value="开始" />
      <input onclick="stop()" type="button" value="结束" />
    </body>
    
    </html>
    

     录完会返回一个blob对象,可通过 formdata上传给后台

  • 相关阅读:
    ORACLE查询删除重复记录三种方法
    是否可以从一个static方法内部发出对非static方法的调用
    协程(微线程)
    多线程、多进程
    python3.6.5修改print的颜色
    Python之时间和日期模块
    Python之字符(2)
    Python之字符
    python之列表
    Python中的文件操作
  • 原文地址:https://www.cnblogs.com/anxiaoyu/p/11824901.html
Copyright © 2011-2022 走看看