-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (68 loc) · 1.9 KB
/
main.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
const cover = [
'images/cover1.jpg'
];
const songs = [
'music/specialz.mp3',
'music/put.mp3',
'music/Moye Moye.mp3'
];
const currentSong = 0;
const totalSong = songs.length;
function songPlay() {
song.src = songs[currentSong];
song.play()
}
// console.log(songs)
const song = new Audio();
song.src = "music/specialz.mp3";
//console.log(song)
const play = document.querySelector("#play");
const seek = document.getElementById("seek");
const volume = document.getElementById("volume");
const next = document.getElementById("next");
const prev = document.getElementById("prev");
play.addEventListener('click', () => {
if (song.paused) {
song.play();
play.innerHTML = "Pause";
document.getElementById("image").classList.add("anime");
} else if (song.ended) {
song.currentTime = 0;
document.getElementById('image').classList.remove("anime")
} else {
song.pause();
play.innerHTML = "Play";
document.getElementById("image").classList.remove("anime");
}
});
song.addEventListener("timeupdate", function() {
seek.value = song.currentTime / song.duration;
if (seek.value == 1) {
play.innerHTML = "Play";
document.getElementById("image").classList.remove("anime");
}
// console.log(seek)
});
volume.addEventListener("change", function(e) {
song.volume = e.currentTarget.value / 100;
//console.log(e)
});
next.addEventListener("click", () => {
currentSong++;
if (currentSong > 2) {
currentSong = 0;
}
songPlay();
//song.src = songs[currentSong];
play.innerHTML = "Pause";
document.getElementById("image").classList.add("anime");
});
prev.addEventListener("click", () => {
currentSong--;
if (currentSong < 0) {
currentSong = 2;
}
songPlay();
document.getElementById("image").classList.add("anime");
play.innerHTML = "Pause";
});