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:
@@ -186,14 +186,21 @@
|
|||||||
endSec.value = trimEnd == null ? '' : trimEnd.toFixed(2)
|
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) {
|
if (editVideo) {
|
||||||
editVideo.addEventListener('loadedmetadata', function () {
|
// 스크립트가 loadedmetadata 이후에 실행되는 경우 (인라인 src) 도 커버.
|
||||||
duration = editVideo.duration || 0
|
if (editVideo.readyState >= 1) applyMetadata()
|
||||||
// 잘못 저장돼있던 값 보정
|
editVideo.addEventListener('loadedmetadata', applyMetadata)
|
||||||
trimStart = clamp(trimStart, 0, Math.max(0, duration - MIN_SELECTION))
|
editVideo.addEventListener('durationchange', applyMetadata)
|
||||||
if (trimEnd != null) trimEnd = clamp(trimEnd, trimStart + MIN_SELECTION, duration)
|
|
||||||
renderTimeline()
|
|
||||||
})
|
|
||||||
editVideo.addEventListener('timeupdate', renderTimeline)
|
editVideo.addEventListener('timeupdate', renderTimeline)
|
||||||
editVideo.addEventListener('seeked', renderTimeline)
|
editVideo.addEventListener('seeked', renderTimeline)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user