Chromium浏览器中的内容设置(Content Settings in Chromium Browser)

[db:摘要]

Chromium浏览器中的内容设置(Content Settings in Chromium Browser)

有没有办法从命令行获取/设置Chromium浏览器中Mic / Camera的USB硬件ID?

我无法找到答案。 要求是在运行期间设置特定的摄像头/麦克风,而无需在铬浏览器中的chrome:// settings / content中手动更新。

如果我可以获得一些链接或一些示例代码,这将是非常好的。 谢谢 !!!

Is there a way to get/set the USB Hardware ID's for Mic/Camera in Chromium browser from the command line.

I could not able to find out. The requirement is to set a particular Camera/Mic during runtime without manually updating in chrome://settings/content in the chromium browser.

It will be great if I can get some link or some sample code. Thanks !!!

最满意答案

您可以使用--use-fake-ui-for-media-stream CLI标志禁止在有媒体流时显示权限对话框。 它会默认允许。

在选择具有CLI标记的特定麦克风或摄像头方面,我不相信这是可能的。 但是,您可以访问并选择要在JavaScript中使用的设备。

navigator.mediaDevices.enumerateDevices对象返回以下信息:

设备种类 - audioinput或videoinput 设备标签 - 例如内置麦克风,罗技bla,FaceTime高清摄像头等。 设备ID - 例如bd9759740e6c29df7703d0bfg62vbbc726fcb9422fdb948a35550835a840b328 设备组Id - 如果2+设备共享相同的物理设备,则它们可以具有组ID

Id是每个会话生成的,所以它不是我们可以硬编码的东西,但标签不太可能改变。 这意味着您可以遍历列表并获取与该字符串匹配的设备ID。 我用async / await做了这个,但是如果需要的话,你可以使用Promises或者transpile到ES5:

(async() => { const getFaceTimeCamId = async() => { try { const devices = await navigator.mediaDevices.enumerateDevices(); const faceTimeCam = devices.find(device => device.kind === 'videoinput' && device.label === 'FaceTime HD Camera'); return (faceTimeCam && faceTimeCam.deviceId) || undefined; } catch(err) { console.log(`${err.name}: ${err.message}`); } } console.log(await getFaceTimeCamId()); })();

然后,您可以为您的流设置约束对象,以包含所需的deviceId ,例如,在使用MediaDevices.getUserMedia 。

const constraints = { video: { deviceId: { exact: faceTimeCamId } } };

我还没有完全测试过,因为我手边没有另外的摄像头或麦克风,但希望这有些帮助。 我不知道你的确切用例,所以可能做了一些假设。

You can use the --use-fake-ui-for-media-stream CLI flag to suppress the permissions dialog from showing up when you have a media stream. It will allow by default.

In terms of selecting a particular microphone or camera with a CLI flag, I don't believe it's possible. However, you can access and select the device to be used in JavaScript.

The navigator.mediaDevices.enumerateDevices object returns the following information:

The device kind - audioinput or videoinput The device label - e.g. Built-in Microphone, Logitech bla, FaceTime HD Camera, etc. The device Id - e.g. bd9759740e6c29df7703d0bfg62vbbc726fcb9422fdb948a35550835a840b328 The device group Id - If 2+ devices share the same physical device, they can have group Id

The Id is generated per session, so it's not something we can hardcode, but the label is unlikely to change. This means you could traverse the list and get the device Id that matches the string. I did this with async/await but you can use Promises or transpile to ES5 if need be:

(async() => { const getFaceTimeCamId = async() => { try { const devices = await navigator.mediaDevices.enumerateDevices(); const faceTimeCam = devices.find(device => device.kind === 'videoinput' && device.label === 'FaceTime HD Camera'); return (faceTimeCam && faceTimeCam.deviceId) || undefined; } catch(err) { console.log(`${err.name}: ${err.message}`); } } console.log(await getFaceTimeCamId()); })();

You can then set the constraints object for your stream to include the deviceId you want, for example, when using MediaDevices.getUserMedia.

const constraints = { video: { deviceId: { exact: faceTimeCamId } } };

I've not fully tested this as I don't have another camera or mic at hand, but hopefully this is of some help. I don't know your exact use case so probably made some assumptions.

发布者:admin,转转请注明出处:http://www.yc00.com/web/1689407092a243023.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信