-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.js
47 lines (37 loc) · 1.08 KB
/
video.js
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
const { ipcRenderer } = require("electron");
const video = document.getElementById("player");
const overlay = document.getElementById("overlay");
const timeouts = [];
const fadeInto = (videoPath, isResting) => {
console.log(isResting);
overlay.className = "";
overlay.classList.add("fadeIn");
timeouts.push(window.setTimeout(() => {
video.setAttribute("src", videoPath);
if (!isResting) {
video.onloadedmetadata = onLoadedMetaData;
} else {
video.onloadedmetadata = null;
video.onended = onLoopEnded;
}
}, 300));
timeouts.push(window.setTimeout(() => {
overlay.className = "";
overlay.classList.add("fadeOut");
}, 600));
}
const onLoadedMetaData = () => {
timeouts.push(window.setTimeout(onVideoEnded, video.duration * 1000 - 300));
}
const onVideoEnded = () => {
ipcRenderer.send('ended');
fadeInto("./assets/resting.mp4", true);
}
const onLoopEnded = () => {
video.play();
}
video.onended = onLoopEnded;
ipcRenderer.on('play', (_, message) => {
timeouts.forEach(t => window.clearTimeout(t));
fadeInto(message, false);
})