• WebRTC中有哪些音视频采集的API


    基本格式

    var promise = navigator.medisDevices.getUserMedia(constraints);
    

    MediaStreamConstraints

    dictionary MediaStreamConstraints{
      (boolean or MediaTrackConstraints)video = false;
      (boolean or MediaTrackConstraints)audio = false;
    }
    

    实战案例

    vim index.html

    <html>
      <head>
        <title>WebRTC 获取视频和音频</title>
      </head>
      <body>
    
        <video autoplay playsinline id="player"></video>
        <script src="./js/client.js"></script>
      </body>
    </html>
    

    cd js

    vim client.js

    "use strict"
    
    var videoplay = document.querySelector("video#player");
    
    if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia){
      console.log("获取音视频方法不存在");
    }else{
      var constraints = {
        video : true,
        audio : true
      };
      
      navigator.mediaDevices.getUserMedia(constraints)
      	.then(gotMediaStream)
      	.catch(handleError);
    }
    
    function gotMediaStream(stream){
      // 复制流到video标签
      videoplay.srcObject = stream;
      
      
    }
    function handleError(err){
      console.log("错误啦:", err)
    }
    
  • 相关阅读:
    Servlet Class4
    Servlet Class3
    Servlet Class2
    Servlet Class1
    HTTP基础知识
    XML基础知识
    JAVA Class25
    JAVA Class24
    JAVA Class23
    JAVA Class22
  • 原文地址:https://www.cnblogs.com/fandx/p/12142296.html
Copyright © 2020-2023  润新知