取消渲染
warning
非常实验性的功能——随时可能出现漏洞和重大更改。
在 GitHub 上跟踪进度 并在 Discord 的 #web-renderer 通道中讨论。
renderMediaOnWeb() 和 renderStillOnWeb() 都通过 AbortSignal API 支持取消。
🌐 Both renderMediaOnWeb() and renderStillOnWeb() support cancellation via the AbortSignal API.
使用 AbortController
🌐 Using AbortController
创建一个 AbortController 并将其 signal 传递给渲染函数:
🌐 Create an AbortController and pass its signal to the render function:
Cancel after timeoutimport {renderMediaOnWeb } from '@remotion/web-renderer'; constabortController = newAbortController (); // Cancel after 10 secondssetTimeout (() =>abortController .abort (), 10000); const {getBlob } = awaitrenderMediaOnWeb ({signal :abortController .signal ,composition , });
检测渲染是否被取消
🌐 Detecting if a render was cancelled
当渲染被取消时,会抛出错误。要区分用户发起的取消和实际错误,请检查信号是否已中止:
🌐 When a render is cancelled, an error is thrown. To distinguish between a user-initiated cancellation and an actual error, check if the signal was aborted:
Handle cancellation in catch blockimport {renderMediaOnWeb } from '@remotion/web-renderer'; constabortController = newAbortController (); try { const {getBlob } = awaitrenderMediaOnWeb ({signal :abortController .signal ,composition , }); } catch (error ) { if (abortController .signal .aborted ) { // Render was cancelled by the user, handle gracefullyconsole .log ('Render was cancelled'); } else { // Handle actual errors throwerror ; } }
另请参阅
🌐 See also