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
|
/**
* Web Deck Player v1.0 - script file
*
* Welcome to the script file!
*
* CONTENTS:
* 1. Playlists Array
* 2. Initial Playlist
* 3. Themes
* 4. Current Theme
*/
/**
* [1. PLAYLISTS ]
* Here are the Youtube Playlists that will be available to play. To add a new one,
* first make sure that your playlist is set to 'Hidden' or 'Public' in Youtube.
*
* Then, look for the URL (for example: https://www.youtube.com/playlist?list=PLZyqOyXxaVETqpHhT_c5GPmAPzhJpJ5K7)
* and copy only the part after 'list=' (for example: PLZyqOyXxaVETqpHhT_c5GPmAPzhJpJ5K7).
* Finally, write a name for your playlist and paste the code you copied in the list below.
*
* You can also delete the lists that you don't want.
*/
var myPlaylists = {
"90s HITS": 'PLZyqOyXxaVETqpHhT_c5GPmAPzhJpJ5K7',
"00s HITS": 'PL69714D95619E327E',
"VAPORWAVE": 'PLSChV4T8EDb9TZsLO23Tsj6-UUyAXtGg5',
//"ANOTHER PLAYLIST": 'PLZyqOyXxaVETqpHhT_c5GPmAPzhJpJ5K7',
};
/**
* [2. INITIAL PLAYLIST ]
* The first playlist that the player will load on startup. You may change it by
* writing the name of the new playlist below.
*/
var currentPlaylist = "90s HITS";
/**
* [3. THEMES]
* Themes are a great way to customize the look of your player! Refer to the website
* instructions to get new themes or to know how can you create yours. Then, you may
* add them to the list below using the format ( "THEME NAME": 'theme-folder-name' ).
*
* You can also delete the themes that you don't want.
*/
var myThemes = {
"DEFAULT": 'default',
"SILVER": 'silver',
"VIOLET": "violet",
"MINIMAL": "minimal",
"RED GRUNGE": "red-grunge",
//"ANOTHER THEME": 'another-theme',
};
/**
* [4. CURRENT THEME]
* Set the theme of your player writing its name below.
*/
var currentTheme = "DEFAULT";
// ===== END OF CONFIGURATION =====
document.getElementById("player-theme").setAttribute("href", "./themes/"+ myThemes[currentTheme] + "/webdeck-player.css");
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var songLabel = document.getElementById("songLabel");
var statusLabel = document.getElementById("statusLabel");
var statusLabelInterval;
var savedVolume = 50;
var volumeButton = document.getElementById("volumeButton");
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/sound.png' alt=''>";
var volumeBar = document.getElementById("volumeBar");
var isSlidingVolumeBar = false;
var videoButton = document.getElementById("videoButton");
var isVideoShowing = true;
var logo = document.getElementById("playerLogo");
logo.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/logo.png' alt=''>";
var seekBar = document.getElementById("seekBar");
var isSlidingSeekBar = false;
var prevButton = document.getElementById("prevButton");
var playButton = document.getElementById("playButton");
var stopButton = document.getElementById("stopButton");
var nextButton = document.getElementById("nextButton");
var shuffleButton = document.getElementById("shuffleButton");
var shufflePlaylist = false;
var infoButton = document.getElementById("infoButton");
prevButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/prev.png' alt=''>";
playButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/play.png' alt=''>";
stopButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/stop.png' alt=''>";
nextButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/next.png' alt=''>";
infoButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/info.png' alt=''>";
var playlistSelector = document.getElementById("playlistSelector");
for(var key in myPlaylists){
var option = document.createElement('option');
option.value = key;
option.innerHTML = key;
playlistSelector.appendChild(option);
}
var themeSelector = document.getElementById("themeSelector");
for(var key in myThemes){
var option = document.createElement('option');
option.value = key;
option.innerHTML = key;
themeSelector.appendChild(option);
}
themeSelector.value = currentTheme;
function onYouTubeIframeAPIReady() {
player = new YT.Player('youtube-player', {
height: '100%',
width: '100%',
playerVars: {
'controls': 0,
'autoplay': 0,
'playsinline': 1,
'loop': 1
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function updateSongLabel() {
if(player.getVideoData() && player.getVideoData().title != undefined){
if(player.getVideoData().title == ""){
songLabel.innerHTML = "<b>READY</b>";
}
else{
songLabel.innerHTML = "<marquee><b>" + player.getVideoData().title + " - " + player.getVideoData().author + "</b></marquee>";
}
}else{
songLabel.innerHTML = "<b>Loading...</b>";
}
}
function updateStatusLabel() {
let statusLabelText = "";
let listText = " " + (player.getPlaylistIndex() + 1) + "/" + player.getPlaylist().length;
let timeText = "0:00/0:00";
seekBar.setAttribute("max", player.getDuration());
if(!isSlidingSeekBar){
seekBar.value = player.getCurrentTime();
}
if(!isSlidingVolumeBar){
volumeBar.value = player.getVolume();
}
switch (player.getPlayerState()) {
case -1:
statusLabelText = "Stopped";
break;
case 0:
statusLabelText = "Ended";
break;
case 1:
statusLabelText = "Playing";
break;
case 2:
statusLabelText = "Paused";
break;
case 3:
statusLabelText = "Loading... ";
break;
case 5:
statusLabelText = "Video Cued";
break;
}
timeText = formatTime(player.getCurrentTime()) + "/" + formatTime(player.getDuration());
statusLabel.innerHTML = statusLabelText + listText + " " + timeText;
if(player.getPlayerState() == 2 /* Paused */){
statusLabel.setAttribute('class', 'blink');
}
else{
statusLabel.removeAttribute('class');
}
}
function formatTime(input) {
var minutes = Math.trunc(input / 60);
var seconds = Math.trunc(input - minutes * 60);
if(seconds < 10) {
return minutes + ":0" + seconds;
}
else {
return minutes + ":" + seconds;
}
}
volumeButton.addEventListener("click", function(){
if(volumeBar.value != 0){
savedVolume = volumeBar.value;
player.setVolume(0);
volumeBar.value = 0;
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/mute.png' alt=''>";
}
else{
player.setVolume(savedVolume);
volumeBar.value = savedVolume;
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/sound.png' alt=''>";
}
});
volumeBar.addEventListener("input", function(){
isSlidingVolumeBar = true;
player.setVolume(this.value);
if(volumeBar.value == 0){
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/mute.png' alt=''>";
}
else{
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/sound.png' alt=''>";
}
});
volumeBar.addEventListener("mouseup", function(){
isSlidingVolumeBar = false;
});
videoButton.addEventListener("click", function(){
if(isVideoShowing){
document.getElementById("youtube-player").hidden = true;
isVideoShowing = false;
videoButton.setAttribute('state', 'off');
}
else{
document.getElementById("youtube-player").hidden = false;
isVideoShowing = true;
videoButton.setAttribute('state', 'on');
}
});
seekBar.addEventListener("input", function(){
isSlidingSeekBar = true;
player.seekTo(this.value);
});
seekBar.addEventListener("mouseup", function(){
isSlidingSeekBar = false;
});
playButton.addEventListener("click", function() {
if(player.getPlayerState() == 1) {
player.pauseVideo();
}
else {
player.playVideo();
}
});
stopButton.addEventListener("click", function() {
if(player.getPlayerState() == 1 || player.getPlayerState() == 2) {
player.stopVideo();
}
});
nextButton.addEventListener("click", function() {
player.nextVideo();
});
prevButton.addEventListener("click", function() {
player.previousVideo();
});
shuffleButton.addEventListener("click", function() {
if(shufflePlaylist == false){
shufflePlaylist = true;
shuffleButton.setAttribute('state', 'on');
}
else{
shufflePlaylist = false;
shuffleButton.setAttribute('state', 'off');
}
player.setShuffle(shufflePlaylist);
});
infoButton.addEventListener("click", function() {
alert("Webdeck Player - created by Genos\ngit.xgenos.me/webdeck-player\n(c) MIT License");
});
playlistSelector.addEventListener("change", function() {
currentPlaylist = playlistSelector.value;
player.stopVideo();
player.loadPlaylist({ list: myPlaylists[currentPlaylist] });
});
themeSelector.addEventListener("change", function() {
currentTheme = themeSelector.value;
document.getElementById("player-theme").setAttribute("href", "./themes/"+ myThemes[currentTheme] + "/webdeck-player.css");
volumeButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/sound.png' alt=''>";
prevButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/prev.png' alt=''>";
playButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/play.png' alt=''>";
stopButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/stop.png' alt=''>";
nextButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/next.png' alt=''>";
infoButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/info.png' alt=''>";
});
function onPlayerReady(event) {
player.loadPlaylist({ list: myPlaylists[currentPlaylist] });
player.setVolume(50);
player.setLoop(true);
}
function onPlayerStateChange(event) {
//Change play/pause button icons
if(player.getPlayerState() == 1 /* Playing */) {
playButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/pause.png' alt=''>";
}
else {
playButton.innerHTML = "<img src='./themes/" + myThemes[currentTheme] + "/images/play.png' alt=''>";
}
//Load next video
if (event.data == YT.PlayerState.ENDED) {
player.nextVideo();
}
updateSongLabel();
clearInterval(statusLabelInterval);
statusLabelInterval = setInterval(updateStatusLabel, 100);
}
|