Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

How to determine which cameras are front and back facing when using HTML5 getUserMedia and enumerateDevices APIs?

When accessing the camera using HTML5 getUserMedia APIs, you can either:

  1. Request an unspecified "user" facing camera
  2. Request an unspecified "environment" facing camera (optionally left or right)
  3. Request a list of cameras available

Originally we used the "facing" constraint to choose the camera. If the camera faces the "user" we show it mirror image as is the convention.

We run into problems, however, when a user does not have exactly 1 user-facing and 1 environment-facing camera. They might be missing one of these, or have multiple. This can result in the wrong camera being used, or the camera not being mirrored appropriately.

So we are looking at enumerating the devices. However, I have not found a way to determine whether a video device is "user facing" and should be mirrored.

Is there any API available to determine whether a video input is "user" facing the in these APIs?

question from:https://stackoverflow.com/questions/65931096/how-to-determine-which-cameras-are-front-and-back-facing-when-using-html5-getuse

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you enumerate devices, devices that are an input may have a method called getCapabilities(). If this method is available you may call it to get a MediaTrackCapabilities object. This object has a field called facingMode which lists the valid facingMode options for that device.

For me this was empty on the PC but on my Android device it populated correctly.

Here's a jsfiddle you can use to check this on your own devices: https://jsfiddle.net/juk61c07/4/

Thanks to the comment from O. Jones for setting me in the right direction.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...