forked from 3rdcupofjava/yap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist.html
501 lines (430 loc) · 25.9 KB
/
playlist.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>YouTubeApp</title>
<script src="googleapis.com/ajax/libs/swfobject/2.2/swtobject.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<style>
.container { width: 825px; }
.header { height: 50px; }
.nav-btns { width: 425px; padding: 12px 0px; position: absolute; }
.VideoTime { padding: 15px 10px; margin-left: 425px; font-size: 16px; border: solid 1px #000; }
#tubePlayer { position: absolute; }
.playlist { margin-left: 425px;height: 356px; font-size: 16px; margin-bottom: 0px;overflow:auto; background-color: #333; }
.list { list-style-type:none; padding: 0px; }
.list li a { text-decoration: none; color: #fff;}
.list li:hover { background-color: #3a3a3a; }
.activePlayed { background-color: #d9534f; pointer-events: none; cursor: default; }
.activeHighlight { background-color: #4cae4c; }
.playlist-details { padding:10px 15px; }
.video-time { float: right; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="nav-btns">
<button onclick="Pause();">Pause</button>
<button onclick="Play()">Start</button>
<button onclick="Restart()">Restart</button>
<button onclick="Previous()">Previous</button>
<button onclick="Next()">Next</button>
</div>
<div class="CurrentTime" style="display:none"></div>
<div class="VideoTime"></div>
</div>
<div id="tubePlayer">
You may or may not need Flash Player something or other and JavaScript enabled to blow up the enterprise.
</div>
<div class="playlist">
<ul class="list" id="list">
</ul>
</div>
</div>
<div class="lyrics"></div>
</body>
<script type="text/javascript">
var tracks = new Array(
[1, 'Jesse Stewart - Cold Beer','3:39','https://www.youtube.com/watch?v=ZEvQOPUHGH8'],
[1, 'Miley Cyrus - Jolene', '2:59', 'https://www.youtube.com/watch?v=wOwblaKmyVw'],
[1, 'DZIDZIO - Старі фотографії','3:33','https://www.youtube.com/watch?v=_Gx0ZyQSSpg'],
[1, 'Sound Choir Romania - Shchedryk','1:54','https://www.youtube.com/watch?v=cP5iHPOJKlk'],
[1, 'Pentatonix - Carol of the Bells','4:10','https://www.youtube.com/watch?v=WSUFzC6_fp8'],
[2, 'Jesse Stewart - Cold Beer', '4:16', 'http://www.jessedirtybeer.com/Cold_Beer_-_Deep_in_Cider.mp3'],
[2, 'Miley Cyrus - Jolene', '3:00', 'http://www.mp3zone.sk/files/4648057/miley-cyrus-jolene.mp3'],
[2, 'Zac Brown Band - Free', '3:48', 'http://a.tumblr.com/tumblr_lpm56qfUjB1qzl28wo1.mp3'],
[2, 'Zac Brown Band - Sweet Annie', '4:39', 'http://mp3for.me/assets/songs/72000-72999/72360-sweet-annie-zac-brown-band.mp3']
);
var Lyrics = {
0 : Array(
['','0:00'],
['Kinda get broken when it comes to emotion makes me start chokin so I sit by the ocean','0:06'],
['I spent my last buck on a bottle o whiskey drunk and broke sittin here in history','0:12'],
["I made my mind up how I'm goin got no where to go don't know where I'm goin",'0:18'],
["I do know one thing that is true wherever I go I'm gonna need you",'0:24'],
["we just can't let each other go now we're to close to ever slow down",'0:30'],
["the only one who keeps my chin up when you touch my lips we're like two dogs stuck",'0:37'],
["cold, cold beer don't you ever worry I am right here never live without you (you) dont care what I amount to",'0:48'],
["talkin bout cold cold beer don't you ever worry Im right here never live without you",'1:01'],
["I pick you up I take you home sit on my couch turn off my phone",'1:07'],
["cause I love your taste love your smell who'd ve ever thought that we could do so well hell",'1:14'],
["I guess we're meant for each other so like the microphone and my buddy Bruce Buffer, I can't really express my joy",'1:22'],
["so like a scrap between so good and patty roy I cant take my eyes off you",'1:28'],
["went to rehab thought that I lost you now we're back together with a vengence must be my little irish decendence",'1:38'],
["feels pretty good to get this off my chest even though people sayin (singer's name)'s obsessed",'1:44'],
["maybe I am maybe they're right all I know is one thing it was love at first sight",'1:50'],
["cold, cold beer don't you ever worry I am right here never live without you I wouldn't even want to",'2:02'],
["cold, cold beer don't you ever worry I am right here never live without you You dont care what I amount to",'2:27'],
["Well I'm sittin on the stoop feelin kinda lonely me and brenda fightin so i call up the homies",'2:34'],
["boys busy hangin out in front of soby's there's only one little fella that really knows me",'2:40'],
["He comes in a little brown bottle or can sits in my hand till I can barely stand",'2:46'],
["part of the fam part of the team took me under his wing when I was just a teen",'2:52'],
["every time he come around it always takes me back to when I had a fake id and a little dirt stash",'2:59'],
["get a road so cold pop two for a whop top twist off pop top tall boy cold shot",'3:05'],
["beer, cold beer don't you ever worry I am right here never live without you You dont care what I amount to",'3:18'],
["cold, cold beer don't you ever worry I am right here I could never live without you I wouldn't even want to",'3:39']
),
1 : Array(
['','0:13'],
["Jolene, Jolene, Jolene, Jolene","0:19"],
["I'm begging of you please don't take my man","0:27"],
["Jolene, Jolene, Jolene, Jolene","0:32"],
["Please don't take him just because you can","0:40"],
["Your beauty is beyond compare","0:42"],
["With flaming locks of auburn hair","0:43"],
["With ivory skin and eyes of emerald green","0:51"],
["Your smile is like a breath of spring","0:53"],
["Your voice is soft like summer rain","0:56"],
["And I cannot compete with you, Jolene","1:02"],
["And I can easily understand","1:05"],
["How you could easily take my man","1:07"],
["But you don't know what he means to me, Jolene","1:14"],
["He talks about you in his sleep","1:17"],
["There's nothing I can do to keep","1:19"],
["From crying when he calls your name, Jolene","1:23"],
["Jolene","1:25"],
["Jolene, Jolene, Jolene, Jolene","1:32"],
["Please don't take him just because you can","1:39"],
["Jolene, Jolene, Jolene, Jolene","1:45"],
["Please don't take him just because you can","1:52"],
["I had to have this talk with you","1:54"],
["My happiness depends on you","1:56"],
["And whatever you decide to do, Jolene","2:03"],
["I'm begging of you please don't take my man","2:06"],
["But I could never love again","2:07"],
["He's the only one for me, Jolene","2:15"],
["Jolene, Jolene, Jolene, Jolene","2:20"],
["I'm begging of you please don't take my man","2:27"],
["Jolene, Jolene, Jolene, Jolene","2:34"],
["Please don't take him even though you can","2:40"],
["Jolene,","2:42"],
["Jolene","2:44"]
["Jol-e-e-ene",""]
),
2 : Array(
["","0:29"],
["Здається, шо то було так давно","0:32"],
["Коли в руках тримаю цей альбом","0:35"],
["Нам було абсолютно все одно","0:38"],
["Немаючи нічого мати всьо","0:41"],
["За гроші не купити тільки час","0:44"],
["Він всіх нас методично поділив","0:47"],
["Когось він опустив, когось підняв","0:50"],
["А є на кого взагалі забив.","0:53"],
["Старі фотографії на стіл розклади","0:59"],
["Дитячі історії смішні розкажи","1:05"],
["І справжнім друзям не забудь, подзвони","1:11"],
["Бо добре чи зле, з тобою завжди вони","1:22"],
["Дешеве пиво і сухе вино","1:25"],
["Робили нас щасливими людьми","1:28"],
["І ніби чудо польське радіо","1:31"],
["Нам відкривало той незнаний світ","1:34"],
["Ми жили всі так ніби, то був сон","1:37"],
["І можна бути вічно молодим","1:40"],
["А залишився тільки цей альбом","1:43"],
["А мрії розлетілися, як дим.","1:45"],
["Старі фотографії на стіл розклади","1:52"],
["Дитячі історії смішні розкажи","1:58"],
["І справжнім друзям не забудь, подзвони","2:04"],
["Бо добре чи зле, з тобою завжди вони","2:16"],
["Ми грали примітивну музику","2:19"],
["Так чесно, що пробила би до сліз","2:22"],
["Чекали, що прийде такий момент","2:25"],
["Коли під ноги впаде цілий світ","2:28"],
["Годинник вперто роки рахував","2:31"],
["І кожен так як міг так і зробив","2:34"],
["І тільки у альбомі всі підряд","2:37"],
["Ми будемо такими, як тоді","2:39"],
["Старі фотографії на стіл розклади","2:46"],
["Дитячі історії смішні розкажи","2:52"],
["І справжнім друзям не забудь, подзвони","2:58"],
["Бо добре чи зле, з тобою завжди вони","3:04"],
["Старі фотографії на стіл розклади","3:10"],
["Дитячі історії смішні розкажи","3:16"],
["І справжнім друзям не забудь, подзвони","3:22"],
["Бо добре чи зле, з тобою завжди вони",""]
)
};
var nextlyrics=0;
function VideoTime(){
$('.VideoTime').each(function(){
videotime = $(this).text();
if(videotime >= Lyrics[PlaylistIdentifier['Number']][nextlyrics][1]){
highlightnext = 0;
nextlyrics++;
NextLyrics(nextlyrics);
}
});
}
function NextLyrics(nextlyrics){
var text ="";
var lyrics = Lyrics[PlaylistIdentifier['Number']][nextlyrics][0].split("");
for(var i=0;i<lyrics.length;i++) {
text += "<span id='p"+i+"' style='color:#000'>" + lyrics[i] + "</span>";
}
$('.lyrics').html(text);
lyricshighlights();
}
var highlightnext= 0;
function lyricshighlights() {
$('#p'+highlightnext).css("background-color", "green");
highlightnext++;
window.setTimeout(lyricshighlights, 200);
}
var getPlaylist = function() {
var res = [];
for(var i = 0; i < tracks.length; i+=1) {
if(tracks[i][0] == 1){
res.push(tracks[i][3].substr(tracks[i][3].indexOf("=") + 1));
} else {
res.push(tracks[i][3]);
}
}
return res;
};
var getVideoTime = function(){
var videotime = [];
for(var x =0; x < tracks.length; x+=1){
videotime.push(tracks[x][2]);
}
return videotime;
};
function getPlaylistDetails(videoID, videoStatus, currentPlay){
var playlist = [];
var classfield;
var clickstatus;
var c =0;
$.each(tracks, function(i) {
if((getPlaylist()[i] == videoID && videoStatus == 'videoPlay') || (getPlaylist()[i] == currentPlay)){
classfield ='class="activePlayed"';
clickstatus ='';
} else if($.inArray(getPlaylist()[i], videoSelected) !== -1) {
classfield ='class="activeHighlight"';
clickstatus ='ondblclick="clickPlaylist('+i+'); return false;"';
} else {
classfield="";
clickstatus='onclick="highLights('+i+')"';
}
if(tracks[i][0] == 1){
playlist.push('<li '+classfield+' id="youtubeapp-song-'+c+'"> <a href="#" '+ clickstatus +'> <div class="playlist-details"> <div class="video-details"> <span class="video-name">' +tracks[i][1]+ '<span class="video-time"> '+tracks[i][2]+' </span> </div> <div class="video-img"> <img src="http://img.youtube.com/vi/'+ tracks[i][3].substr(tracks[i][3].indexOf("=") + 1) +'/default.jpg" width="72"> </div> </div> </a> </li>');
} else {
playlist.push('<li '+classfield+' id="mp3-song-'+c+'"> <a href="#" '+ clickstatus +' id="play"> <div class="playlist-details"> <div class="video-details"><span class="video-name">' +tracks[i][1]+ '<span class="video-time">'+tracks[i][2]+'</span> </div> <audio id="myAudio'+c+'" preload="auto"> <source src="'+tracks[i][3]+'" type="audio/mp3"/></audio> </div> </a> </li>');
}
c++;
});
$('.list').html( playlist.join(''));
}
var params = { allowScriptAccess: "always"};
var atts = { id: "tubePlayer"};
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=ytplayer&version=3&controls=1&showinfo=0", "tubePlayer", "425", "356", "8", null, null, params, atts);
var player;
var PlaylistIdentifier = {};
function onYouTubePlayerReady(id, iter) {
if(iter == undefined){
iter = 0;
getPlaylistDetails(getPlaylist()[iter], 'videoPlay', '0');
}
removeHightlights();
PlaylistIdentifier['Number'] = iter;
setInterVal();
player=$("#tubePlayer").get(0);
if(tracks[iter][0] == 1){
nextlyrics=0;
$('.lyrics').html("");
player.loadVideoById({'videoId': getPlaylist()[iter], 'startSeconds': 0,/* 'endSeconds': 0,*/ 'suggestedQuality': 'large'});
player.addEventListener("onStateChange", "onytplayerStateChange");
} else {
player.pauseVideo();
getPlaylistDetails(getPlaylist()[iter], 'videoPlay');
var myAudio = document.getElementById("myAudio"+iter+"");
myAudio.play();
}
}
function Play(){
if(tracks[PlaylistIdentifier['Number']][0] == 1){
player.playVideo()
} else {
var myAudio = document.getElementById("myAudio"+PlaylistIdentifier['Number']+"");
myAudio.play();
}
}
function Pause(){
$('.CurrentTime').each(function(){
if(tracks[PlaylistIdentifier['Number']][0] == 1){
player.pauseVideo();
} else {
var myAudio = document.getElementById("myAudio"+PlaylistIdentifier['Number']+"");
myAudio.pause();
}
var LenghtTime = $(this).text().indexOf(".");
var CurrentVideoTime = $(this).text().substring(0, LenghtTime);
var PlaylistNumber = tracks.length - 1;
if(CurrentVideoTime >= 81){
if(PlaylistIdentifier['Number'] < PlaylistNumber){
alert('Next Video: ' + tracks[nextPlay()][1] + ' - ' + tracks[nextPlay()][2]);
}
}
});
}
function Next(){
var PlaylistNumber = tracks.length;
nextNumber = nextPlay();
if(nextNumber <= PlaylistNumber){
onYouTubePlayerReady('ytplayer', nextNumber);
if(tracks[nextNumber][0] == 1){
getPlaylistDetails(getPlaylist()[nextNumber], 'videoPlay');
}
getCurrentTime('Reset');
} else {
alert('There are no video for next');
}
}
function Previous(){
if(PlaylistIdentifier['Number'] != 0){
previousNumber = PlaylistIdentifier['Number'] - 1;
onYouTubePlayerReady('ytplayer', previousNumber);
if(tracks[previousNumber][0] == 1){
getPlaylistDetails(getPlaylist()[previousNumber], 'videoPlay');
}
getCurrentTime('Reset');
} else {
alert('There are no video for previous');
}
}
function Restart(){
if(tracks[PlaylistIdentifier['Number']][0] == 1){
onYouTubePlayerReady('ytplayer', PlaylistIdentifier['Number']);
} else {
var myAudio = document.getElementById("myAudio"+PlaylistIdentifier['Number']+"");
myAudio.load();
myAudio.play();
}
getCurrentTime('Reset');
}
function clickPlaylist(videoID){
onYouTubePlayerReady('ytplayer', videoID);
getCurrentTime('Reset');
if(tracks[videoID][0] == 1){
getPlaylistDetails(getPlaylist()[videoID], 'videoPlay');
}
}
var videoSelected = [];
var videoNumSelected =[];
function highLights(videoID){
if($.inArray(getPlaylist()[videoID], videoSelected) !== -1){
alert('already saved');
} else {
videoSelected.push(getPlaylist()[videoID]);
videoNumSelected.push(videoID);
if(tracks[PlaylistIdentifier['Number']][0] == 2){
if(tracks[videoID][0] == 2){
$('#mp3-song-'+videoID+'').html('<li class="activeHighlight" id="mp3'+videoID+'"> <a href="#" ondblclick="clickPlaylist('+videoID+'); return false;" id="play"> <div class="playlist-details"> <div class="video-details"><span class="video-name">' +tracks[videoID][1]+ '<span class="video-time">'+tracks[videoID][2]+'</span> </div> <audio id="myAudio'+videoID+'" preload="auto"> <source src="'+tracks[videoID][3]+'" type="audio/mp3"/></audio> </div> </a> </li>');
} else {
$('#youtubeapp-song-'+videoID+'').html('<li class="activeHighlight" id="youtubeapp-song-'+videoID+'"> <a href="#" ondblclick="clickPlaylist('+videoID+'); return false;"> <div class="playlist-details"> <div class="video-details"> <span class="video-name">' +tracks[videoID][1]+ '<span class="video-time"> '+tracks[videoID][2]+' </span> </div> <div class="video-img"> <img src="http://img.youtube.com/vi/'+ tracks[videoID][3].substr(tracks[videoID][3].indexOf("=") + 1) +'/default.jpg" width="72"> </div> </div> </a> </li>');
}
} else {
getPlaylistDetails(getPlaylist()[videoID], 'videoHighLights', getPlaylist()[PlaylistIdentifier['Number']]);
}
}
}
function removeHightlights(){
if($.inArray(getPlaylist()[PlaylistIdentifier['Number']], videoSelected) !== -1){
videoSelected.splice($.inArray(getPlaylist()[PlaylistIdentifier['Number']], videoSelected),1);
videoNumSelected.splice($.inArray(PlaylistIdentifier['Number'], videoNumSelected),1);
}
}
function nextPlay(){
if(videoNumSelected.length > 1){
NextPlay = videoNumSelected[1];
} else {
NextPlay = PlaylistIdentifier['Number'] + 1;
}
return NextPlay;
}
var secInterval = 0;
var minutes = 0;
var currentvideoTime;
function getCurrentTime(status){
if(tracks[PlaylistIdentifier['Number']][0] == 2){
var myAudio = document.getElementById("myAudio"+PlaylistIdentifier['Number']+"");
$('.CurrentTime').text(myAudio.currentTime);
} else {
$('.CurrentTime').text(player.getCurrentTime());
}
$('.CurrentTime').each(function(){
var getCurrentTime = $(this).text();
var LenghtTime = getCurrentTime.indexOf(".");
var getSeconds = getCurrentTime.substring(0, LenghtTime);
if(status=='Reset'){
secInterval =0;
minutes = 0;
getSeconds =0;
}
if(secInterval == 0){
secInterval = 60;
}
if(getSeconds == secInterval){
secInterval = secInterval + 60;
++minutes;
}
if(getSeconds > 59){
subValue = secInterval - 60;
} else {
subValue =0;
}
Seconds = getSeconds - subValue;
if(Seconds <= 9){
Seconds = '0'+Seconds;
}
if(minutes == 1 && Seconds == 22){
NextPlay = nextPlay();
alert('Next Play: ' + tracks[NextPlay][1] + ' - ' + tracks[NextPlay][2]);
}
currentvideoTime = minutes + ':' + Seconds;
$('.VideoTime').text(currentvideoTime);
if(currentvideoTime >= tracks[PlaylistIdentifier['Number']][2]){
var PlaylistNumber = tracks.length - 1;
if(PlaylistIdentifier['Number'] < PlaylistNumber){
onYouTubePlayerReady('ytplayer', NextPlay);
if(tracks[NextPlay][0] == 1){
getPlaylistDetails(getPlaylist()[NextPlay], 'videoPlay');
} else {
player.pauseVideo();
}
minutes = 0;
secInterval =0;
Seconds =0;
} else {
clearInterval(myTimer);
}
}
});
}
function setInterVal(){
var myTimer = setInterval(getCurrentTime, 1000);
var videoLyrics = setInterval(VideoTime, 1000);
}
</script>
</html>