-
Notifications
You must be signed in to change notification settings - Fork 9
/
webPlayer.html
365 lines (329 loc) · 11.6 KB
/
webPlayer.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html>
<head>
<title>Visionular web player</title>
</head>
<body>
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'sidebyside')">Side by side</button>
<button class="tablinks" onclick="openTab(event, 'slide')">Slide</button>
<button class="tablinks" onclick="openTab(event, 'help')">Help</button>
</div>
<!-- side by side -->
<div id="sidebyside" class="tabcontent">
<div style="text-align:center">
<br><br>
<video id="video1" width="720" onplay="playV(video2)" onpause="pauseV(video2)" controls style="vertical-align:left;">
Your browser does not support the video tag.
</video>
<video id="video2" width="720" onplay="playV(video1)" onpause="pauseV(video1)" controls style="vertical-align:right;">
Your browser does not support the video tag.
</video>
</div>
<div class="it_maind">
<font color=#AAAAAA>
<p>Control:
<button onclick="playPause(video1, video2)">Play/Pause</button>
<button onclick="stop(video1, video2)">Stop</button>
<button onclick="makeRes(video1, video2, 1080)">1080</button>
<button onclick="makeRes(video1, video2, 720)">720</button>
<button onclick="makeRes(video1, video2, 540)">540</button>
<button onclick="makeRes(video1, video2, 0)">origin</button>
</p>
<p>VideoA: <input id="v_file" type="file" onchange="playFile('v_file', 'video1')"> <span id="video1_size" /> </span>
<span> <- vs -> </span>
VideoB: <input id="v_file2" type="file" onchange="playFile('v_file2', 'video2')"> <span id="video2_size"> </span></p>
<p> Time:
<input id="time_value" type="value"> sec <button onclick="setTime(video1, video2, 'time_value')">Set Time</button>
</p>
<p> Player width:
<input id="player_value" type="value"> px <button onclick="setRes(video1, video2)">Set Resolution</button>
</p>
</font>
</div>
</div>
<!-- slide -->
<!-- ref: https://codemyui.com/video-comparison-slider-animation-using-html5 -->
<div id="slide" class="tabcontent">
<p style="text-align:center" >
VideoA: <input id="v_file3" type="file" onchange="playFile('v_file3', 'video3')"> <span id="video3_size"/> </span>
<span> <- vs -> </span>
VideoB: <input id="v_file4" type="file" onchange="playFile('v_file4', 'video4')"> <span id="video4_size"> </span></p>
<div id="video-compare-container" >
<video id="video4" onplay="playV(video3)" onpause="pauseV(video3)"></video>
<div id="video-clipper">
<video id="video3" onplay="playV(video4)" onpause="pauseV(video4)"></video>
</div>
</div>
<div>
<font color=#AAAAAA>
<p style="text-align:center" >Control
<button onclick="playPause(video3, video4)">Play/Pause</button>
<button onclick="stop(video3, video4)">Stop</button>
<button onclick="fitWindow()">Enlarge</button>
<button onclick="makeResA()">Left Size</button>
<button onclick="makeResB()">Right Size</button>
Time:
<input id="time_value2" type="value"/> sec
<button onclick="setTime(video3, video4, 'time_value2')">Set Time</button>
<button id="videoonly" onclick="onVideoOnly()">video only</button>
</p>
</font>
</div>
</div>
<div id="help" class="tabcontent">
<p>URL arguments:</p>
<p>mode: sbs / slide </p>
<p>videoA: url for the video load to left </p>
<p>VideoB: url for the video load to right </p>
<p>Example1: https://pengbins.github.io/aomanalyzer.io/webPlayer.html?mode=sbs&VideoA=https://demo.visionular.cn/videos/av1/Tears_of_Steal-4k-1920-3min.mov-55-8-out.mp4&VideoB=https://demo.visionular.cn/videos/av1/Tears_of_Steal-4k-1920-3min.mov-50-8-out.mp4</p>
<p>Example2: https://pengbins.github.io/aomanalyzer.io/webPlayer.html?mode=slide&VideoA=https://demo.visionular.cn/videos/av1/Tears_of_Steal-4k-1920-3min.mov-55-8-out.mp4&VideoB=https://demo.visionular.cn/videos/av1/Tears_of_Steal-4k-1920-3min.mov-50-8-out.mp4</p>
</div>
<div style="text-align: center" > Powered by <a href="mailto:[email protected]">Sandy Chuang</a> <a href="https://github.com/pengbins/aomanalyzer.io/blob/master/webPlayer.html">Code</a> </div>
<!-- set border -->
<style>
html {
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
body {
background: #FDF5E6;
margin: 1rem;
}
#video-compare-container {
display: inline-block;
line-height: 0;
position: relative;
width: 100%;
padding-top: 42.3%;
left: 50%;
transform: translate(-50%,0);
}
#video-compare-container>video {
width: 100%;
position: absolute;
top: 0;
height: 100%;
}
#video-clipper {
width: 50%;
position: absolute;
top: 0;
bottom: 0;
overflow: hidden;
border-right-style: solid;
border-color: #FFFAFA;
border-width: 1px
}
#video-clipper video {
width: 200%;
postion: absolute;
height: 100%;
}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 6px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
<script>
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
// Slide window
function trackLocation(e) {
var rect = videoContainer.getBoundingClientRect(),
position = ((e.pageX - rect.left) / videoContainer.offsetWidth) * 100;
if (position <= 92 && position >= 8) {
videoClipper.style.width = position + "%";
clippedVideo.style.width = ((100 / position) * 100) + "%";
clippedVideo.style.zIndex = 3;
}
}
var videoContainer = document.getElementById("video-compare-container"),
videoClipper = document.getElementById("video-clipper"),
clippedVideo = videoClipper.getElementsByTagName("video")[0];
videoContainer.addEventListener("mousemove", trackLocation, false);
videoContainer.addEventListener("touchstart", trackLocation, false);
videoContainer.addEventListener("touchmove", trackLocation, false);
var videoRatio = {"video3":"100%", "video4": "100%" };
function onVideoOnly() {
videoonly = !videoonly;
var btn = document.getElementById("videoonly")
btn.innerHTML = videoonly ? "with audio" : "video only";
playFile('v_file3', 'video3')
playFile('v_file4', 'video4')
}
// Player controller
function playURL(url, tag){
console.log(url);
var v = document.getElementById(tag)
v.src = url;
v.addEventListener("loadedmetadata", function (e) {
var width = this.videoWidth,
height = this.videoHeight;
var sz = document.getElementById( tag +"_size" )
sz.innerHTML = width.toString() + "x" + height.toString();
var winWidth = videoContainer.offsetWidth;
var ratio = (width * 100 / winWidth);
ratio = ratio > 100 ? 100 : ratio;
videoRatio[tag] = ratio.toFixed(0) + "%";
console.log("v: ", width, height, tag, winWidth, videoRatio[tag] );
}, false);
v.addEventListener("error", function (e) {
v.poster = url;
}, true);
}
function playIVF(id, tag) {
fitWindow();
var worker = new Worker('dist/worker.js');
worker.addEventListener('message', function (e) {
console.log('Worker said: ', e.data);
playURL(e.data, tag);
}, false);
var files = document.getElementById(id).files;
console.log('msg: ', files);
worker.postMessage(files);
}
function playFile(id, tag) {
var file = document.getElementById(id).files[0];
if (!file) {
return;
}
fitWindow();
var index = file.name.lastIndexOf(".");
var ext = file.name.substr(index + 1);
console.log(file.name, ext);
if (ext === 'ivf' || videoonly) {
playIVF(id, tag);
} else {
var url = URL.createObjectURL(file);
playURL(url, tag);
}
}
function playV(v1) {
v1.play();
}
function pauseV(v1) {
v1.pause();
}
function seekedV(src, tgt) {
tgt.currentTime = src.currentTime;
}
function playPause(v1, v2) {
if (v1.paused) {
v2.currentTime = v1.currentTime;
v1.play();
v2.play();
}
else {
v1.pause();
v2.pause();
v2.currentTime = v1.currentTime;
}
}
function stop(v1, v2) {
v1.pause();
v2.pause();
v1.currentTime = 0;
v2.currentTime = 0;
}
function rotate(v1, v2) {
}
function load(v1, v2) {
v1.load();
v2.load();
}
function setTime(v1, v2, time_value) {
time = document.getElementById(time_value).value
v1.currentTime = time;
v2.currentTime = time;
}
function makeRes(v1, v2, width) {
v1.width = width;
v2.width = width;
}
function fitWindow() {
videoContainer.style.width = "100%"
}
function makeResA() {
videoContainer.style.width = videoRatio.video3
}
function makeResB() {
videoContainer.style.width = videoRatio.video4
}
function setRes(v1, v2) {
resolution = document.getElementById("player_value").value
v1.width = resolution;
v2.width = resolution;
}
function getQueryVariable(variable){
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return false;
}
// mode=sbs/slide
var mode = getQueryVariable("mode");
var videoonly = getQueryVariable("videoonly");
var tagA, tagB
if (mode == "sbs") {
document.getElementsByClassName('tablinks')[0].click()
tagA = "video1"
tagB = "video2"
} else {
document.getElementsByClassName('tablinks')[1].click()
tagA = "video3"
tagB = "video4"
}
var videoA = getQueryVariable("VideoA");
if (videoA) {
playURL(videoA, tagA);
}
var videoB = getQueryVariable("VideoB");
if (videoB) {
playURL(videoB, tagB);
}
</script>
</body>
</html>