-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
105 lines (92 loc) · 2.43 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// constants
const videos = ["apollo.mp4", "sunset_trim.mp4"];
const videoEl = "example_video";
const timeout = 1000;
// global state
let videoId = 0;
let looking = {
"advance": false,
"backtrack": false,
"prev": false,
"playpause": false,
"speed": false,
"next": false
};
// functions
function lookAt(btn, button_name) {
looking[button_name] = true;
btn.style.backgroundColor = "yellow";
setTimeout(function() {
console.log("timeout went");
console.log(looking);
if (looking[button_name]) {
if (button_name == "advance") {
advanceVideo(btn);
} else if (button_name == "backtrack") {
backtrackVideo(btn);
} else if (button_name == "prev") {
previousVideo(btn);
} else if (button_name == "playpause") {
playpause(btn);
} else if (button_name == "speed") {
speedslow(btn);
} else if (button_name == "next") {
nextVideo(btn);
}
}
}, timeout);
}
function stopLookingAt(btn, button_name) {
looking[button_name] = false;
btn.style.backgroundColor = "green";
}
function playpause(btn) {
const vid = document.getElementById(videoEl);
if (vid.paused) {
vid.play();
btn.innerHTML = "Pause";
} else {
vid.pause();
btn.innerHTML = "Play";
}
}
function speedslow(btn) {
const vid = document.getElementById(videoEl);
if (vid.playbackRate == 1) {
vid.playbackRate = 2;
btn.innerHTML = "2x";
} else {
vid.playbackRate = 1;
btn.innerHTML = "1x";
}
}
function advanceVideo(btn) {
const vid = document.getElementById(videoEl);
if (vid.currentTime + 15 > vid.duration) {
vid.currentTime = vid.duration;
} else {
vid.currentTime += 15;
}
}
function backtrackVideo(btn) {
const vid = document.getElementById(videoEl);
if (vid.currentTime - 15 > vid.duration) {
vid.currentTime = 0;
} else {
vid.currentTime -= 15;
}
}
function previousVideo(btn) {
const vid = document.getElementById(videoEl);
if (videoId != 0) {
videoId -= 1;
}
vid.src = videos[videoId];
}
function nextVideo(btn) {
const vid = document.getElementById(videoEl);
if (videoId != videos.length - 1) {
videoId += 1;
}
vid.src = videos[videoId];
}