我正在使用面向模式"约束来在两个摄像头之间切换,但我无法完全确定用户端是否有环境"摄像头(后置摄像头).仅计算 enumerateDevices 函数返回的承诺的视频输入"是不够的.
I'm using the 'facingMode' constrain in order to switch between the two cameras, but I'm not able to fully decided whether the user end has an 'environment' camera (back facing camera).. it's not enough to to count the 'videoinput' of the returned promise of enumerateDevices function.
我尝试搜索它,我发现的只是使用视频 MediaTrack 标签并搜索包含面向背面"的内容.字符串,在所有浏览器(例如 IOS)中似乎不是恒定的.
I tried searching for it and all I found was to use the video MediaTrack label and search for containing "facing back" string, which doesnt seem to be constant in all browsers (IOS for instance).
我相信一定有更好的方法:)
I'm sure there must be a better way :)
这里有第二个答案.选择前置 ( facesMode:'user'
) 和后置 (facingMode:'environment'
) 摄像头是我正在处理的问题.
A second answer here. The selection of front (facingMode:'user'
) and back (facingMode:'environment'
) cameras is an issue for something I'm working on.
如果您有一个打开的 .getUserMedia()
流到相机,则可以判断您正在使用哪个相机.stream.getTracks[0].getCapabilities()
返回一个带有 facingMode:'user'
或 facingMode:'environment'
字段的对象在里面.但是您必须已经为特定设备打开了一个流才能获得它.
It's possible to tell which camera you're using if you have an open .getUserMedia()
stream to a camera. stream.getTracks[0].getCapabilities()
gives back an object with either a facingMode:'user'
or facingMode:'environment'
field in it. But you already must have a stream open to the particular device to get this.
这是我在移动设备测试场中使用多个设备时发现的.这些是 .enumerateDevices()
产生的 device
条目的顺序.
Here's what I have discovered using multiple devices in a mobile-device test farm. These are the order of the device
entries yielded by .enumerateDevices()
.
tl;dr:在 iOs 设备上,前置摄像头是列表中的第一个视频输入设备,后置摄像头是第二个.在 Android 设备上,前置摄像头具有字符串front";在它们的 device.label
值中,后置摄像头或相机具有字符串back".
tl;dr: On iOs devices, the front facing camera is the first videoinput device in the list, and the back-facing camera is the second one. On Android devices, the front facing camera or cameras have the string "front" in their device.label
values and the back facing camra or cameras have the string "back".
device.label
项均已本地化为当前选择的国家语言.device.kind:'videoinput'
.这是我从我尝试过的每台 iOS 设备 auf Deutsch 中获得的设备标签列表:device.label
items are all localized to the currently selected national language.device.kind:'videoinput'
. Here is the list of devices labels I got from every iOS device I tried, auf Deutsch:
你可以告诉你什么时候在 iPhone 上
You can tell you’re on an iPhone when
navigator.userAgent.indexOf(' iPhone ') >= 0
你可以告诉你什么时候在 iPad 上
You can tell you’re on an iPad when
typeof navigator.maxTouchPoints === 'number'
&& navigator.maxTouchPoints > 2
&& typeof navigator.vendor === 'string'
&& navigator.vendor.indexOf('Apple') >= 0
请注意,iPad Safari 现在撒谎并声称它是英特尔 Mac.它显示了这个 User-Agent 字符串:
Notice that iPad Safari now lies and claims it's an Intel Mac. It presents this User-Agent string:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) 版本/14.0.1 Safari/605.1.15
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15
Android 设备:device.label"项未本地化.
我查看的设备有不同的 device.label 列表.但我发现的所有摄像头在 device.label 中都有字符串 front
或 back
.
The devices I looked at had different device.label lists. But the cameras I found all had either the string front
or back
in the device.label.
运行 Android 11 的 Pixel 3A 具有此设备列表.
A Pixel 3A running Android 11 has this list of devices.
运行 Android 9 的三星 SM-A205F 有这些设备.
A Samsung SM-A205F running Android 9 has these devices in order.
这个列举了两个不同的前置自拍相机.第一个提供比第二个更高的分辨率.
This one enumerates two different front-facing selfiecams. The first one offers higher resolution than the second one.
运行 Android 6.0.1 的三星 SM-G925I
A Samsung SM-G925I running Android 6.0.1
顺便说一下,.getSupportedConstraints()
的结果并没有多大帮助:iOS 和 Android 都给出 faceMode:true
.
And, by the way, the results of .getSupportedConstraints()
don't help much: both iOS and Android give facingMode:true
.
这篇关于getUserMedia 检测前置摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!