Chrome 为什么navigator.mediaDevices.enumerateDevices()返回不同的值?

ybzsozfc  于 2023-06-03  发布在  Go
关注(0)|答案(1)|浏览(388)

我试图在我的应用程序中使用navigator.mediaDevices.enumerateDevices(),但我在macOS上的Chrome浏览器(版本90.0.4430.212(官方版本)(x86_64))的其他选项卡中获得的值不同。
我有一个应用程序,其中值是正确的:

(6) [InputDeviceInfo, InputDeviceInfo, MediaDeviceInfo, MediaDeviceInfo, MediaDeviceInfo, MediaDeviceInfo]
0: InputDeviceInfo {deviceId: "default", kind: "audioinput", label: "Default - Internal Microphone (Built-in)", groupId: "c94bbcbb837464efa2be6befae9af57071548deadbaa65858734e6ec195b13e5"}
1: InputDeviceInfo {deviceId: "1cc1945e5003a2e0719d7dd5d8a608751d736931f5b4717779477b81de639cc7", kind: "audioinput", label: "Internal Microphone (Built-in)", groupId: "c94bbcbb837464efa2be6befae9af57071548deadbaa65858734e6ec195b13e5"}
2: MediaDeviceInfo {deviceId: "default", kind: "audiooutput", label: "Default - Headphones (Built-in)", groupId: "c94bbcbb837464efa2be6befae9af57071548deadbaa65858734e6ec195b13e5"}
3: MediaDeviceInfo {deviceId: "e7a1915585026f90deec4ec0c8f6b80e9501d024383f6b57e39b66459e84e16f", kind: "audiooutput", label: "Headphones (Built-in)", groupId: "c94bbcbb837464efa2be6befae9af57071548deadbaa65858734e6ec195b13e5"}
4: MediaDeviceInfo {deviceId: "4b226402572bc2af31811f5420c82ab7d28e957a2972e1505060cbdcd4f349c0", kind: "audiooutput", label: "DELL U2719D (DisplayPort)", groupId: "a4fbcbab8bae9811e123536d0ab9ea28a9179aed6439209ec74a08ba3b978da0"}
5: MediaDeviceInfo {deviceId: "c1e379faea073a3dc9e6ad3a69c2b7ef9e186b3faa1194f454cdc9ae1cb8aa80", kind: "audiooutput", label: "DELL U2719D (DisplayPort)", groupId: "7a20b5af20e078ebff0a2ee7d0412c9cce78be62378c22e492380ff201ac0a63"}

但是如果你切换到另一个域的另一个标签页(但使用我的应用程序的生产版本),甚至切换到chrome://newtab,我会得到:

0: InputDeviceInfo
deviceId: ""
groupId: "44b72fddafb7c5df78739a1b773a7842214a620402bca6537a545dd3e1df7424"
kind: "audioinput"
label: ""
__proto__: InputDeviceInfo
1: MediaDeviceInfo
deviceId: ""
groupId: "44b72fddafb7c5df78739a1b773a7842214a620402bca6537a545dd3e1df7424"
kind: "audiooutput"
label: ""

这种行为的原因是什么?我甚至没有使用这些设备,当我得到第二个结果时,我的应用程序的标签是关闭的。

oiopk7p5

oiopk7p51#

如果您看到一个空的deviceId,这意味着您没有授予它的权限。使用MediaDevices.getUserMedia()

相关问题