getUserMedia throw error NavigatorUserMediaError:InvalidStateError

时间:2017-06-16 03:42:15

标签: google-chrome-extension getusermedia

我从desktopCapture.chooseDesktopMedia Api获得streamId但是getUserMedia失败

navigator.mediaDevices.getUserMedia({
    audio: {
      mandatory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: streamId
      }
    },
    video: {
      mandatory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: streamId,
        maxWidth: window.screen.width,
        maxHeight: window.screen.height
      }
    }
  }).then(function(stream) {

    }).catch(function(err) {
       // The error show here
     console.log(err)
    });

由于

1 个答案:

答案 0 :(得分:0)

as,navigator.mediaDevices.getUserMedia会给你一个承诺。所以,你必须像承诺一样使用它。你的功能应该是这样的。

var obj = {
    audio: {
      mandatory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: streamId
      }
    },
    video: {
      mandatory: {
        chromeMediaSource: 'desktop',
        chromeMediaSourceId: streamId,
        maxWidth: window.screen.width,
        maxHeight: window.screen.height
      }
    }
  };

window.navigator.mediaDevices.getUserMedia(obj).then(function(stream) {
    // Do your work with the stream
}).catch(function(err) {
   // Your error show here.
 console.log(err)
});

有关详细信息,请点击此处 - > Check it out希望有所帮助