diff --git a/core/CaptureContext.js b/core/CaptureContext.js index 2d5a15a..aad32ca 100644 --- a/core/CaptureContext.js +++ b/core/CaptureContext.js @@ -22,6 +22,8 @@ export default class CaptureContext { frameInterval = 0; /** @type {boolean} - 准备完毕标志 */ readyFlag = false; + /** @type {boolean} - 启动标志 */ + startFlag = false; /** @type {boolean} - 停止标志 */ stopFlag = false; /** @type {boolean} - 暂停标志 */ @@ -51,6 +53,7 @@ export default class CaptureContext { /** @type {number} - 目标总帧数 */ frameCount: null }; + skipFramePromise; /** @type {SvgAnimation[]|VideoCanvas[]|DynamicImage[]|LottieCanvas[]} - 媒体调度列表 */ dispatchMedias = []; @@ -119,6 +122,8 @@ export default class CaptureContext { this.startTime = Date.now(); // 计算帧间隔时间 this.frameInterval = 1000 / this.config.fps; + // 设置启动标志 + this.startFlag = true; // 递归捕获帧 (function nextFrame() { (async () => { @@ -350,6 +355,8 @@ export default class CaptureContext { window.____setInterval = window.setInterval; // 重写setInterval函数 window.setInterval = (fn, interval) => { + if(!this.startFlag) + return window.____setInterval(fn, interval); if (typeof fn !== "function") throw new TypeError("setInterval function must be Function"); if (isNaN(interval)) @@ -363,16 +370,21 @@ export default class CaptureContext { // 重写cleanInterval函数 window.clearInterval = timerId => { if (!timerId) return; + if(!this.startFlag) + return window.____clearInterval(timerId); this.intervalCallbacks = this.intervalCallbacks.filter(([_timerId]) => { if (_timerId == timerId) return false; return true; }); + window.____clearInterval(timerId); } // 暂存setTimeout函数 window.____setTimeout = window.setTimeout; // 重写setTimeout函数 window.setTimeout = (fn, timeout = 0) => { + if(!this.startFlag) + return window.____setTimeout(fn, timeout); if (typeof fn !== "function") return; this.timerId++; @@ -384,11 +396,14 @@ export default class CaptureContext { // 重写clearTimeout函数 window.clearTimeout = timerId => { if (!timerId) return; + if(!this.startFlag) + return window.____clearTimeout(timerId); this.timeoutCallbacks = this.timeoutCallbacks.filter(([_timerId]) => { if (_timerId == timerId) return false; return true; }); + window.____clearTimeout(timerId); } // 暂存requestAnimationFrame函数 window.____requestAnimationFrame = window.requestAnimationFrame; @@ -397,7 +412,7 @@ export default class CaptureContext { if (this.stopFlag) return; // 下一个事件循环再调用 - window.____requestAnimationFrame(() => fn(this.currentTime)); + return window.____requestAnimationFrame(rawCurrentTime => fn(this.startFlag ? this.currentTime : rawCurrentTime)); }; // 暂存Date对象 window.____Date = Date;