HTMLVideoElement: cancelVideoFrameCallback() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("HTML DOM")}}
The **cancelVideoFrameCallback()** method of the {{domxref("HTMLVideoElement")}} interface cancels a previously-registered video frame callback.
Syntax
js-nolint
cancelVideoFrameCallback(id)Parameters
id- : A number representing the ID of the video frame callback you want to cancel. This will be the value returned by the corresponding {{DOMxRef("HTMLVideoElement.requestVideoFrameCallback")}} call.
Return value
None ({{jsxref("undefined")}}).
Examples
Canceling a video frame callback
This example shows how to use cancelVideoFrameCallback() to cancel a previously-registered video frame callback.
js
let videoCallbackId = null;
function updateCanvas(now, metadata) {
// Do something with the frame
// …
// Re-register the callback to run on the next frame
// It's important to update the videoCallbackId on each iteration
// so you can cancel the callback successfully
videoCallbackId = video.requestVideoFrameCallback(updateCanvas);
}
// Initial registration of the callback to run on the first frame
videoCallbackId = video.requestVideoFrameCallback(updateCanvas);
// …
// Cancel video frame callback using the latest videoCallbackId
if (videoCallbackId !== null) {
video.cancelVideoFrameCallback(videoCallbackId);
}Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- The {{HTMLElement("video")}} element
- {{DOMxRef("HTMLVideoElement.requestVideoFrameCallback()")}}
- [Perform efficient per-video-frame operations on video with
requestVideoFrameCallback()](https://web.dev/articles/requestvideoframecallback-rvfc) on developer.chrome.com (2023)