-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
79 lines (59 loc) · 1.84 KB
/
script.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
const songs = [
"Shiddat Title Track.mp3",
"Andaz-Zindagi Ek Safar Hai.mp3",
"Believer Mp3 Imagine Dragons.mp3",
"bijlee-bijlee-harrdy-sandhu.mp3",
"Raataan Lambiyan.mp3",
"Rockabye.mp3",
"Sajna.mp3",
"Parshawan.mp3",
"Srivalli.mp3",
"Dekhte-Dekhte.mp3",
"Tera Mera Viah.mp3",
];
const player = document.getElementById("player");
const createSongList = () => {
const list = document.createElement("ol");
for (let i = 0; i < songs.length; i++) {
const item = document.createElement("li");
item.appendChild(document.createTextNode(songs[i]));
list.appendChild(item);
}
return list;
};
const songList = document.getElementById("songList");
songList.appendChild(createSongList());
const links = document.querySelectorAll("li");
for (const link of links) {
link.addEventListener("click", setSong);
}
function setSong(e) {
document.querySelector("#headphones").classList.remove("pulse");
const source = document.getElementById("source");
document.getElementById(
"currentSong"
).innerText = `Now Playing: ${e.target.innerText}`;
source.src = "songs/" + e.target.innerText;
player.load();
player.play();
document.querySelector("#headphones").classList.add("pulse");
};
function playAudio() {
if (player.readyState) {
player.play();
}
}
function pauseAudio() {
player.pause();
}
const slider = document.getElementById("volumeSlider");
slider.oninput = function (e) {
const volume = e.target.value;
player.volume = volume;
};
function updateProgress() {
if (player.currentTime > 0) {
const progressBar = document.getElementById("progress");
progressBar.value = (player.currentTime / player.duration) * 100;
}
}