HTMLVideoElement: cancelVideoFrameCallback() 方法
HTMLVideoElement 介面的 cancelVideoFrameCallback() 方法用於取消先前註冊的影片幀回撥。
語法
js
cancelVideoFrameCallback(id)
引數
id-
一個代表您要取消的影片幀回撥 ID 的數字。這將是相應
HTMLVideoElement.requestVideoFrameCallback呼叫返回的值。
返回值
無(undefined)。
示例
取消影片幀回撥
此示例展示瞭如何使用 cancelVideoFrameCallback() 來取消先前註冊的影片幀回撥。
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);
}
規範
| 規範 |
|---|
| HTMLVideoElement.requestVideoFrameCallback() # dom-htmlvideoelement-cancelvideoframecallback |
瀏覽器相容性
載入中…
另見
<video>元素HTMLVideoElement.requestVideoFrameCallback()- 使用
requestVideoFrameCallback()對影片執行高效的逐幀操作 (developer.chrome.com, 2023)