大网数据广告活动
Web 标准与前端开发

媒体追踪约束

· 52CE 我爱测

The **`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 MediaStreamTrack.applyConstraints to allow a script to establish a set of exact (required) values or ranges and/o

媒体捕获与媒体流

The 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 MediaStreamTrack.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 MediaStreamTrack.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.

Properties

Some combination—but not necessarily all—of the following properties will exist on the object.

Properties of all media tracks

  • MediaTrackConstraints.deviceId
    • : A ConstrainDOMString object specifying a device ID or an array of device IDs which are acceptable and/or required.
  • MediaTrackConstraints.groupId
    • : A ConstrainDOMString object specifying a group ID or an array of group IDs which are acceptable and/or required.

Properties of audio tracks

  • MediaTrackConstraints.autoGainControl
    • : 一个 ConstrainBoolean 对象,用来指明是否首选或要求使用声音的自动增益。
  • MediaTrackConstraints.channelCount
    • : 一个 ConstrainLong,用来指明可选或要求的声道数或者是声道数的范围。
  • MediaTrackConstraints.echoCancellation
    • : 一个 ConstrainBoolean 对象,用来指明是否首选或需要开启回声消除。
  • MediaTrackConstraints.latency
    • : 一个 ConstrainDouble,用来指明多大延迟是被可接受的。
  • MediaTrackConstraints.noiseSuppression
    • : 一个 ConstrainBoolean,用来指明是否首选或需要开启降噪。
  • MediaTrackConstraints.sampleRate
    • : 一个 ConstrainLong,用来指明可接受的或要求的音频采样率/采样率范围。
  • MediaTrackConstraints.sampleSize
    • : 一个 ConstrainLong,用来指明可接受的或要求的音频采样大小/采样范围。
  • MediaTrackConstraints.volume
    • : 一个 ConstrainDouble,用来指明可接受的或要求的音量大小/范围。

Properties of image tracks

  • MediaTrackConstraints.whiteBalanceMode
    • : A String specifying one of "none", "manual", "sigle-shot", or "continuous".
  • MediaTrackConstraints.exposureMode
    • : A String specifying one of "none", "manual", "sigle-shot", or "continuous".
  • MediaTrackConstraints.focusMode
    • : A String specifying one of "none", "manual", "sigle-shot", or "continuous".
  • MediaTrackConstraints.pointsOfInterest
    • : The pixel coordinates on the sensor of one or more points of interest. This is either an object in the form { x:value, y:value } or an array of such objects, where value is a double-precision integer.
  • MediaTrackConstraints.expsureCompensation
    • : A ConstrainDouble (a double-precision integer) specifying f-stop adjustment by up to ±3.
  • MediaTrackConstraints.colorTemperature
    • : A ConstrainDouble (a double-precision integer) specifying a desired color temperature in degrees kelvin.
  • MediaTrackConstraints.iso
    • : A ConstrainDouble (a double-precision integer) specifying a desired iso setting.
  • MediaTrackConstraints.brightness
    • : A ConstrainDouble (a double-precision integer) specifying a desired brightness setting.
  • MediaTrackConstraints.contrast
    • : A ConstrainDouble (a double-precision integer) specifying the degree of difference between light and dark.
  • MediaTrackConstraints.saturation
    • : A ConstrainDouble (a double-precision integer) specifying the degree of color intensity.
  • MediaTrackConstraints.sharpness
    • : A ConstrainDouble (a double-precision integer) specifying the intensity of edges.
  • MediaTrackConstraints.focusDistance
    • : A ConstrainDouble (a double-precision integer) specifying distance to a focused object.
  • MediaTrackConstraints.zoom
    • : A ConstrainDouble (a double-precision integer) specifying the desired focal length.
  • MediaTrackConstraints.torch
    • : A Boolean whter the fill light continuously connected, meaning it stays on as long as the track is active.

Properties of video tracks

  • MediaTrackConstraints.aspectRatio
    • : A ConstrainDouble specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.
  • MediaTrackConstraints.facingMode
    • : A ConstrainDOMString object specifying a facing or an array of facings which are acceptable and/or required.
  • MediaTrackConstraints.frameRate
    • : A ConstrainDouble specifying the frame rate or range of frame rates which are acceptable and/or required.
  • MediaTrackConstraints.height
    • : A ConstrainLong specifying the video height or range of heights which are acceptable and/or required.
  • MediaTrackConstraints.width
    • : A ConstrainLong specifying the video width or range of widths which are acceptable and/or required.

Specifications

Browser compatibility

See also

  • MediaDevices.getUserMedia()
  • MediaStreamTrack.getConstraints()
  • MediaStreamTrack.applyConstraints()
  • MediaDevices.getSupportedConstraints()
  • MediaTrackSupportedConstraints
  • MediaStreamTrack.getSettings()

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。