暂停、继续和中止解析
你可以暂停、继续和中止解析过程。
🌐 You can pause, resume and abort the parsing process.
创建一个 mediaParserController() 并使用以下方法:
🌐 Create a mediaParserController() and use the following methods:
暂停与恢复
🌐 Pause and resume
Pause and resumeimport {mediaParserController ,parseMedia } from '@remotion/media-parser'; constcontroller =mediaParserController ();parseMedia ({src : 'https://www.w3schools.com/html/mov_bbb.mp4',controller , }) .then (() => {console .log ('Finished downloading'); }) .catch ((err ) => {console .error ('Error downloading',err ); }); // Wait 1 sec, pause, wait 1 sec, resume await newPromise ((resolve ) =>setTimeout (resolve , 1000));controller .pause (); await newPromise ((resolve ) =>setTimeout (resolve , 1000));controller .resume ();
取消解析过程
🌐 Cancel a parsing process
Cancel a parsing processimport {mediaParserController ,parseMedia } from '@remotion/media-parser'; constcontroller =mediaParserController ();parseMedia ({src : 'https://www.w3schools.com/html/mov_bbb.mp4',controller , }) .then (() => {console .log ('Finished parsing'); }) .catch ((err ) => {console .error ('Error parsing',err ); }); // Cancel after 10 seconds await newPromise ((resolve ) =>setTimeout (resolve , 10_000));controller .abort ();
检查解析是否被中止
🌐 Checking if a parse was aborted
使用 hasBeenAborted() 函数检查解析是否通过 .abort() 方法中止。
🌐 Use the hasBeenAborted() function to check if a parse was aborted using the .abort() method.
Checking if a parse was abortedimport {mediaParserController ,parseMedia ,hasBeenAborted } from '@remotion/media-parser'; constcontroller =mediaParserController (); constpromise =parseMedia ({src : 'https://www.w3schools.com/html/mov_bbb.mp4',controller , }) .then (() => {console .log ('Finished downloading'); }) .catch ((err ) => { if (hasBeenAborted (err )) {console .log ('Download was cancelled'); } else {console .error ('Error downloading',err ); } });
另请参阅
🌐 See also