From db6fe6224dda20ed4d18cedeea17101efd1e830e Mon Sep 17 00:00:00 2001 From: claude-bot Date: Fri, 15 May 2026 18:35:10 +0900 Subject: [PATCH] fix(editor): handle loadedmetadata race so timeline shows duration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 비디오의 src 가 HTML 인라인이라 loadedmetadata 가 스크립트 실행보다 먼저 끝나는 경우, 늦게 붙은 리스너가 영원히 못 받아 duration=0 으로 멈춰있던 문제 수정. readyState 즉시 검사 + durationchange 도 같이 구독하도록 변경. Co-Authored-By: Claude Opus 4.7 --- public/editor.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/public/editor.js b/public/editor.js index 2f30fa9..b6e04f5 100644 --- a/public/editor.js +++ b/public/editor.js @@ -186,14 +186,21 @@ endSec.value = trimEnd == null ? '' : trimEnd.toFixed(2) } + function applyMetadata() { + var d = editVideo.duration + if (!d || !isFinite(d) || d <= 0) return + duration = d + // 잘못 저장돼있던 값 보정 + trimStart = clamp(trimStart, 0, Math.max(0, duration - MIN_SELECTION)) + if (trimEnd != null) trimEnd = clamp(trimEnd, trimStart + MIN_SELECTION, duration) + renderTimeline() + } + if (editVideo) { - editVideo.addEventListener('loadedmetadata', function () { - duration = editVideo.duration || 0 - // 잘못 저장돼있던 값 보정 - trimStart = clamp(trimStart, 0, Math.max(0, duration - MIN_SELECTION)) - if (trimEnd != null) trimEnd = clamp(trimEnd, trimStart + MIN_SELECTION, duration) - renderTimeline() - }) + // 스크립트가 loadedmetadata 이후에 실행되는 경우 (인라인 src) 도 커버. + if (editVideo.readyState >= 1) applyMetadata() + editVideo.addEventListener('loadedmetadata', applyMetadata) + editVideo.addEventListener('durationchange', applyMetadata) editVideo.addEventListener('timeupdate', renderTimeline) editVideo.addEventListener('seeked', renderTimeline) }