Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何启用浏览器以访问摄像头?_Javascript_Css_Html - Fatal编程技术网

Javascript 如何启用浏览器以访问摄像头?

Javascript 如何启用浏览器以访问摄像头?,javascript,css,html,Javascript,Css,Html,嗨,目前我正在使用Chrome浏览器的摄像头API。但我的浏览器不支持navigation.getUserMedia 嗨,分享一些代码 这是我的HTML页面: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>getUserMedi</title> <link rel="stylesheet" href="style.css"&g

嗨,目前我正在使用Chrome浏览器的摄像头API。但我的浏览器不支持navigation.getUserMedia

嗨,分享一些代码

这是我的HTML页面:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>getUserMedi</title>
<link rel="stylesheet" href="style.css">
 </head>
 <body>
 <div id="video-container">
  <video id="camera-stream" width="500" autoplay></video>
  </div>
  <script src="camera.js">
  </script>
  </body>
  </html>
这里是camera.js文件:

    window.onload = function() {

    // Normalize the various vendor prefixed versions of getUserMedia.
   navigator.getUserMedia = (navigator.getUserMedia ||
   navigator.webkitGetUserMedia ||
   navigator.mozGetUserMedia || 
   navigator.msGetUserMedia);

   if (navigator.getUserMedia) {
  // Request the camera.
   navigator.getUserMedia(
    // Constraints
    {
    video: true
    },

    // Success Callback
    function(localMediaStream) {
     // Get a reference to the video element on the page.
    var vid = document.getElementById('camera-stream');

    // Create an object URL for the video stream and use this 
    // to set the video source.
    vid.src = window.URL.createObjectURL(localMediaStream);
                 },

         // Error Callback
    function(err) {
    // Log the error to the console.
    console.log('The following error occurred when trying to use  
     getUserMedia: ' + err);           
              }
           );

        } else {
        alert('Sorry, your browser does not support getUserMedia');
            }
            };

这里我的相机无法打开。浏览器也不支持,请澄清这家伙的问题。

首先,
导航。getUserMedia已被弃用,大多数浏览器不再支持它

Mozilla.org网站上推荐的新API是
navigator.mediaDevices.getUserMedia

请通过下面的URL阅读更多内容


首先,
导航.getUserMedia
已被弃用,大多数浏览器不再支持它

Mozilla.org网站上推荐的新API是
navigator.mediaDevices.getUserMedia

请通过下面的URL阅读更多内容


这正按预期工作。我只需要删除错误回调函数中控制台日志中的换行符。刚刚看到
getUserMedia()
不再适用于不安全的源代码。看一看就知道了。所以,也许这就是为什么我删除了chrome中不安全的origin.jsfiddle–DavidDomain,但我没有得到接受的输出。你得到了什么错误?你能给出一些可能的答案吗?这是预期的工作。我只需要删除错误回调函数中控制台日志中的换行符。刚刚看到
getUserMedia()
不再适用于不安全的源代码。看一看就知道了。所以,也许这就是为什么我删除了chrome中不安全的origin.jsfiddle–DavidDomain,但是我没有得到接受的输出。你得到了什么错误?你能给出一些可能的答案吗。
    window.onload = function() {

    // Normalize the various vendor prefixed versions of getUserMedia.
   navigator.getUserMedia = (navigator.getUserMedia ||
   navigator.webkitGetUserMedia ||
   navigator.mozGetUserMedia || 
   navigator.msGetUserMedia);

   if (navigator.getUserMedia) {
  // Request the camera.
   navigator.getUserMedia(
    // Constraints
    {
    video: true
    },

    // Success Callback
    function(localMediaStream) {
     // Get a reference to the video element on the page.
    var vid = document.getElementById('camera-stream');

    // Create an object URL for the video stream and use this 
    // to set the video source.
    vid.src = window.URL.createObjectURL(localMediaStream);
                 },

         // Error Callback
    function(err) {
    // Log the error to the console.
    console.log('The following error occurred when trying to use  
     getUserMedia: ' + err);           
              }
           );

        } else {
        alert('Sorry, your browser does not support getUserMedia');
            }
            };