[dyad] Constrain video preview to trimmed selection - wrote 1 file(s)

This commit is contained in:
[dyad]
2026-01-30 08:26:16 +01:00
parent ec60edcc4b
commit 355df6695e

View File

@@ -31,17 +31,26 @@ export function VideoEditor() {
if (!video) return;
const handleTimeUpdate = () => {
if (video.currentTime > trimValues[1]) {
video.pause();
// When the video plays past the end of the trim selection, loop back to the start
if (video.currentTime >= trimValues[1]) {
video.currentTime = trimValues[0];
}
};
const handlePlay = () => {
// If the video is outside the trim range when play is clicked, jump to the start of the trim
if (video.currentTime < trimValues[0] || video.currentTime >= trimValues[1]) {
video.currentTime = trimValues[0];
}
};
video.addEventListener('timeupdate', handleTimeUpdate);
video.addEventListener('play', handlePlay);
return () => {
if (video) {
video.removeEventListener('timeupdate', handleTimeUpdate);
video.removeEventListener('play', handlePlay);
}
};
}, [trimValues]);