Chrome扩展程序:无法制作chrome.desktopCapture.chooseDesktopMedia捕获窗口音频 [英] Chrome extension: Can't make chrome.desktopCapture.chooseDesktopMedia capture window audio
问题描述
我正在尝试使用 chrome.desktopCapture.chooseDesktopMedia
API来从扩展窗口捕获音频.
I'm trying to use the chrome.desktopCapture.chooseDesktopMedia
API in order to capture audio from the extension window.
我正在从popup.js页面发送捕获请求.
I'm sending the capture request from the popup.js page.
清单:
{
"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"
}
功能:
chrome.desktopCapture.chooseDesktopMedia(["window"], function (streamId) {
var audioStream = navigator.mediaDevices.getUserMedia({
audio: true,
chromeMediaSource: 'desktop',
chromeMediaSourceId: streamId
});
audioStream.then(function (mediaStream) {...}
我尝试使用不同的参数,但是每当忽略: audio:true
时,我都会得到:
I have tried using different parameters, but whenever I omit: audio:true
, I get :
无法在"MediaDevices"上执行"getUserMedia":至少一项必须请求音频和视频(…).
Failed to execute 'getUserMedia' on 'MediaDevices': At least one of audio and video must be requested(…).
以下代码未出现在API中,但我已经在此处阅读并尝试了它,先前的错误也适用于它:
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
}
}
当我确实使用 audio:true
时,即使我得到了源窗口选择对话框,它也会记录麦克风.
When I do use audio:true
, it records the mic, even though I get the source window selection dialog.
我做错了什么?
推荐答案
在对代码进行了一些试验之后,在我看来,捕获系统音频的唯一方法是通过video参数.我无法使用audio参数捕获非麦克风音频.屏幕录像机应用程序正在做同样的事情-系统音频是通过视频记录的.
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.
这篇关于Chrome扩展程序:无法制作chrome.desktopCapture.chooseDesktopMedia捕获窗口音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!