javascriptwebrtcrecordrtc

Navigator​.mediadevices.get​User​Media() not accessing the laptops inbuilt camera


I am developing a web application for video recording.

I have tried the below code but the problem is it working fine with a external camera, but in the laptops inbuilt camera with the same Browser it is giving no Object found error.

I am using Firefox 60.6.1

     if (navigator.mediaDevices.getUserMedia) {       
      navigator.mediaDevices.getUserMedia(constraints)
      .then(function(stream) {
    //load the stream in the video variable
        video.srcObject = stream;
    //load the stream in revokeAccess variable 
        revokeAccess=stream;
    //video playback
        video.play(); 
    /*
    Optional to avoid the dual audio disturbance. Playback audio is muted
    */
    video.muted= true;


    if (MediaRecorder.isTypeSupported('video/webm;codecs=vp9')) {
      var options = {mimeType: 'video/webm;codecs=vp9'};
      console.log("using vp9");
    } else if (MediaRecorder.isTypeSupported('video/webm;codecs=h264')) {
      var options = {mimeType: 'video/webm;codecs=h264'};
      console.log("using h264");
    } else  if (MediaRecorder.isTypeSupported('video/webm;codecs=vp8')) {
      var options = {mimeType: 'video/webm;codecs=vp8',videoBitsPerSecond : 1500000,audioBitsPerSecond : 160000};
      console.log("using vp8");
    }else{
    console.log('isTypeSupported is not supported, using default codecs for browser');
    } 

    //load the stream and type of video in the function
    mediaRecorder = new MediaRecorder(stream,options);
    //handle the data availability
    mediaRecorder.ondataavailable = handleDataAvailable;
    //Start the recording
    mediaRecorder.start(); 

    alert("Started Recording");


    //push the data into chunks(array)
    function handleDataAvailable(event) {
     if (event.data.size > 0) {
       recordedChunks.push(event.data);
        console.log(recordedChunks);
     } else {
      alert(event);
     }
    }
    //disable the Start Recording button
    document.getElementById("startRecording").disabled = true;  
      })
      .catch(function(error) {
    //handle the device not found exception
        alert("Camera not Found !! Please connect camera properly");
        console.log(error);
      });
    }

I want the application to be working in each platform.


Solution

  • Hi All Developers Thanks for your support and quick response.

    I fixed the issues using the below adapter addition in the code.

    var getUserMedia = navigator.getUserMedia ||
    navigator.mozGetUserMedia ||
    navigator.webkitGetUserMedia;