MediaTrackConstraints
dictionary's
facingMode
特性为
ConstrainDOMString
describing the requested or mandatory constraints placed upon the value of the
facingMode
constrainable property.
If needed, you can determine whether or not this constraint is supported by checking the value of
MediaTrackSupportedConstraints.facingMode
as returned by a call to
MediaDevices.getSupportedConstraints()
. However, typically this is unnecessary since browsers will simply ignore any constraints they're unfamiliar with.
因为
RTP
doesn't include this information, tracks associated with a
WebRTC
RTCPeerConnection
will never include this property.
var constraintsObject = { facingMode: constraint };
constraintsObject.facingMode = constraint;
An object based on
ConstrainDOMString
specifying one or more acceptable, ideal, and/or exact (mandatory) facing modes are acceptable for a video track.
An
exact
value in this case indicates that the specified facing mode is specifically required; for example:
var constraints = {
facingMode: { exact: "user" }
};
This indicates that only a user-facing camera is acceptable; if there is no user-facing camera, or the user declines permission to use that camera, the media request will fail.
The following strings are permitted values for the facing mode. These may represent separate cameras, or they may represent directions in which an adjustable camera can be pointed.
"user"
The video source is facing toward the user; this includes, for example, the front-facing camera on a smartphone.
"environment"
The video source is facing away from the user, thereby viewing their environment. This is the back camera on a smartphone.
"left"
The video source is facing toward the user but to their left, such as a camera aimed toward the user but over their left shoulder.
"right"
The video source is facing toward the user but to their right, such as a camera aimed toward the user but over their right shoulder.
见 Example: Constraint exerciser in Capabilities, constraints, and settings 范例。
| 规范 | 状态 | 注释 |
|---|---|---|
|
媒体捕获和流
The definition of 'facingMode' in that specification. |
候选推荐 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
facingMode
|
Chrome 59 | Edge ≤79 | Firefox 50 | IE No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 50 | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
不支持
兼容性未知
MediaTrackConstraints
MediaDevices.getSupportedConstraints()
MediaTrackSupportedConstraints
MediaStreamTrack
MediaTrackConstraints
AudioStreamTrack
BlobEvent
CanvasCaptureMediaStream
ConstrainBoolean
ConstrainDOMString
ConstrainDouble
ConstrainLong
DoubleRange
HTMLCanvasElement.captureStream()
LongRange
MediaDevices
MediaStream
MediaStreamTrack
MediaStreamTrackEvent
MediaTrackCapabilities
MediaTrackSettings
MediaTrackSupportedConstraints
Navigator.mediaDevices
NavigatorUserMedia
NavigatorUserMediaError
VideoStreamTrack
navigator.mediaDevices.getUserMedia()