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