2

I'm trying to build a web app using Ionic2 and cordova ,for an augmented reality purpose. This code work but only the front camera work ! how can i activate the back camera ?

video = document.querySelector('video');
  canvas = document.querySelector('canvas');
  context = canvas.getContext("2d");
  //Canvas prendre les dimensions de la fenétre 
  //qu'il le contien
  canvas.width = parseInt(window.innerWidth);
  canvas.height = parseInt(window.innerHeight);

  function hasGetUserMedia() {
    return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
              navigator.mozGetUserMedia || navigator.msGetUserMedia);
  }
  if (hasGetUserMedia()) {

    function successCallback(stream){
      if (window.webkitURL) {
        video.src = window.webkitURL.createObjectURL(stream);
      } else if (video.mozSrcObject !== undefined) {
        video.mozSrcObject = stream;
      } else {
        video.src = stream;
      }
    }

    function errorCallback(error){
      //Rien a faire
    }
    //Qualité de la video HD(1280x720)
    navigator.getUserMedia({ video: { facingMode: { exact: "environment" } } },
                            successCallback,
                            errorCallback
                          );


    } else {
      alert('getUserMedia() is not supported in your device');
    }
}
elbo
  • 67
  • 1
  • 9
  • this might help you http://stackoverflow.com/questions/32086122/getusermedia-facingmode – Sarantis Tofas Feb 13 '17 at 18:47
  • Thanks but doesn't work. – elbo Mar 29 '17 at 22:39
  • any solution to this? I have the same problem. Facingmode doesn't change anything.. – N4ppeL Jun 08 '20 at 15:43
  • it's been a long time, I remember that my teammate found the solution, however I forgot how it is look like, here is the link of the project, it's contain the [solution](https://github.com/aghileschaouchi/pdp_ra), it would be nice if you can post it here. – elbo Jun 08 '20 at 21:09

0 Answers0