CanvasCaptureMediaStreamTrack.requestFrame() - Web APIs 编辑
The CanvasCaptureMediaStreamTrack
method 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.
Syntax
stream.requestFrame();
Return value
undefined
Usage notes
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).
Example
// 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();
Specifications
Specification | Status | Comment |
---|---|---|
Media Capture from DOM Elements The definition of 'CanvasCaptureMediaStream.requestFrame()' in that specification. | Working Draft | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
CanvasCaptureMediaStream
, the interface it belongs to.<canvas>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论