简体   繁体   English

Chrome扩展程序麦克风捕获

[英]Chrome extension microphone capture

I have a browser_action extension where the user can press start and stop in order to capture some audio input. 我有一个browser_action扩展名,用户可以按startstop键来捕获一些音频输入。 After the file has been recorded I would like to dump its url in the console. 记录完文件后,我想将其URL转储到控制台中。 The problem is that I cannot get access to the microphone. 问题是我无法使用麦克风。 This is what I have tried so far: 到目前为止,这是我尝试过的:

navigator.webkitGetUserMedia - does not work, navigator.webkitGetUserMedia({ audio: true },...); navigator.webkitGetUserMedia不起作用, navigator.webkitGetUserMedia({ audio: true },...); calls the error callback with a MediaDeviceFailedDueToShutdown. 使用MediaDeviceFailedDueToShutdown调用错误回调。 I tried looking into that error but I found nothing useful about that. 我尝试调查该错误,但没有发现任何有用的信息。 That error is nowhere to be found. 找不到该错误。

Could you please guide me to the right path? 您能指导我走正确的道路吗? Thank you. 谢谢。

So it turns out that I have to get the user media from within an html page that is baked into the extension itself. 因此,事实证明,我必须从内置于扩展程序本身的html页面中获取用户媒体。 After the user has given access to the microphone, the background script of the extension also gets access to it. 用户授予对麦克风的访问权限后,扩展程序的后台脚本也将对其进行访问。

In my case, after installing I launch the welcome.html page where access is being requested: 就我而言,安装后,我启动了welcome.html页面,其中请求访问:

background.js

chrome.runtime.onInstalled.addListener((details) => {
    if (details.reason.search(/install/g) === -1) {
        return
    }
    chrome.tabs.create({
        url: chrome.extension.getURL("welcome.html"),
        active: true
    })
})

welcome.js

navigator.webkitGetUserMedia({ audio: true }, s => {...}, err => {...}

尝试将“ audioCapture”添加到manifest.json中的权限中:

"permissions": ["fullscreen", "audioCapture"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM