From 52ddf8268f9e844d09e32a0bc0f7a786e497ff0e Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 31 Mar 2025 05:33:52 -0400 Subject: [PATCH] Implemented Video Progress Saving and Resuming --- fileManager.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/fileManager.js b/fileManager.js index a1c9bee..03f4e9c 100644 --- a/fileManager.js +++ b/fileManager.js @@ -180,14 +180,17 @@ function previewFile(fileUrl, fileName) { document.body.appendChild(modal); function closeModal() { - // Pause and reset any video or audio elements within the modal + // Pause media elements without resetting currentTime for video elements const mediaElements = modal.querySelectorAll("video, audio"); mediaElements.forEach(media => { media.pause(); - try { - media.currentTime = 0; - } catch(e) { - // Some media types might not support setting currentTime. + // Only reset if it's not a video + if (media.tagName.toLowerCase() !== 'video') { + try { + media.currentTime = 0; + } catch(e) { + // Some media types might not support setting currentTime. + } } }); modal.style.display = "none"; @@ -265,7 +268,29 @@ function previewFile(fileUrl, fileName) { video.src = fileUrl; video.controls = true; video.className = "image-modal-img"; + + // Create a unique key for this video (using fileUrl here) + const progressKey = 'videoProgress-' + fileUrl; + + // When the video's metadata is loaded, check for saved progress + video.addEventListener("loadedmetadata", () => { + const savedTime = localStorage.getItem(progressKey); + if (savedTime) { + video.currentTime = parseFloat(savedTime); + } + }); + + // Listen for time updates and save the current time + video.addEventListener("timeupdate", () => { + localStorage.setItem(progressKey, video.currentTime); + }); + + video.addEventListener("ended", () => { + localStorage.removeItem(progressKey); + }); + container.appendChild(video); + } else if (/\.(mp3|wav|m4a|ogg|flac|aac|wma|opus)$/i.test(fileName)) { const audio = document.createElement("audio"); audio.src = fileUrl;