Files
JaredTherriault-ComfyUI-JNodes/web/js/common/VideoControl.js
T
JaredTherriault f0338b0c5f Batch selection, batch deletion, classifying some scripts, module manager
-Added new batch selection and batch deletion features. All imageElements now have a checkbox and each selected element is tracked within a context or folder. When you've selected all you want to delete, click the recycle button on the toolbar, then again to confirm. All checked items will be recylced/deleted. You can also click on the selection widget next to the batch delete button to toggle select/deselect all.
-Renamed ImageDrawer.js to ImageDrawerMain.js
-Separated ImageListAndSearch out into separate scripts and classes named ImageDrawerList and ImageDrawerSearch
-Changed order of some initialized functions and variables in imageElements to better accommodate batch selection
-
-Moved some scripts over to a classy architecture. More scripts will be moved over time. This will eventually allow for multiple image drawer instances in the same window.
-Added a new module script that manages all class instances. See ImageDrawerModule.js for an explanation of the new architecture. Basically, it makes cyclical dependencies impossible.
-Updated imports
-Updated various scripts to use class instances where applicable
-Updated some outdated comments
-Added option to prepend or append labels to Labeled widgets
-Parameter optimizations
-
2024-05-07 20:39:40 -07:00

63 lines
1.8 KiB
JavaScript

import { utilitiesInstance } from "./Utilities.js";
export function isElementVideo(element) {
return element && element.tagName === 'VIDEO';
}
export async function toggleVideoPlayback(video) {
if (!video.pause || !video.play || !('paused' in video)) { return; }
if (video.paused) {
await video.play();
} else {
video.pause();
}
};
export function toggleVideoMute(video) {
if ('muted' in video) {
video.muted = !video.muted;
}
}
export function setVideoVolume(video, percentage) {
video.volume = utilitiesInstance.clamp(percentage / 100, 0.0, 1.0); // Slider is 1-100, volume is 0-1
}
export function toggleVideoFullscreen(video) {
if (!document.fullscreenElement) {
video.requestFullscreen();
} else {
document.exitFullscreen();
}
}
export function setVideoPlaybackRate(video, rate) {
video.playbackRate = utilitiesInstance.clamp(rate, 0.05, 100.00);
}
export function seekVideo(video, delta) {
if (!video.duration || !video.currentTime) { return; }
const maxTime = video.duration;
const currentTime = video.currentTime;
const seekStep = utilitiesInstance.clamp(maxTime / 100, 1, 10); // Seek multiplier: 1 sec min / 1% of video / 10 sec max
let newTime = currentTime + (delta * seekStep);
newTime = utilitiesInstance.clamp(newTime, 0, maxTime); // utilitiesInstance.clamp within valid range
video.currentTime = newTime; // Seek the video to the new time
};
export function onScrollVideo(video, event, bInvertWheelSeek) {
event.preventDefault(); // Prevent default scroll behavior
// Determine the scroll direction (positive or negative)
let scrollDelta = Math.sign(event.deltaY); // -1 for up, 1 for down
if (bInvertWheelSeek) {
scrollDelta *= -1;
}
seekVideo(video, scrollDelta);
}