From d54568e03d5c4027975757bc105b6e58f93c2d4f Mon Sep 17 00:00:00 2001 From: cocos02 Date: Fri, 12 Jun 2026 23:27:43 +0800 Subject: [PATCH] fix: defer play() via setTimeout(0) after seek in loop, avoid browser event loop race --- engine/core/Engine.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/engine/core/Engine.ts b/engine/core/Engine.ts index f4d67d3..8f72270 100644 --- a/engine/core/Engine.ts +++ b/engine/core/Engine.ts @@ -118,8 +118,11 @@ export class Engine { this.videoManager.onEnd(() => { if (this.loopActive && scene.loopEnd) { - this.videoManager.seekTo(scene.loopStart!) - this.videoManager.getActiveVideoElement()?.play().catch(() => {}) + const activeEl = this.videoManager.getActiveVideoElement() + if (activeEl) { + activeEl.currentTime = scene.loopStart! + setTimeout(() => activeEl.play().catch(() => {}), 0) + } return } if (scene.loopStart && !this.loopActive) { @@ -230,8 +233,11 @@ export class Engine { } if (this.loopActive && scene.loopEnd && time >= scene.loopEnd) { - this.videoManager.seekTo(scene.loopStart) - this.videoManager.getActiveVideoElement()?.play().catch(() => {}) + const activeEl = this.videoManager.getActiveVideoElement() + if (activeEl) { + activeEl.currentTime = scene.loopStart + setTimeout(() => activeEl.play().catch(() => {}), 0) + } } }