MediaTrackConstraints
dictionary is used to describe a set of capabilities and the value or values each can take on. A constraints dictionary is passed into
applyConstraints()
to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling
getConstraints()
.
For each constraint, you can typically specify an exact value you need, an ideal value you want, a range of acceptable values, and/or a value which you'd like to be as close to as possible. The specifics vary somewhat depending on the type of the constrainable property.
To learn more about how constraints work, see Capabilities, constraints, and settings .
Some combination—but not necessarily all—of the following properties will exist on the object. This may be because a given browser doesn't support the property, or because it doesn't apply. For example, because
RTP
doesn't provide some of these values during negotiation of a WebRTC connection, a track associated with a
RTCPeerConnection
will not include certain values, such as
facingMode
or
groupId
.
deviceId
ConstrainDOMString
object specifying a device ID or an array of device IDs which are acceptable and/or required.
groupId
ConstrainDOMString
object specifying a group ID or an array of group IDs which are acceptable and/or required.
autoGainControl
ConstrainBoolean
object which specifies whether automatic gain control is preferred and/or required.
channelCount
ConstrainLong
specifying the channel count or range of channel counts which are acceptable and/or required.
echoCancellation
ConstrainBoolean
object specifying whether or not echo cancellation is preferred and/or required.
latency
ConstrainDouble
specifying the latency or range of latencies which are acceptable and/or required.
noiseSuppression
ConstrainBoolean
which specifies whether noise suppression is preferred and/or required.
sampleRate
ConstrainLong
specifying the sample rate or range of sample rates which are acceptable and/or required.
sampleSize
ConstrainLong
specifying the sample size or range of sample sizes which are acceptable and/or required.
volume
ConstrainDouble
specifying the volume or range of volumes which are acceptable and/or required.
whiteBalanceMode
字符串
specifying one of
"none"
,
"manual"
,
"single-shot"
,或
"continuous"
.
exposureMode
字符串
specifying one of
"none"
,
"manual"
,
"single-shot"
,或
"continuous"
.
focusMode
字符串
specifying one of
"none"
,
"manual"
,
"single-shot"
,或
"continuous"
.
pointsOfInterest
exposureCompensation
ConstrainDouble
(a double-precision integer) specifying f-stop adjustment by up to ±3.
colorTemperature
ConstrainDouble
(a double-precision integer) specifying a desired color temperature in degrees kelvin.
iso
ConstrainDouble
(a double-precision integer) specifying a desired iso setting.
brightness
ConstrainDouble
(a double-precision integer) specifying a desired brightness setting.
contrast
ConstrainDouble
(a double-precision integer) specifying the degree of difference between light and dark.
saturation
ConstrainDouble
(a double-precision integer) specifying the degree of color intensity.
sharpness
ConstrainDouble
(a double-precision integer) specifying the intensity of edges.
focusDistance
ConstrainDouble
(a double-precision integer) specifying distance to a focused object.
zoom
ConstrainDouble
(a double-precision integer) specifying the desired focal length.
torch
布尔
defining whether the fill light is continuously connected, meaning it stays on as long as the track is active.
aspectRatio
ConstrainDouble
specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.
facingMode
ConstrainDOMString
object specifying a facing or an array of facings which are acceptable and/or required.
frameRate
ConstrainDouble
specifying the frame rate or range of frame rates which are acceptable and/or required.
height
ConstrainLong
specifying the video height or range of heights which are acceptable and/or required.
width
ConstrainLong
specifying the video width or range of widths which are acceptable and/or required.
resizeMode
ConstrainDOMString
object specifying a mode or an array of modes the UA can use to derive the resolution of a video track. Allowed values are
none
and
crop-and-scale
.
none
means that the user agent uses the resolution provided by the camera, its driver or the OS.
crop-and-scale
means that the user agent can use cropping and downscaling on the camera output in order to satisfy other constraints that affect the resolution.
These constraints apply to
MediaTrackConstraints
objects specified as part of the
DisplayMediaStreamConstraints
对象的
视频
property when using
getDisplayMedia()
to obtain a stream for screen sharing.
cursor
A
ConstrainDOMString
which specifies whether or not to include the mouse cursor in the generated track, and if so, whether or not to hide it while not moving. The value may be a single one of the following strings, or an array of them to allow the browser flexibility in deciding what to do about the cursor.
always
The mouse is always visible in the video content of the {domxref("MediaStream"), unless the mouse has moved outside the area of the content.
motion
The mouse cursor is always included in the video if it's moving, and for a short time after it stops moving.
never
The mouse cursor is never included in the shared video.
displaySurface
A
ConstrainDOMString
which specifies the types of display surface that may be selected by the user. This may be a single one of the following strings, or a list of them to allow multiple source surfaces:
application
The stream contains all of the windows of the application chosen by the user rendered into the one video track.
浏览器
The stream contains the contents of a single browser tab selected by the user.
monitor
The stream's video track contains the entire contents of one or more of the user's screens.
window
The stream contains a single window selected by the user for sharing.
logicalSurface
ConstrainBoolean
value which may contain a single Boolean value or a set of them, indicating whether or not to allow the user to choose source surfaces which do not directly correspond to display areas. These may include backing buffers for windows to allow capture of window contents that are hidden by other windows in front of them, or buffers containing larger documents that need to be scrolled through to see the entire contents in their windows.
| 规范 | 状态 | 注释 |
|---|---|---|
| 媒体捕获和流 | 候选推荐 | 初始定义。 |
| MediaStream 图像捕获 | 工作草案 | Adds image constraints. |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MediaTrackConstraints
|
Chrome 59 | Edge ≤18 | Firefox Yes | IE ? | Opera 46 | Safari ? | WebView Android 59 | Chrome Android Yes | Firefox Android Yes | Opera Android 43 | Safari iOS ? | Samsung Internet Android Yes |
aspectRatio
|
Chrome 59 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 29 | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
autoGainControl
|
Chrome Yes | Edge ≤79 |
Firefox
55
|
IE 不支持 No | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes |
Firefox Android
55
|
Opera Android ? | Safari iOS ? | Samsung Internet Android Yes |
channelCount
|
Chrome 59 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
cursor
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 不支持 No |
deviceId
|
Chrome 59 | Edge ≤79 |
Firefox
36
注意事项
|
IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 |
Firefox Android
36
注意事项
|
Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
displaySurface
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 不支持 No |
echoCancellation
|
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 |
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 |
frameRate
|
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 |
groupId
|
Chrome 59 | Edge ≤79 | Firefox 70 | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
height
|
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 |
latency
|
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 |
logicalSurface
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 不支持 No |
noiseSuppression
|
Chrome Yes | Edge ≤79 |
Firefox
55
|
IE 不支持 No | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes |
Firefox Android
55
|
Opera Android ? | Safari iOS ? | Samsung Internet Android Yes |
sampleRate
|
Chrome 59 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
sampleSize
|
Chrome 59 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
volume
弃用
非标
|
Chrome 59 | Edge ≤79 | Firefox 不支持 No | IE 不支持 No | Opera Yes | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android 不支持 No | Opera Android ? | Safari iOS ? | Samsung Internet Android 7.0 |
width
|
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 |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
要求使用供应商前缀或不同名称。
MediaDevices.getUserMedia()
MediaStreamTrack.getConstraints()
MediaStreamTrack.applyConstraints()
MediaDevices.getSupportedConstraints()
MediaTrackSupportedConstraints
MediaStreamTrack.getSettings()
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()