首页 > 解决方案 > Navigator​.mediadevices.get​User​Media() 未访问笔记本电脑内置摄像头

问题描述

我正在开发一个用于视频录制的 Web 应用程序。

我已经尝试了下面的代码,但问题是它与外部摄像头一起工作正常,但在具有相同浏览器的笔记本电脑内置摄像头中,它没有给出对象发现错误。

我正在使用 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);
      });
    }

我希望应用程序能够在每个平台上运行。

标签: javascriptwebrtcrecordrtc

解决方案


您好所有开发人员感谢您的支持和快速响应。

我在代码中使用以下适配器添加修复了这些问题。

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

推荐阅读