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.
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();
Specification | Status | Comment |
---|---|---|
Media Capture from DOM Elements The definition of 'CanvasCaptureMediaStream.requestFrame()' in that specification. | Working Draft | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | ? | ? | 41
|
No | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | ? | ? | ? | ? | ? |
CanvasCaptureMediaStream
, the interface it belongs to.<canvas>
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasCaptureMediaStreamTrack/requestFrame