diff --git a/engine/core/Engine.ts b/engine/core/Engine.ts index c7c0347..ffff2b4 100644 --- a/engine/core/Engine.ts +++ b/engine/core/Engine.ts @@ -46,13 +46,13 @@ export class Engine { this.stateManager.apply(scene.onEnter) } - this.videoManager.play(scene.videoUrl) - this.emit('sceneChange', scene) - this.videoManager.onEnd(() => { this.emit('videoEnd', scene) this.onVideoEnd(scene) }) + + this.videoManager.play(scene.videoUrl) + this.emit('sceneChange', scene) } private onVideoEnd(scene: SceneNode) { diff --git a/engine/core/VideoManager.ts b/engine/core/VideoManager.ts index 401fcee..46cecef 100644 --- a/engine/core/VideoManager.ts +++ b/engine/core/VideoManager.ts @@ -25,9 +25,22 @@ export class VideoManager { if (this.lastSrc !== src) { this.videoEl.src = src this.lastSrc = src + if (this.videoEl.readyState >= 1) { + this.videoEl.currentTime = 0 + this.videoEl.play().catch(() => {}) + } else { + const onReady = () => { + if (this.videoEl) { + this.videoEl.currentTime = 0 + this.videoEl.play().catch(() => {}) + } + } + this.videoEl.addEventListener('loadedmetadata', onReady, { once: true }) + } + } else { + this.videoEl.currentTime = 0 + this.videoEl.play().catch(() => {}) } - this.videoEl.currentTime = 0 - this.videoEl.play().catch(() => {}) } pause() {