MediaTrackConstraints.cursor - Web APIs 编辑

The MediaTrackConstraints dictionary's cursor property is a ConstrainDOMString describing the requested or mandatory constraints placed upon the value of the cursor constrainable property, which is used to specify whether or not the cursor should be included in the captured video.

If needed, you can determine whether or not this constraint is supported by checking the value of MediaTrackSupportedConstraints.cursor as returned by a call to MediaDevices.getSupportedConstraints(). However, typically this is unnecessary since browsers will ignore any constraints they're unfamiliar with.

Syntax

var constraintsObject = { cursor: constraint };

constraintsObject.cursor = constraint;

Value

A ConstrainDOMString which specifies whether or not the mouse cursor should be rendered into the video track in the MediaStream returned by the call to getDisplayMedia(). See How constraints are defined in Capabilities, constraints, and settings for an explanation of how to define constraints.

Usage notes

You can check the setting selected by the user agent after the display media has been created by getDisplayMedia() by calling getSettings() on the display media's video MediaStreamTrack, then checking the value of  the returned MediaTrackSettings object's cursor object.

For example, if your app needs to alter the stream by inserting a representation of the cursor position if the stream doesn't include the rendered cursor, you can determine the need to do so by using code like this:

let insertFakeCursorFlag = false;

if (displayStream.getVideoTracks()[0].getSettings().cursor === "never") {
  insertFakeCursorFlag = true;
}

Following this code, insertFakeCursorFlag is true if there's no cursor rendered into the stream already. Later code can detect this flag's value and if it's true, can manually look at some metadata that might be provided and insert a fake representation of the cursor at the correct position.

Examples

Here are some example constraints objects for getDisplayMedia() that make use of the cursor property. In addition, see Example: Constraint exerciser in Capabilities, constraints, and settings for a complete example showing how constraints are used.

Example: Cursor always visible

This example sets up the constraints to request that the cursor always be visible.

let displayMediaOptions = {
  cursor: "always"
};

Example: Cursor visible during motion with fallback

In this example, the cursor property is configured to request that the cursor be visible when in motion, falling back to always being visible if the user agent doesn't support in-motion only cursor rendering.

let displayMediaOptions = {
  cursor: ["motion", "always"]
};

Example: Require that the cursor not be visible

This constraints object explicitly requires that the cursor not be rendered into the video track.

let displayMediaOptions = {
  cursor: {
    exact: "none"
  }
};

Specifications

SpecificationStatusComment
Screen Capture
The definition of 'MediaTrackConstraints.cursor' in that specification.
UnknownInitial specification.

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:92 次

字数:7172

最后编辑:6 年前

编辑次数:0 次

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