Implemented Video Progress Saving and Resuming
This commit is contained in:
@@ -180,14 +180,17 @@ function previewFile(fileUrl, fileName) {
|
|||||||
document.body.appendChild(modal);
|
document.body.appendChild(modal);
|
||||||
|
|
||||||
function closeModal() {
|
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");
|
const mediaElements = modal.querySelectorAll("video, audio");
|
||||||
mediaElements.forEach(media => {
|
mediaElements.forEach(media => {
|
||||||
media.pause();
|
media.pause();
|
||||||
try {
|
// Only reset if it's not a video
|
||||||
media.currentTime = 0;
|
if (media.tagName.toLowerCase() !== 'video') {
|
||||||
} catch(e) {
|
try {
|
||||||
// Some media types might not support setting currentTime.
|
media.currentTime = 0;
|
||||||
|
} catch(e) {
|
||||||
|
// Some media types might not support setting currentTime.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
modal.style.display = "none";
|
modal.style.display = "none";
|
||||||
@@ -265,7 +268,29 @@ function previewFile(fileUrl, fileName) {
|
|||||||
video.src = fileUrl;
|
video.src = fileUrl;
|
||||||
video.controls = true;
|
video.controls = true;
|
||||||
video.className = "image-modal-img";
|
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);
|
container.appendChild(video);
|
||||||
|
|
||||||
} else if (/\.(mp3|wav|m4a|ogg|flac|aac|wma|opus)$/i.test(fileName)) {
|
} else if (/\.(mp3|wav|m4a|ogg|flac|aac|wma|opus)$/i.test(fileName)) {
|
||||||
const audio = document.createElement("audio");
|
const audio = document.createElement("audio");
|
||||||
audio.src = fileUrl;
|
audio.src = fileUrl;
|
||||||
|
|||||||
Reference in New Issue
Block a user