-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.html
618 lines (515 loc) · 20.8 KB
/
play.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Hour of Power</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/agency.css" rel="stylesheet">
<link href="css/kylecss.css" rel="stylesheet">
<link href="css/test.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
</head>
<body id="page-top" class="index">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href="./#page-top">Hour of Power</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
<a href="./#page-top"></a>
</li>
<li>
<a class="page-scroll" href="./#mostpopular">Popular</a>
</li>
<li>
<a class="page-scroll" href="./#about">About</a>
</li>
<!-- <li>
<a class="page-scroll" href="./#team">Team</a>
</li> -->
<li>
<a class="page-scroll" href="./#contact">Contact</a>
</li>
<li>
<div id="noti_Container">
<a class="page-scroll" href="./mylist.html">My List</a>
<div class="noti_bubble" style="display:none"></div>
</div>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<section id="player">
<div class="container">
<!-- This element will be made full screen-->
<div id="fullscreen-element" style="position:relative">
<div id="playercontainer" class="embed-responsive embed-responsive-16by9">
<div id="player1"></div>
<div id="player2"></div>
</div>
<p id="metadata" style="color:#FF358B"></p>
<div id="loading" class="triangles">
<div class="tri invert"></div>
<div class="tri invert"></div>
<div class="tri"></div>
<div class="tri invert"></div>
<div class="tri invert"></div>
<div class="tri"></div>
<div class="tri invert"></div>
<div class="tri"></div>
<div class="tri invert"></div>
</div>
</div>
<button id="fullscreen" class="btn btn-default" style="float:right">
<span class="glyphicon glyphicon-fullscreen"></span>
</button>
<button id="centuryclub" class="btn btn-default" style="display: none;">CENTURY CLUB</button>
<h2 class = "section-heading" id="counter"></h2>
</div>
</section>
</body>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/lodash.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<script src="js/classie.js"></script>
<!-- Contact Form JavaScript -->
<script src="js/jqBootstrapValidation.js"></script>
<!-- Custom Theme JavaScript -->
<script src="js/agency.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if(sessionStorage.getItem('myListMap_size') > 0) {
$(".noti_bubble").text(sessionStorage.getItem('myListMap_size'));
$(".noti_bubble").show();
console.log(sessionStorage.getItem('myListMap_size'));
}
});
var myListMap;
var myListMap_order;
$(document).ready(function(){
// Once the document is fully loaded, load the iframe API asynchronously
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
myListMap = JSON.parse(sessionStorage.getItem("myListMap"));
myListMap_order = JSON.parse(sessionStorage.getItem("myListMap_order"));
console.log(myListMap);
console.log(myListMap_order);
});
// Variable to hold the playerHandler instance
var pHandler;
var default_width = 854;
var default_height = 512;
function advanceUpnextSelection(vidIndex)
{
var children = $("#upnext").children();
var current_e = children[vidIndex];
var chilOfCur = $(current_e).children();
var selected = chilOfCur[0];
$(selected).addClass('playing');
if(vidIndex != 0){
var lastInd = vidIndex - 1;
var last_e = children[lastInd];
var chilOfLast = $(last_e).children();
var unselected = chilOfLast[0];
$(unselected).removeClass();
}
}
// Called after youtube iframe api is loaded and creates the youtube players
function onYouTubeIframeAPIReady() {
// Initialize the youtube iframe players
var player1 = new YT.Player('player1', {
height: default_height + "px",
width: default_width + "px",
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': onError
},
playerVars: {
'controls': 0,
'fs': 0,
'showinfo': 0,
'iv_load_policy': 3,
'modestbranding': 1,
'disablekb': 1
}
});
var player2 = new YT.Player('player2', {
height: default_height + "px",
width: default_width + "px",
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onError': onError
},
playerVars: {
'controls': 0,
'fs': 0,
'showinfo': 0,
'iv_load_policy': 3,
'modestbranding':1,
'disablekb': 1
}
});
console.log("youtube api ready");
// Hide both players to begin
$(player1.getIframe()).hide();
$(player2.getIframe()).hide();
//$(player1.getIframe()).addClass("embed-responsive-item");
//$(player2.getIframe()).addClass("embed-responsive-item");
// Create a new playerHandler from the players and the videoIds
pHandler = new playerHandler(player1, player2, myListMap_order);
}
// Variable used to determine when both players are ready as this function will be called once for each player
var allPlayersLoaded = false;
// Called after a youtube player is loaded and ready
function onPlayerReady(event) {
console.log("player ready");
// Initialize players volume to 0
event.target.setVolume(0);
// Ensure that both players are ready
if(allPlayersLoaded) {
// Listen for the begin button to start the power hour
pHandler.init();
$("#begin").click(function() {
pHandler.init();
$("#begin").hide();
});
// Listen for fullscreen button in order to enter fullscreen
$("#fullscreen").click(function() {
if(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
exitFullscreen();
} else {
launchIntoFullscreen(document.getElementById("fullscreen-element"));
}
});
$("#centuryclub").click(function() {
pHandler.century();
$("#centuryclub").hide();
});
}
// After first player is loaded, set this variable true so that when the second player is loaded, the program will start
allPlayersLoaded = true;
}
// Called when one of the player's state changes
function onPlayerStateChange(event) {
// If a play event, pass the event target to the playerHandler
if(event.data == YT.PlayerState.PLAYING) {
pHandler.playEvent(event.target);
}
// If a pause event, pass the event target to the playerHandler
if(event.data == YT.PlayerState.PAUSED) {
pHandler.pauseEvent(event.target);
}
}
function onError(event) {
console.log("error");
pHandler.errorEvent(event.target);
}
</script>
<script type="text/javascript">
// Handles the loading and switching of videos
function playerHandler(player1, player2) {
// Keep track of which player is active and which is in the background
this.activePlayer = player2;
this.backgroundPlayer = player1;
// Will contain the indices of loaded videos
this.playQueue = [];
this.playCounter;
// Indicates the index of the next video to load
this.loadIndex = 0;
// Variable indicating whether the activePlayer is paused
this.paused = false;
// Will hold the metadata for the loaded video
this.metadata;
// Will hold the pauseableInterval/pauseableTimeout of the function currently in waiting
this.process;
// Holds the times for the fade between videos and the playing time of each video
this.fadeTime = 1000;
this.playTime = 60000;
// Indicate whether this is the functions first run so that a video can be loaded before played
this.firstRun;
// Initializes variables and the youtube players
this.init = function() {
this.firstRun = true;
this.loadIndex = 0;
this.playQueue = [];
this.playCounter = 60;
// Variable indicating whether the activePlayer is paused
this.paused = false;
// Initially both players should be hidden
//$(this.activePlayer.getIframe()).hide();
//$(this.backgroundPlayer.getIframe()).hide();
// Start both players at 0 volume
this.activePlayer.setVolume(0);
this.backgroundPlayer.setVolume(0);
// Load video in player1 (the "background player")
this.load();
}
// Starts a video on the backgroundPlayer so that it will begin loading and get the metadata of the video from the database
this.load = function () {
// Load the video which will trigger play event after done loading
this.backgroundPlayer.loadVideoById(myListMap_order[this.loadIndex], 60, "highres");
// Set the video's quality
this.backgroundPlayer.setPlaybackQuality("hd720");
// Add the loadIndex to the playQueue
this.playQueue.push(this.loadIndex);
this.metadata = myListMap[myListMap_order[this.loadIndex]];
// Indicate the index of the next video to load
this.loadIndex++
}
// Handles the fading out of the currently active player
this.fadeOut = function() {
var volume = 100;
// Assign the PauseableInterval to process so that if the user pauses the player during a fadeout, the player will be able to resume
this.process = new PauseableInterval(function() { if(volume < 0) { this.process.clearInterval(); this.switch(); } else{ this.activePlayer.setVolume(volume); volume-=10; }}.bind(this), this.fadeTime/10);
}
// Handle the switching between the videos and begin the loading of the next video
this.switch = function() {
// If there is another video to play, switch the background and active players
if(this.playQueue.length > 0 && this.playCounter > 1) {
// Switch the activePlayers
var tmp = this.backgroundPlayer;
this.backgroundPlayer = this.activePlayer;
this.activePlayer = tmp;
// Remove loaded video from playQueue
this.playQueue.shift();
var vidCount = 61 - this.playCounter;
$("#counter").text("Video: " + vidCount);
this.playCounter--;
// Play the loaded video
this.activePlayer.playVideo();
// Set the song and artist headers with the metadata of the loaded video
$("#metadata").text(this.metadata);
$("#metadata").show();
//console.log("going");
window.setTimeout(function() {$("#metadata").fadeOut(1500) }, 8000);
// If more videos to load, load it
if(this.loadIndex < myListMap_order.length)
this.load();
// Begin the fade in of the new video
this.fadeIn();
}
// If there are no other videos to play, stop the currently playing video and run the end code
else {
// Stop the videos
this.activePlayer.stopVideo();
this.backgroundPlayer.stopVideo();
$("#metadata").text("END");
$("#centuryclub").show();
}
}
// Handles the fading in of the currently active player
this.fadeIn = function() {
var volume = 0;
// Assign the PauseableInterval to process so that if the user pauses the player during a fadein, the player will be able to resume
this.process = new PauseableInterval(function() { if(volume > 100) { this.process.clearInterval(); this.waitForSwitch(); } else{ this.activePlayer.setVolume(volume); volume+=10; }}.bind(this), this.fadeTime/10);
}
// Handles the wait between video switches
this.waitForSwitch = function() {
// Assign the PauseableTimeout to process so that if the user pauses the player between video switches, the player will be able to resume
this.process = new PauseableTimeout(function() { this.process.clearTimeout(); this.fadeOut(); }.bind(this), this.playTime);
}
// Handles a play event triggered by a youtube player
this.playEvent = function (eventTarget) {
// If the play event is on the active player, ensure that the active player is not hidden and resume any paused process
if(this.activePlayer == eventTarget) {
// If the video has been paused by the user, resume it
if(this.paused) {
this.process.resume();
this.paused = false;
}
// Otherwise this is a new video playing and the activePlayer needs to be shown and the background player hidden
else {
$(this.backgroundPlayer.getIframe()).hide();
$(this.activePlayer.getIframe()).show();
}
}
// If the play event is on the background player, the video needs to be set to the correct location and should be paused
else if(this.backgroundPlayer == eventTarget) {
// Set the player to the middle
var duration = this.backgroundPlayer.getDuration();
if(duration/2 < 60) {
this.backgroundPlayer.seekTo(0);
} else if(duration > 0) {
this.backgroundPlayer.seekTo(duration/2);
}
// Video done loading, pause the video which will trigger pause event
this.backgroundPlayer.pauseVideo()
}
}
// Handles a pause event triggered by a youtube player
this.pauseEvent = function (eventTarget) {
// If the pause event is on the active player, then pause the currently running process and indicate that the activePlayer is paused
if(this.activePlayer == eventTarget) {
this.paused = true;
this.process.pause();
}
// If the pause event is on the background player, then this just indicates that the video has finished loading and nothing needs to be done
else if(this.backgroundPlayer == eventTarget) {
// If this is the first run however, then switch the video so that the loaded video is active
if(this.firstRun) {
this.firstRun = false;
$("#loading").hide();
this.switch();
}
}
}
this.errorEvent = function (eventTarget) {
console.log("error");
if(this.backgroundPlayer == eventTarget) {
if(this.loadIndex < myListMap_order.length)
this.load();
}
}
this.fullscreen = function() {
this.activePlayer.setSize($(window).width(), $(window).height());
this.backgroundPlayer.setSize($(window).width(), $(window).height());
$("#metadata").css("font-size", 28*$(window).width()/default_width + "px");
}
this.exitFullscreen = function() {
this.activePlayer.setSize(default_width + "px", default_height + "px");
this.backgroundPlayer.setSize(default_width + "px", default_height + "px");
$("#metadata").css("font-size", 28 + "px");
}
this.century = function() {
this.playCounter = 40;
this.switch();
}
}
</script>
<script type="text/javascript">
// Set element to fullscreen
function launchIntoFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
// Exit full screen (will trigger a fullscreenchange event)
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
// This function listens for a fullscreenchange event and alters the player size accordingly
var exitHandler = function(){
if(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
// If going fullscreen, set the player sizes to the width and height of the window
pHandler.fullscreen();
$("#playercontainer").removeClass("embed-responsive embed-responsive-16by9");
//$("#fullscreen-element").removeClass("container");
//$("#content-container").removeClass("defaultsize");
//$("#content-container").addClass("fullscreen");
} else {
// If exiting fullscreen, set the player sizes to a smaller width and height
pHandler.exitFullscreen();
$("#playercontainer").addClass("embed-responsive embed-responsive-16by9");
//$("#fullscreen-element").addClass("container");
//$("#content-container").removeClass("fullscreen");
//$("#content-container").addClass("defaultsize");
}
}
if (document.addEventListener)
{
document.addEventListener('webkitfullscreenchange', exitHandler, false);
document.addEventListener('mozfullscreenchange', exitHandler, false);
document.addEventListener('fullscreenchange', exitHandler, false);
document.addEventListener('MSFullscreenChange', exitHandler, false);
}
</script>
<script type="text/javascript">
// Wrapper for the timeout function that allows a timeout to be paused and resumed
function PauseableTimeout(func, delay){
this.func = func;
var _now = new Date().getTime();
this.triggerTime = _now + delay;
this.t = window.setTimeout(this.func,delay);
this.paused_timeLeft = 0;
this.getTimeLeft = function(){
var now = new Date();
return this.triggerTime - now;
}
this.pause = function(){
this.paused_timeLeft = this.getTimeLeft();
window.clearTimeout(this.t);
this.t = null;
}
this.resume = function(){
if (this.t == null){
this.t = window.setTimeout(this.func, this.paused_timeLeft);
}
}
this.clearTimeout = function(){ window.clearTimeout(this.t);}
}
// Wrapper for the interval function that allows a interval to be paused and resumed
function PauseableInterval(func, delay){
this.func = func;
this.delay = delay;
this.triggerSetAt = new Date().getTime();
this.triggerTime = this.triggerSetAt + this.delay;
this.i = window.setInterval(this.func, this.delay);
this.t_restart = null;
this.paused_timeLeft = 0;
this.getTimeLeft = function(){
var now = new Date();
return this.delay - ((now - this.triggerSetAt) % this.delay);
}
this.pause = function(){
this.paused_timeLeft = this.getTimeLeft();
window.clearInterval(this.i);
this.i = null;
}
this.restart = function(sender){
sender.i = window.setInterval(sender.func, sender.delay);
}
this.resume = function(){
if (this.i == null){
this.i = window.setTimeout(this.restart, this.paused_timeLeft, this);
}
}
this.clearInterval = function(){ window.clearInterval(this.i);}
}
</script>
</html>