WEBRTC DEMO1:通过浏览器显示摄像头视频

  1. 通过浏览器显示摄像头视频DEMO说明

    我们通过一个简单的HTML+JavaScript网页来使用getUserMeida() API,通过这个网页访问本地摄像头并显示本地视频到网页之中。

getUserMedia.html:

  
  
  
  
getUserMedia very simple demo  
   
  
  

getUserMedia() very simple demo

With this example, we simply call getUserMedia() and display the received stream inside an HTML5

View page source to access both HTML and javascript code...

getUserMedia.js:

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;  
  
var constraints = {audio: false, video: true};  
var video = document.querySelector("video");  
  
function successCallback(stream) {  
  window.stream = stream; // make the returned stream available to console...  
  if (window.URL) {  
    video.src = window.URL.createObjectURL(stream);  
  } else {  
    video.src = stream;  
  }  
  video.play();  
}  
  
function errorCallback(error){  
  console.log("navigator.getUserMedia error: ", error);  
}  
  
navigator.getUserMedia(constraints, successCallback, errorCallback);

使用firefox浏览器(版本号:58.0.2;时间:2018.02)打开getUserMedia.html:

WEBRTC DEMO1:通过浏览器显示摄像头视频_第1张图片

点击“允许“打开摄像头:

WEBRTC DEMO1:通过浏览器显示摄像头视频_第2张图片

完整原代码下载地址:https://download.csdn.net/download/paolochristian/10280794


2. 遗留问题

(1)发现存在摄像头视频卡顿问题,后面分析原因及给出解决方法。


转载博文:http://blog.csdn.net/yamingwu/article/details/44628145

你可能感兴趣的:(WEBRTC)