-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork.js
244 lines (238 loc) · 7.96 KB
/
work.js
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
/* Music
======================================*/
var playlist = [
{
"song" : "ADM Radio",
"album" : "song collection",
"artist" : " 🖤 Song collections 🖤",
"artwork" : "https://telegra.ph/file/6deb0b73ca49e05589b73.jpg",
"mp3" : "https://node-34.zeno.fm/x6gu78qhvf9uv?rj-ttl=5&rj-tok=AAABfe0IHL8A1x_URZTHZvMrLQ"
},
];
/* General Load / Variables
======================================*/
var rot = 0;
var duration;
var playPercent;
var rotate_timer;
var armrot = -45;
var bufferPercent;
var currentSong = 0;
var arm_rotate_timer;
var arm = document.getElementById("arm");
var song = document.getElementById("song");
var timer = document.getElementById("timer");
var music = document.getElementById("music");
var album = document.getElementById("album");
var artist = document.getElementById("artist");
var volume = document.getElementById("volume");
var playButton = document.getElementById("play");
var timeline = document.getElementById("slider");
var playhead = document.getElementById("elapsed");
var pauseButton = document.getElementById("pause");
var bufferhead = document.getElementById("buffered");
var artwork = document.getElementsByClassName("artwork")[0];
var timelineWidth = timeline.offsetWidth - playhead.offsetWidth;
var visablevolume = document.getElementsByClassName("volume")[0];
music.addEventListener("ended", _next, false);
music.addEventListener("timeupdate", timeUpdate, false);
music.addEventListener("progress", bufferUpdate, false);
load();
/* Functions
======================================*/
function load(){
pauseButton.style.visibility = "hidden";
song.innerHTML = playlist[currentSong]['song'];
song.title = playlist[currentSong]['song'];
album.innerHTML = playlist[currentSong]['album'];
album.title = playlist[currentSong]['album'];
artist.innerHTML = playlist[currentSong]['artist'];
artist.title = playlist[currentSong]['artist'];
artwork.setAttribute("style", "background:url(https://i.imgur.com/3idGgyU.png), url('"+playlist[currentSong]['artwork']+"') center no-repeat;");
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
music.load();
}
function reset(){
rotate_reset = setInterval(function(){
Rotate();
if(rot == 0){
clearTimeout(rotate_reset);
}
}, 1);
fireEvent(pauseButton, 'click');
armrot = -45;
playhead.style.width = "0px";
bufferhead.style.width = "0px";
timer.innerHTML = "0:00";
music.innerHTML = "";
currentSong = 0; // set to first song, to stay on last song: currentSong = playlist.length - 1;
song.innerHTML = playlist[currentSong]['song'];
song.title = playlist[currentSong]['song'];
album.innerHTML = playlist[currentSong]['album'];
album.title = playlist[currentSong]['album'];
artist.innerHTML = playlist[currentSong]['artist'];
artist.title = playlist[currentSong]['artist'];
artwork.setAttribute("style", "background:url(https://i.imgur.com/3idGgyU.png), url('"+playlist[currentSong]['artwork']+"') center no-repeat;");
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
music.load();
}
function formatSecondsAsTime(secs, format) {
var hr = Math.floor(secs / 3600);
var min = Math.floor((secs - (hr * 3600))/60);
var sec = Math.floor(secs - (hr * 3600) - (min * 60));
if (sec < 10){
sec = "0" + sec;
}
return min + ':' + sec;
}
function timeUpdate() {
bufferUpdate();
playPercent = timelineWidth * (music.currentTime / duration);
playhead.style.width = playPercent + "px";
timer.innerHTML = formatSecondsAsTime(music.currentTime.toString());
}
function bufferUpdate() {
bufferPercent = timelineWidth * (music.buffered.end(0) / duration);
bufferhead.style.width = bufferPercent + "px";
}
function Rotate(){
if(rot == 361){
artwork.style.transform = 'rotate(0deg)';
rot = 0;
} else {
artwork.style.transform = 'rotate('+rot+'deg)';
rot++;
}
}
function RotateArm(){
if(armrot > -12){
arm.style.transform = 'rotate(-38deg)';
armrot = -45;
} else {
arm.style.transform = 'rotate('+armrot+'deg)';
armrot = armrot + (26 / duration);
}
}
function fireEvent(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
function _next(){
if(currentSong == playlist.length - 1){
reset();
} else {
fireEvent(next, 'click');
}
}
playButton.onclick = function() {
music.play();
}
pauseButton.onclick = function() {
music.pause();
}
music.addEventListener("play", function () {
playButton.style.visibility = "hidden";
pause.style.visibility = "visible";
rotate_timer = setInterval(function(){
if(!music.paused && !music.ended && 0 < music.currentTime){
Rotate();
}
}, 10);
if(armrot != -45){
arm.setAttribute("style", "transition: transform 800ms;");
arm.style.transform = 'rotate('+armrot+'deg)';
}
arm_rotate_timer = setInterval(function(){
if(!music.paused && !music.ended && 0 < music.currentTime){
if(armrot == -45){
arm.setAttribute("style", "transition: transform 800ms;");
arm.style.transform = 'rotate(-38deg)';
armrot = -38;
}
if(arm.style.transition != ""){
setTimeout(function(){
arm.style.transition = "";
}, 1000);
}
RotateArm();
}
}, 1000);
}, false);
music.addEventListener("pause", function () {
arm.setAttribute("style", "transition: transform 800ms;");
arm.style.transform = 'rotate(-45deg)';
playButton.style.visibility = "visible";
pause.style.visibility = "hidden";
clearTimeout(rotate_timer);
clearTimeout(arm_rotate_timer);
}, false);
next.onclick = function(){
arm.setAttribute("style", "transition: transform 800ms;");
arm.style.transform = 'rotate(-45deg)';
clearTimeout(rotate_timer);
clearTimeout(arm_rotate_timer);
playhead.style.width = "0px";
bufferhead.style.width = "0px";
timer.innerHTML = "0:00";
music.innerHTML = "";
arm.style.transform = 'rotate(-45deg)';
armrot = -45;
if((currentSong + 1) == playlist.length){
currentSong = 0;
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
} else {
currentSong++;
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
}
song.innerHTML = playlist[currentSong]['song'];
song.title = playlist[currentSong]['song'];
album.innerHTML = playlist[currentSong]['album'];
album.title = playlist[currentSong]['album'];
artist.innerHTML = playlist[currentSong]['artist'];
artist.title = playlist[currentSong]['artist'];
artwork.setAttribute("style", "transform: rotate("+rot+"deg); background:url(https://i.imgur.com/3idGgyU.png), url('"+playlist[currentSong]['artwork']+"') center no-repeat;");
music.load();
duration = music.duration;
music.play();
}
previous.onclick = function(){
arm.setAttribute("style", "transition: transform 800ms;");
arm.style.transform = 'rotate(-45deg)';
clearTimeout(rotate_timer);
clearTimeout(arm_rotate_timer);
playhead.style.width = "0px";
bufferhead.style.width = "0px";
timer.innerHTML = "0:00";
music.innerHTML = "";
arm.style.transform = 'rotate(-45deg)';
armrot = -45;
if((currentSong - 1) == -1){
currentSong = playlist.length - 1;
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
} else {
currentSong--;
music.innerHTML = '<source src="'+playlist[currentSong]['mp3']+'" type="audio/mp3">';
}
song.innerHTML = playlist[currentSong]['song'];
song.title = playlist[currentSong]['song'];
album.innerHTML = playlist[currentSong]['album'];
album.title = playlist[currentSong]['album'];
artist.innerHTML = playlist[currentSong]['artist'];
artist.title = playlist[currentSong]['artist'];
artwork.setAttribute("style", "transform: rotate("+rot+"deg); background:url(https://i.imgur.com/3idGgyU.png), url('"+playlist[currentSong]['artwork']+"') center no-repeat;");
music.load();
duration = music.duration;
music.play();
}
volume.oninput = function(){
music.volume = volume.value;
visablevolume.style.width = (80 - 11) * volume.value + "px";
}
music.addEventListener("canplay", function () {
duration = music.duration;
}, false);