Chrome extension: Can't make chrome.desktopCapture.chooseDesktopMedia capture window audio

此生再无相见时 提交于 2021-02-08 05:48:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!