File size: 1,847 Bytes
5193146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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);
}