简体   繁体   中英

how can i solve html5_webcam problem on the website?

there is a problem about html5 webcam this is the error i have Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided. at photo.js:17

photo.js :17 video.src=vendorUrl.createObjectURL(stream);

please check my code

thank you so much!

takeing_photo.html

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Document</title>
    <link href="{% static 'css/photo.css' %}" rel="stylesheet">
  </head>
  <body>

    <div class="booth">
      <video id="video" width="400" height="300"></video>
      <a href="#" id="capture" class="booth-capture-button">Take photo</a>
      <canvas id="canvas" width="400" height="300"></canvas>
      <img id="photo" src="http://placekitten.com/g/400/300" alt="photo of you">
    </div>
    <script src="{% static 'js/photo.js' %}"></script>
  </body>
</html>

photo.js

(function(){
  var video = document.getElementById('video'),
      photo = document.getElementById('photo'),
      context = canvas.getContext('2d'),
      phto = document.getElementById('photo');
      vendorUrl = window.URL || window.webkitURL;

  navigator.getMedia = navigator.getUserMedia ||
                       navigator.webkitGetUserMedia ||
                       navigator.mozGetUserMedia ||
                       navigator.msGetUserMedia;

  navigator.getMedia({
      video:true, 
      audio:false
  }, function(stream){
      video.src=vendorUrl.createObjectURL(stream);
      video.play();
  }, function(error){

  });
  document.getElementById('capture').addEventListener('click', function(){
      context.drawImage(video, 0, 0, 400, 300);
      photo.setAttribute('src', canvas.toDataURL('image/png'))
  });
})();

photo.css

.booth{
  width:400px;
  background-color: #ccc;
  border:10px solid #ddd;
  margin:0 auto;
}

.booth-capture-button {
  display:block;
  margin:10px 0;
  padding:10px 20px;
  background-color: cornflowerblue;
  color: #fff;
  text-align: center;
  text-decoration: none;
}

#canvas {
  display :none;
}

i just want to make webcam properly and im wondering there is a way to save the pics into the folder when i put the button "take of you"

please give me advice. thank you so much.

This error is caused because the function createObjectURL is deprecated. You need to update your code to set srcObject to the video object directly.

video.srcObject=stream;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM