fix(editor): handle loadedmetadata race so timeline shows duration

비디오의 src 가 HTML 인라인이라 loadedmetadata 가 스크립트 실행보다
먼저 끝나는 경우, 늦게 붙은 리스너가 영원히 못 받아 duration=0 으로
멈춰있던 문제 수정. readyState 즉시 검사 + durationchange 도 같이
구독하도록 변경.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-15 18:35:10 +09:00
parent f587dce5ce
commit db6fe6224d

View File

@@ -186,14 +186,21 @@
endSec.value = trimEnd == null ? '' : trimEnd.toFixed(2)
}
if (editVideo) {
editVideo.addEventListener('loadedmetadata', function () {
duration = editVideo.duration || 0
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) {
// 스크립트가 loadedmetadata 이후에 실행되는 경우 (인라인 src) 도 커버.
if (editVideo.readyState >= 1) applyMetadata()
editVideo.addEventListener('loadedmetadata', applyMetadata)
editVideo.addEventListener('durationchange', applyMetadata)
editVideo.addEventListener('timeupdate', renderTimeline)
editVideo.addEventListener('seeked', renderTimeline)
}