fix: defer play() via setTimeout(0) after seek in loop, avoid browser event loop race

This commit is contained in:
2026-06-12 23:27:43 +08:00
parent dda717522d
commit d54568e03d

View File

@@ -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)
}
}
}