-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-control.html
187 lines (157 loc) · 4.73 KB
/
video-control.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Video Control Experiment</title>
<style>
.display-wrap {
display: flex;
flex-flow: row wrap;
}
.control-panel {
border: 1px solid black;
height: 20em;
flex: 1;
padding: 1em;
}
.videoPlayer {
border: 2px solid red;
position: relative;
padding-bottom: 56.23%;
/* Use 75% for 4:3 videos */
height: 0;
overflow: hidden;
max-width: 100%;
background: #000;
margin: 5px;
flex: 4;
}
.videoPlayer #video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
background: transparent;
}
.player-icons {
display: flex;
flex-flow: row;
justify-content: space-between;
}
.icon {
border: 0;
flex: 1;
height: auto;
width: 32px;
}
</style>
</head>
<body>
<section class='display-wrap'>
<div class='videoPlayer'>
<video id='video' controls poster='video/hololens.jpg'>
<source
src='video/hololens.webm'
type='video/webm'>
<source
src='video/hololens.mp4'
type='video/mp4'>
<track kind='subtitles' src='video/hololens.en.vtt' srclang='en'
label='English' id='english'>
</video>
</div>
<div class='control-panel'>
<h2>Video Control Panel</h2>
<div class='player-icons'>
<a href='#' id='rewind'><img class='icon' src='images/icons/rewind.svg' alt='back'></a>
<a href='#' id='play'><img class='icon' id='playIcon' src='images/icons/play-button.svg' alt='play'></a>
<a href='#' id='myStop'><img class='icon' src='images/icons/stop.svg' alt='stop'></a>
<a href='#' id='forward'><img class='icon' src='images/icons/fast-forward.svg' alt='forward'></a>
</div>
<div class='player-icons'>
<a href='#' id='showCaptions'>Enable Captions</a>
<a href='#' id='disableCaptions'>Disable Captions</a>
</div>
</div>
</section>
<script>
// Event Listeners For Play/Pause Button
let video = document.getElementById('video');
let play = document.getElementById('play');
let playIcon = document.getElementById('playIcon');
let rewind = document.getElementById('rewind');
let forward = document.getElementById('forward');
let captions = document.getElementById('captions');
// Remove native controls
video.removeAttribute('controls');
// Event handler for keyboard navigation
window.addEventListener('keypress', (e) => {
if ((e.keyCode !== 32) || (e.keyCode !== 13)) {
if (video.paused) {
video.play();
playIcon.src = 'images/icons/pause.svg';
} else {
video.pause();
playIcon.src = 'images/icons/play-button.svg';
}
}
}
);
// play handler
play.addEventListener('click', (e) => {
// Prevent Default Click Action
e.preventDefault();
if (video.paused) {
video.play();
playIcon.src = 'images/icons/pause.svg';
} else {
video.pause();
playIcon.src = 'images/icons/play-button.svg';
}
});
// captions.addEventListener('click', (e) => {
//
// e.preventDefault();
// console.log(video.textTracks[0].mode);
// if (video.textTracks[0].mode = 'showing') {
// video.textTracks[0].mode = 'hidden';
// console.log(video.textTracks[0].mode);
// } else {
// video.textTracks[0].mode = 'showing';
// console.log(video.textTracks[0].mode);
// }
//
// })
// Show captions
showCaptions.addEventListener('click', (e) => {
e.preventDefault();
video.textTracks[0].mode = 'showing';
});
// Hide captions
disableCaptions.addEventListener('click', (e) => {
e.preventDefault();
video.textTracks[0].mode = 'hidden';
});
// Stop and reset
myStop.addEventListener('click', (e) => {
video.pause();
playIcon.src = 'images/icons/play-button.svg';
video.currentTime = 0;
video.load();
});
// Back 10
rewind.addEventListener('click', (e) => {
skip(-30);
});
// Forward 10
forward.addEventListener('click', (e) => {
skip(30);
});
function skip(value) {
video.currentTime += value;
}
</script>
</body>
</html>