Access camera from a browser

前端 未结 6 1988
悲&欢浪女
悲&欢浪女 2020-11-30 02:38

Is it possible to access the camera (built-in on Apples) from a browser?

Optimal solution would be client-side javascript. Looking to avoid using Java or Flash.

相关标签:
6条回答
  • 2020-11-30 02:44

    You can use HTML5 for this:

    <video autoplay></video>
    <script>
      var onFailSoHard = function(e) {
        console.log('Reeeejected!', e);
      };
    
      // Not showing vendor prefixes.
      navigator.getUserMedia({video: true, audio: true}, function(localMediaStream) {
        var video = document.querySelector('video');
        video.src = window.URL.createObjectURL(localMediaStream);
    
        // Note: onloadedmetadata doesn't fire in Chrome when using it with getUserMedia.
        // See crbug.com/110938.
        video.onloadedmetadata = function(e) {
          // Ready to go. Do some stuff.
        };
      }, onFailSoHard);
    </script>
    

    Source

    0 讨论(0)
  • 2020-11-30 02:47

    There is a really cool solution from Danny Markov for that. It uses navigator.getUserMedia method and should work in modern browsers. I have tested it successfully with Firefox and Chrome. IE didn't work:

    Here is a demo:

    https://tutorialzine.github.io/pwa-photobooth/

    Link to Danny Markovs description page:

    http://tutorialzine.com/2016/09/everything-you-should-know-about-progressive-web-apps/

    Link to GitHub:

    https://github.com/tutorialzine/pwa-photobooth/

    0 讨论(0)
  • 2020-11-30 02:49

    The HTML5 spec does allow accessing the webcamera, but last I checked, it is far from finalized, and has very, very little browser support.

    This is a link to get you started: http://www.html5rocks.com/en/tutorials/getusermedia/intro/

    You'll probably have to use flash if you want it to work cross-browser.

    W3 draft

    0 讨论(0)
  • 2020-11-30 03:02

    Video Tutorial: Accessing the Camera with HTML5 & appMobi API will be helpful for you.

    Also, you may try the getUserMedia method (supported by Opera 12)

    enter image description here

    0 讨论(0)
  • 2020-11-30 03:05

    As of 2017, WebKit announces support for WebRTC on Safari

    Now you can access them with video and standard javascript WebRTC

    E.g.

    var video = document.createElement('video');
    video.setAttribute('playsinline', '');
    video.setAttribute('autoplay', '');
    video.setAttribute('muted', '');
    video.style.width = '200px';
    video.style.height = '200px';
    
    /* Setting up the constraint */
    var facingMode = "user"; // Can be 'user' or 'environment' to access back or front camera (NEAT!)
    var constraints = {
      audio: false,
      video: {
       facingMode: facingMode
      }
    };
    
    /* Stream it to video element */
    navigator.mediaDevices.getUserMedia(constraints).then(function success(stream) {
      video.srcObject = stream;
    });
    

    Have a play with it.

    0 讨论(0)
  • 2020-11-30 03:06

    Possible with HTML5.

    http://www.html5rocks.com/en/tutorials/getusermedia/intro/

    0 讨论(0)
提交回复
热议问题