-
Notifications
You must be signed in to change notification settings - Fork 0
/
sartusscript.js
237 lines (196 loc) · 7.46 KB
/
sartusscript.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
function createTrackItem(index,name,duration){
var trackItem = document.createElement('div');
trackItem.setAttribute("class", "playlist-track-ctn");
trackItem.setAttribute("id", "ptc-"+index);
trackItem.setAttribute("data-index", index);
document.querySelector(".playlist-ctn").appendChild(trackItem);
var playBtnItem = document.createElement('div');
playBtnItem.setAttribute("class", "playlist-btn-play");
playBtnItem.setAttribute("id", "pbp-"+index);
document.querySelector("#ptc-"+index).appendChild(playBtnItem);
var btnImg = document.createElement('i');
btnImg.setAttribute("class", "fas fa-play");
btnImg.setAttribute("height", "40");
btnImg.setAttribute("width", "40");
btnImg.setAttribute("id", "p-img-"+index);
document.querySelector("#pbp-"+index).appendChild(btnImg);
var trackInfoItem = document.createElement('div');
trackInfoItem.setAttribute("class", "playlist-info-track");
trackInfoItem.innerHTML = name
document.querySelector("#ptc-"+index).appendChild(trackInfoItem);
var trackDurationItem = document.createElement('div');
trackDurationItem.setAttribute("class", "playlist-duration");
trackDurationItem.innerHTML = duration
document.querySelector("#ptc-"+index).appendChild(trackDurationItem);
}
var listAudio = [
{
name:"##AMEL_LARRiEUX - I_DO_TAKE##SARTU",
file:"https://github.com/ThakaRashard/bubblegumpop/raw/gh-pages/audio/Amel_Larrieux_iDoTake__SARTU_I_DO_TAKE_YOU_AS_MY_WIFE_PLEASE_RESPOND_IN_PHYSICALITY.mp3",
duration:"05:28"
},
{
name:"##HARLEM_WORLD_1981 ##TREATCHEROUS3_VS_BUSY_BEE",
file:"https://github.com/ThakaRashard/bubblegumpop/raw/gh-pages/video/KoolMoeDeevsBusyBeeStarskiDec1981HarlemWorld.mp3",
duration:"11:49"
},
{
name:"##RENé_&_Angela - ##iMAGiNARY_PLAYMATES",
file:"https://github.com/ThakaRashard/bubblegumpop/raw/gh-pages/audio/Imaginary_Playmates128kbps_RNE_and_ANGELA.mp3",
duration:"04:37"
},
{
name:"##BiG_PUN ft. FAT_JOEY_CRACK - GLAMOUR_LiFE",
file:"https://github.com/ThakaRashard/bubblegumpop/raw/gh-pages/audio/BiGPUN_GLAMOURLiFE.mp3",
duration:"04:42"
}
]
for (var i = 0; i < listAudio.length; i++) {
createTrackItem(i,listAudio[i].name,listAudio[i].duration);
}
var indexAudio = 0;
function loadNewTrack(index){
var player = document.querySelector('#source-audio')
player.src = listAudio[index].file
document.querySelector('.title').innerHTML = listAudio[index].name
this.currentAudio = document.getElementById("myAudio");
this.currentAudio.load()
this.toggleAudio()
this.updateStylePlaylist(this.indexAudio,index)
this.indexAudio = index;
}
var playListItems = document.querySelectorAll(".playlist-track-ctn");
for (let i = 0; i < playListItems.length; i++){
playListItems[i].addEventListener("click", getClickedElement.bind(this));
}
function getClickedElement(event) {
for (let i = 0; i < playListItems.length; i++){
if(playListItems[i] == event.target){
var clickedIndex = event.target.getAttribute("data-index")
if (clickedIndex == this.indexAudio ) { // alert('Same audio');
this.toggleAudio()
}else{
loadNewTrack(clickedIndex);
}
}
}
}
document.querySelector('#source-audio').src = listAudio[indexAudio].file
document.querySelector('.title').innerHTML = listAudio[indexAudio].name
var currentAudio = document.getElementById("myAudio");
currentAudio.load()
currentAudio.onloadedmetadata = function() {
document.getElementsByClassName('duration')[0].innerHTML = this.getMinutes(this.currentAudio.duration)
}.bind(this);
var interval1;
function toggleAudio() {
if (this.currentAudio.paused) {
document.querySelector('#icon-play').style.display = 'none';
document.querySelector('#icon-pause').style.display = 'block';
document.querySelector('#ptc-'+this.indexAudio).classList.add("active-track");
this.playToPause(this.indexAudio)
this.currentAudio.play();
}else{
document.querySelector('#icon-play').style.display = 'block';
document.querySelector('#icon-pause').style.display = 'none';
this.pauseToPlay(this.indexAudio)
this.currentAudio.pause();
}
}
function pauseAudio() {
this.currentAudio.pause();
clearInterval(interval1);
}
var timer = document.getElementsByClassName('timer')[0]
var barProgress = document.getElementById("myBar");
var width = 0;
function onTimeUpdate() {
var t = this.currentAudio.currentTime
timer.innerHTML = this.getMinutes(t);
this.setBarProgress();
if (this.currentAudio.ended) {
document.querySelector('#icon-play').style.display = 'block';
document.querySelector('#icon-pause').style.display = 'none';
this.pauseToPlay(this.indexAudio)
if (this.indexAudio < listAudio.length-1) {
var index = parseInt(this.indexAudio)+1
this.loadNewTrack(index)
}
}
}
function setBarProgress(){
var progress = (this.currentAudio.currentTime/this.currentAudio.duration)*100;
document.getElementById("myBar").style.width = progress + "%";
}
function getMinutes(t){
var min = parseInt(parseInt(t)/60);
var sec = parseInt(t%60);
if (sec < 10) {
sec = "0"+sec
}
if (min < 10) {
min = "0"+min
}
return min+":"+sec
}
var progressbar = document.querySelector('#myProgress')
progressbar.addEventListener("click", seek.bind(this));
function seek(event) {
var percent = event.offsetX / progressbar.offsetWidth;
this.currentAudio.currentTime = percent * this.currentAudio.duration;
barProgress.style.width = percent*100 + "%";
}
function forward(){
this.currentAudio.currentTime = this.currentAudio.currentTime + 5
this.setBarProgress();
}
function rewind(){
this.currentAudio.currentTime = this.currentAudio.currentTime - 5
this.setBarProgress();
}
function next(){
if (this.indexAudio <listAudio.length-1) {
var oldIndex = this.indexAudio
this.indexAudio++;
updateStylePlaylist(oldIndex,this.indexAudio)
this.loadNewTrack(this.indexAudio);
}
}
function previous(){
if (this.indexAudio>0) {
var oldIndex = this.indexAudio
this.indexAudio--;
updateStylePlaylist(oldIndex,this.indexAudio)
this.loadNewTrack(this.indexAudio);
}
}
function updateStylePlaylist(oldIndex,newIndex){
document.querySelector('#ptc-'+oldIndex).classList.remove("active-track");
this.pauseToPlay(oldIndex);
document.querySelector('#ptc-'+newIndex).classList.add("active-track");
this.playToPause(newIndex)
}
function playToPause(index){
var ele = document.querySelector('#p-img-'+index)
ele.classList.remove("fa-play");
ele.classList.add("fa-pause");
}
function pauseToPlay(index){
var ele = document.querySelector('#p-img-'+index)
ele.classList.remove("fa-pause");
ele.classList.add("fa-play");
}
function toggleMute(){
var btnMute = document.querySelector('#toggleMute');
var volUp = document.querySelector('#icon-vol-up');
var volMute = document.querySelector('#icon-vol-mute');
if (this.currentAudio.muted == false) {
this.currentAudio.muted = true
volUp.style.display = "none"
volMute.style.display = "block"
}else{
this.currentAudio.muted = false
volMute.style.display = "none"
volUp.style.display = "block"
}
}