-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic-player.html
76 lines (68 loc) · 2.43 KB
/
music-player.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Player</title>
<link rel="stylesheet" href="music-player.css">
</head>
<body>
<div class="container">
<div class="music-player">
<nav>
<div class="circle">
<i class="fa-solid fa-angle-left"></i>
</div>
<div class="circle">
<i class="fa-solid fa-bars"></i>
</div>
</nav>
<img src="images/468-thumbnail.png" class="song-img">
<h1>Despacito</h1>
<p>Luis Fonsi Ft Puerto Ricon</p>
<audio controls id="song">
<source src="Audio/Luis Fonsi feat. Daddy Yankee - Despacito (Official Music Video).mp3" type="audio/mpeg">
</audio>
<input type="range" value="0" id="progress">
<div class="controls">
<div><i class="fa-solid fa-backward"></i></div>
<div onclick="playPause()"><i class="fa-solid fa-play" id="ctrlIcon" ></i></div>
<div><i class="fa-solid fa-forward"></i></div>
</div>
</div>
</div>
<script src="https://kit.fontawesome.com/113c86a1e5.js" crossorigin="anonymous"></script>
<script>
let progress = document.getElementById('progress');
let song = document.getElementById('song');
let ctrlIcon = document.getElementById('ctrlIcon');
song.onloadedmetadata = function(){
progress.max = song.duration;
progress.value = song.currentTime;
}
function playPause() {
if(ctrlIcon.classList.contains("fa-pause")){
song.pause();
ctrlIcon.classList.remove("fa-pause");
ctrlIcon.classList.add("fa-play");
}
else {
song.play();
ctrlIcon.classList.add("fa-pause");
ctrlIcon.classList.remove("fa-play");
}
}
if(song.play()){
setInterval(()=>{
progress.value = song.currentTime;
},500);
}
progess.onchange = function(){
song.play();
song.currentTime = progress.value;
ctrlIcon.classList.add("fa-pause");
ctrlIcon.classList.remove("fa-play");
}
</script>
</body>
</html>