MediaStreamTrack.getConstraints() - Web APIs 编辑

The getConstraints() method of the MediaStreamTrack interface returns a MediaTrackConstraints object containing the set of constraints most recently established for the track using a prior call to applyConstraints(). These constraints indicate values and ranges of values that the Web site or application has specified are required or acceptable for the included constrainable properties.

Constraints can be used to ensure that the media meets certain guidelines you prefer. For example, you may prefer high definition video but require that the frame rate be a little low to help keep the data rate low enough not overtax the network. Constraints can also specify ideal and/or acceptable sizes or ranges of sizes. See Capabilities, constraints, and settings for details on how to work with constrainable properties.

Syntax

const constraints = track.getConstraints()

Return value

MediaTrackConstraints object which indicates the constrainable properties the Web site or app most recently set using applyConstraints(). The properties in the returned object are listed in the same order as when they were set, and only properties specifically set by the site or app are included.

Note: The returned set of constraints doesn't necessarily describe the actual state of the media. Even if any of the constraints couldn't be met, they are still included in the returned object as originally set by the site's code. To get the currently active settings for all constrainable properties, you should instead call getSettings().

Example

This example obtains the current constraints for a track, sets the facingMode, and applies the updated constraints.

function switchCameras(track, camera) {
  const constraints = track.getConstraints();
  constraints.facingMode = camera;
  track.applyConstraints(constraints);
}

Specifications

SpecificationStatusComment
Media Capture and Streams
The definition of 'getConstraints()' in that specification.
Candidate RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:108 次

字数:3657

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文