-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (54 loc) · 1.42 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
const play = document.getElementById("play");
const music = document.querySelector("audio");
const img = document.querySelector("img");
const title = document.getElementById("title");
const artist = document.getElementById("artist");
const prev = document.getElementById("prev");
const next = document.getElementById("next");
const songs = [
{
title: "Comethru",
artist: "Jeremy Zucker",
image: "img00",
track: "track00",
},
{
title: "Make you mine",
artist: "Public - The Band",
image: "img01",
track: "track01",
},
];
let isPlaying = false;
let songNumber = 0;
const playMusic = () => {
isPlaying = true;
music.play();
play.classList.replace("fa-play", "fa-pause");
img.classList.add("anime");
};
const pauseMusic = () => {
isPlaying = false;
music.pause();
play.classList.replace("fa-pause", "fa-play");
img.classList.remove("anime");
};
play.addEventListener("click", () => {
isPlaying ? pauseMusic() : playMusic();
});
const loadSong = (song) => {
title.textContent = song.title;
artist.textContent = song.artist;
music.src = "Music/" + song.track + ".mp3";
img.src = "Images/" + song.image + ".jpg";
};
next.addEventListener("click", () => {
++songNumber;
loadSong(songs[songNumber % songs.length]);
playMusic();
});
prev.addEventListener("click", () => {
songNumber = songNumber - 1 + songs.length;
loadSong(songs[songNumber % songs.length]);
playMusic();
});