Enable rear camera with HTML5

前端 未结 5 1709
失恋的感觉
失恋的感觉 2020-11-28 03:02

I\'m working on a project with MVC ASP.Net 4 HTML5 (default browser is google-chrome v29.0.1547.57) I can interact with these tools and take photographs but only with front

5条回答
  •  广开言路
    2020-11-28 03:08

    A demo can be found at https://webrtc.github.io/samples/src/content/devices/input-output/. This will allow access to both the front and rear camera.

    Many demos that you will find rely on the deprecated function:

    MediaStreamTrack.getSources() 
    

    As of Chrome 45 and FireFox 39, you will need to use the function:

    MediaDevices.enumerateDevices()
    

    Example:

    if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
      console.log("enumerateDevices() not supported.");
      return;
    }
    
    // List cameras and microphones.
    
    navigator.mediaDevices.enumerateDevices()
      .then(function(devices) {
        devices.forEach(function(device) {
          console.log(device.kind + ": " + device.label +
            " id = " + device.deviceId);
        });
      })
      .catch(function(e) {
        console.log(e.name + ": " + e.message);
      });

    Further documentation can be found here: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

提交回复
热议问题