CanvasCaptureMediaStreamTrack
方法
requestFrame()
requests that a frame be captured from the canvas and sent to the stream.
Applications that need to carefully control the timing of rendering and frame capture can use
requestFrame()
to directly specify when it's time to capture a frame.
To prevent automatic capture of frames, so that frames are only captured when
requestFrame()
is called, specify a value of 0 for the
captureStream()
method when creating the stream.
stream.requestFrame();
undefined
There is currently an issue flagged in the specification pointing out that at this time, no exceptions are being thrown if the canvas isn't origin-clean. This may change in the future, so it would be wise to plan ahead and watch for exceptions such as
SecurityError
(although the specific error that might be thrown is not mentioned in the spec, this is a likely candidate).
// Find the canvas element to capture
var canvasElt = document.getElementsByTagName("canvas")[0];
// Get the stream
var stream = canvasElt.captureStream(25); // 25 FPS
// Send the current state of the canvas as a frame to the stream
stream.getVideoTracks()[0].requestFrame();
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Capture from DOM Elements
The definition of 'CanvasCaptureMediaStream.requestFrame()' in that specification. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
requestFrame
|
Chrome 51 | Edge ≤79 | Firefox 41 | IE No | Opera No | Safari No | WebView Android 51 | Chrome Android 51 | Firefox Android ? | Opera Android No | Safari iOS No | Samsung Internet Android 5.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
用户必须明确启用此特征。
CanvasCaptureMediaStream
, the interface it belongs to.
<canvas>
CanvasCaptureMediaStreamTrack
requestFrame()
AudioStreamTrack
BlobEvent
CanvasCaptureMediaStream
ConstrainBoolean
ConstrainDOMString
ConstrainDouble
ConstrainLong
DoubleRange
HTMLCanvasElement.captureStream()
LongRange
MediaDevices
MediaStream
MediaStreamTrack
MediaStreamTrackEvent
MediaTrackCapabilities
MediaTrackConstraints
MediaTrackSettings
MediaTrackSupportedConstraints
Navigator.mediaDevices
NavigatorUserMedia
NavigatorUserMediaError
VideoStreamTrack
navigator.mediaDevices.getUserMedia()