问题
I'm trying to use the chrome.desktopCapture.chooseDesktopMedia
API in order to capture audio from the extension window.
I'm sending the capture request from the popup.js page.
Manifest:
{
"background": {
"scripts": [ "background.js" ]
},
"browser_action": {
"default_icon": "style/icons/icon16.png",
"default_title": "__MSG_name__"
},
"default_locale": "en",
"description": "__MSG_description__",
"icons": {
"128": "style/icons/icon128.png"
},
"manifest_version": 2,
"name": "__MSG_extName__",
"permissions": ["activeTab","desktopCapture"],
"offline_enabled": true,
"short_name": "__MSG_short__",
"version": "1.0.9"
}
function:
chrome.desktopCapture.chooseDesktopMedia(["window"], function (streamId) {
var audioStream = navigator.mediaDevices.getUserMedia({
audio: true,
chromeMediaSource: 'desktop',
chromeMediaSourceId: streamId
});
audioStream.then(function (mediaStream) {...}
I have tried using different parameters, but whenever I omit: audio:true
, I get :
Failed to execute 'getUserMedia' on 'MediaDevices': At least one of audio and video must be requested(…).
The following code doesn't appear in the API, but I've read about it here and tried it, the previous error applies to it as well:
audio: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: streamId
}
}
When I do use audio:true
, it records the mic, even though I get the source window selection dialog.
What am I doing wrong?
回答1:
After experimenting with the code a bit, it seems to me like the only way to capture the system audio is through the video parameter. I wasn't able to capture a non-mic audio using the audio parameter. The screen recorder app is doing the same thing - system audio is recorded through the video.
来源:https://stackoverflow.com/questions/40686795/chrome-extension-cant-make-chrome-desktopcapture-choosedesktopmedia-capture-wi