-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript2.js
76 lines (66 loc) · 2.89 KB
/
script2.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
///intilisation of songs
let myprogressBar =document.getElementById('myprogressBar');
let audioElement= new Audio('songs/10.mp3');
let masterplay=document.getElementById('masterplay');
let gif=document.getElementById('gif');
let songitems=Array.from(document.getElementsByClassName('songitem'));
let songIndex=0;
let songs=[
{songName:"let me love you",filepath:"songs/1.mp3" ,coverPath:"covers/1.jpg" },
{songName:" Alone",filepath:"songs/2.mp3" ,coverPath:"covers/2.jpg" },
{songName:"Unstoppable",filepath:"songs/3.mp3" ,coverPath:"covers/3.jpg" },
{songName:"Darkside",filepath:"songs/4.mp3" ,coverPath:"covers/4.jpg" },
{songName:"Don't say good bye",filepath:"songs/5.mp3" ,coverPath:"covers/5.jpg" },
{songName:"hall of fame ",filepath:"songs/6.mp3" ,coverPath:"covers/6.jpg" },
{songName:"in to your arms ",filepath:"songs/7.mp3" ,coverPath:"covers/7.jpg" },
{songName:"love me like you do ",filepath:"songs/8.mp3" ,coverPath:"covers/8.jpg" },
{songName:"peaky blinder",filepath:"songs/9.mp3" ,coverPath:"covers/9.jpg" },
{songName:"worriyo mortals",filepath:"songs/10.mp3" ,coverPath:"covers/10.jpg" },
];
songitems.forEach((element,i)=>{
console.log(element,i);
element.getElementsByTagName("img")[0].src=songs[i].coverPath;
element.getElementsByClassName("songName")[0].innerText=songs[i].songName;
})
masterplay.addEventListener('click',()=>{
if(audioElement.paused||audioElement.currentTime<=0){
audioElement.play();
masterplay.classList.remove('fa-play-circle');
masterplay.classList.add('fa-pause-circle');
gif.style.opacity=1;
}
else{
audioElement.pause();
masterplay.classList.remove('fa-pause-circle');
masterplay.classList.add('fa-play-circle');
gif.style.opacity=0;
}
})
audioElement.addEventListener('timeupdate',()=>{
//console.log('timeupdate');
progress= parseInt((audioElement.currentTime/audioElement.duration)*100)
//console.log(progress);
myprogressBar.value=progress;
})
myprogressBar.addEventListener('change',()=>{
audioElement.currentTime=myprogressBar.value*audioElement.duration/100;
})
const makeAllplays=()=>{
Array.from(document.getElementsByClassName('songitemplay')).forEach((element)=>{
element.classList.remove('fa-pause-circle');
element.classList.add('fa-play-circle');
})
}
Array.from(document.getElementsByClassName('songitemplay')).forEach((element)=>{
element.addEventListener('click',(e)=>{
makeAllplays();
// this is targeted location index = parseInt(e.target.id);
e.target.classList.remove('fa-play-circle');
e.target.classList.add('fa-pause-circle');
audioElement.src='songs/6.mp3';
audioElement.currentTime=0;
audioElement.play();
masterplay.classList.remove('fa-play-circle');
masterplay.classList.add('fa-pause-circle');
})
})