MediaTrackConstraints
dictionary's
cursor
特性为
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 simply ignore any constraints they're unfamiliar with.
var constraintsObject = { cursor: constraint };
constraintsObject.cursor = constraint;
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()
。见
How constraints are defined
in
Capabilities, constraints, and settings
for an explanation of how to define constraints.
You can check the setting selected by the user agent after the display media has been created by
getDisplayMedia()
通过调用
getSettings()
on the display media's video
MediaStreamTrack
, then checking the value of the returned
MediaTrackSettings
对象的
cursor
对象。
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.
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.
This example sets up the constraints to request that the cursor always be visible.
let displayMediaOptions = {
cursor: "always"
};
在此范例中,
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"]
};
This constraints object explicitly requires that the cursor not be rendered into the video track.
let displayMediaOptions = {
cursor: {
exact: "none"
}
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
Screen Capture
The definition of 'MediaTrackConstraints.cursor' in that specification. |
未知 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 |
完整支持
不支持
兼容性未知
MediaTrackConstraints
MediaDevices.getSupportedConstraints()
MediaTrackSupportedConstraints
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()