-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.php
352 lines (288 loc) · 8.37 KB
/
watch.php
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
<?php
session_start();
include 'checkSession.php';
include 'fetcher.php';
include 'calculations.php';
include 'head.php';
//$id = $_GET;
$id = $_SERVER['QUERY_STRING'];
?>
<script>
$(document).ready(function(){
//Debug
console.log(sessionStorage.getItem("storedScrollTop"));
//Default general variables
var player = document.getElementById('player');
var playing = false;
var updateDuration;
//Default play button variables
var playBtn = $('#play');
//Default timeline variables
var trailDrag = $("#trailDrag");
var trail = $("#trail");
var trailPos;
var trailPosLeft;
var trailIconWidth = (trailDrag.width()/trailDrag.parent().width())*100;
var scaleFactor = 100/(100-trailIconWidth);
//Default sound variables
var soundDrag = $("#soundDrag");
var soundDragPos = soundDrag.position();
var soundDragPosTop;
var volume = 1;
//Initialization of player
player.removeAttribute("controls");
//Attempt to start video from cookies
try {
if(Cookies.get('1')) player.currentTime = Cookies.get('1');
}
catch(e) {
console.log(e);
}
//Attempt to set volume from cookies
try {
if(Cookies.get('volume')) volume = Cookies.get('volume');
}
catch(e) {
console.log(e);
}
finally {
player.volume = volume;
console.log(volume);
soundDrag.css("top", (100-(volume*100))+"px");
player.play();
}
//Create a new player based on input. NOT USED YET.
function newPlayer(id, volume, currentTime) {
var id = this.id;
var volume = this.volume;
var currentTime = this.currentTime;
var mediaPath;
var subs;
}
/* -------------------- Controllers ------------------ */
//////////////////
//Play & Pause
//////////////////
$('#play').click(function() { player.paused ? player.play() : player.pause(); });
player.onplay = function() { togglePlay(); }
player.onpause = function() { togglePlay(); }
function togglePlay() {
playBtn.html() == '<i class="fa fa-pause" aria-hidden="true"></i>' ? playBtn.html('<i class="fa fa-play" aria-hidden="true"></i>') : playBtn.html('<i class="fa fa-pause" aria-hidden="true"></i>');
playing = !playing;
timeStamp();
}
function timeStamp() {
if(playing) {
updateDuration = setTimeout(function(){
var v = (parseFloat(player.currentTime) / (parseFloat(player.duration)*scaleFactor))*100;
trailDrag.css("left", v+ "%");
trail.css("width", v+ "%");
Cookies.set('1', player.currentTime);
timeStamp();
$("#trailHover").html((player.currentTime/60).toFixed(2));
}, 1000);
}
else { clearTimeout(updateDuration); }
}
//////////////////
//Volume
//////////////////
soundDrag.draggable({ containment: "parent" });
soundDrag.on("drag", function() {
soundDragPos = soundDrag.position();
soundDragPosTop = soundDragPos.top;
volume = ((110-soundDragPosTop)/100).toFixed(2);
Cookies.set('volume', volume);
player.volume = volume;
console.log(volume);
});
var volumePump = $("#volumePump");
$('#volume').click(function() {
volumePump.fadeToggle("fast", "linear");
});
//////////////////
//Fullscreen
//////////////////
var browser = 0;
$("#fullscreen").click(function() {
toggleFullScreen();
});
//Update for cross browsers later. Works in Chrome atm.
//https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API#Toggling_fullscreen_mode
function toggleFullScreen() {
if (!document.webkitFullscreenElement) document.documentElement.webkitRequestFullscreen();
else document.webkitExitFullscreen();
}
//////////////////
//Subtitles
//////////////////
var sw = $("#subsWrapper");
sw.hide();
$('#subtitles').click(function() {
sw.fadeToggle("fast", "linear");
//appendSubs("storage/movies/completed/iron man/subs/bbt.vtt");
});
function appendSubs(src) {
s = '<track src="'+src+'" srclang="en" kind="subtitles" default="true" class="hover">';
$("#player").append(s);
}
var subs = ['English', 'Danish'];
subs.sort();
var subsList = '<ul>'
$.each(subs, function(v,k) {
subsList += '<li>'+k+'</li>';
});
subsList += '</ul>'
$("#selectSub").append(subsList);
$("#selectSub").on('click', 'li', function() {
//console.log(this);
//s = '<track label="Captions" kind="captions" srclang="en" src="storage/movies/completed/iron man/subs/bbt.vtt" id="dynamicTrack" default>';
//$("#player").html(s);
$("#dynamicTrack").attr("src", "storage/movies/completed/iron man/subs/bbt.vtt");
//console.log(getDynamicCues());
reloadCues();
});
var dynamicCues = document.getElementById('dynamicTrack').track.cues;
var cueReloadStatus = false;
var cueRotation;
var counter = 1;
function reloadCues() {
if(!cueReloadStatus) {
dynamicCues = []; //Reset cues
dynamicCues = document.getElementById('dynamicTrack').track.cues;
cueReloadStatus = true;
}
//console.log(dynamicCues.length == 0);
console.log("Cues length: " + dynamicCues.length);
if(dynamicCues.length == 0) {
cueRotation = setTimeout(function() {
console.log("rotation:" + counter);
counter++;
reloadCues(); //Recursively run own function until new cues are ready.
}, 100);
}
else {
cueReloadStatus = false;
clearTimeout(cueRotation);
console.log(dynamicCues.length);
setCueLines(1);
}
}
function setCueLines(pos) {
var val;
var enum = {
'integer': 50,
'percent': "%"
}
if(pos == 1) val = 10;
else val = "auto"
for(i in dynamicCues) {
console.log("Setting val to: "+ val);
dynamicCues[i].line = val;
dynamicCues[i].line = val;
}
}
/*
*/
//////////////////
//Timeline
//////////////////
trailDrag.draggable({
containment: 'parent',
snap: '.gridlines',
axis: 'x',
stop: function () {
player.play();
$("#trailHover").hide();
}
});
trailDrag.on("drag", function() {
trailIconWidth = (trailDrag.width()/trailDrag.parent().width())*100;
scaleFactor = 100/(100-trailIconWidth);
trailPosLeft = ( 100 * parseFloat(trailDrag.position().left / parseFloat(trailDrag.parent().width())));
trailDrag.css("left", trailPosLeft+ "%");
trail.css("width", trailPosLeft+ "%");
scaledDuration = player.duration*scaleFactor;
current = (scaledDuration*trailPosLeft)/100;
player.currentTime = current;
player.pause();
$("#trailHover").html((player.currentTime/60).toFixed(2));
$("#trailHover").show();
});
//////////////////
//Back
//////////////////
$('#back').click(function() {
sessionStorage.setItem("back", 1);
window.location.href = "cinema.php";
});
//////////////////
//Eventlisteners
//////////////////
//Display controls
var mouseafk;
var controlStatus = true;
$("#full").mousemove(function() {
clearTimeout(mouseafk);
if(!controlStatus){
$("#full").css("opacity", 1).css("cursor", "default");
setCueLines(1);
controlStatus = true;
console.log("Set control status: "+ controlStatus)
} else {
if(!player.paused) {
mouseafk = setTimeout(function() {
$("#full").css("opacity", 0).css("cursor", "none");
setCueLines(0);
controlStatus = false;
console.log("Set control status: "+ controlStatus)
}, 3500);
}
}
});
//Pause player on space
$(document).on('keyup',function(evt) {
if (evt.keyCode == 32) {
player.paused ? player.play() : player.pause();
}
});
});
</script>
<video autobuffer controls id="player">
<source src="<?php echo $id ?>">
<track label="Captions" kind="captions" srclang="en" src="" id="dynamicTrack" default>
</video>
<div id="full">
<div id="playerBack">
<i class="fa fa-arrow-circle-left" aria-hidden="true" id="back"></i>
<div id="timedata"></div>
</div>
<div id="controlWrapper">
<div id="timeline">
<div id="trailDrag"><div id="trailHover"></div></div>
<div id="trail"></div>
<div id="inner"></div>
</div>
<div id="playerControls">
<div class="controlBlock left" id="play">
<i class="fa fa-play" aria-hidden="true"></i>
</div>
<div class="controlBlock left" id="volume">
<i class="fa fa-volume-up" aria-hidden="true"></i>
<div id='volumePump'>
<div id="dragContain"><div id="soundDrag"></div></div>
</div>
</div>
<div class="controlBlock right" id="fullscreen">
<i class="fa fa-arrows-alt" aria-hidden="true"></i>
</div>
<div class="controlBlock right" id="subtitles">
<i class="fa fa-cc" aria-hidden="true"></i>
<div id='subsWrapper'>
<div id="selectSub"></div>
</div>
</div>
<div class="controlBlock title"></div>
</div>
</div>
</div>