-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathMusic Player.html
128 lines (77 loc) · 3.18 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html>
<head>
<link href="Main.css" rel="stylesheet"/>
<script src="jquery-1.10.2.min.js"></script>
</head>
<body>
<div id="bg">
<div id="blackLayer"></div>
<img src="Poster1.jpg"/>
</div>
<div id="main">
<div id="image">
<img src="Poster1.jpg"/>
</div>
<div id="player">
<div id="songTitle">Demo</div>
<div id="buttons">
<button id="pre" onclick="pre()"><img src="Pre.png" height="90%" width="90%"/></button>
<button id="play" onclick="playOrPauseSong()"><img src="Pause.png"/></button>
<button id="next" onclick="next()"><img src="Next.png" height="90%" width="90%"/></button>
</div>
<div id="seek-bar">
<div id="fill"></div>
<div id="handle"></div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var songs = ["Song1.mp3","Song2.mp3","Song3.mp3"];
var poster = ["Poster1.jpg","Poster2.jpg","Poster3.jpg"];
var songTitle = document.getElementById("songTitle");
var fillBar = document.getElementById("fill");
var song = new Audio();
var currentSong = 0; // it point to the current song
window.onload = playSong; // it will call the function playSong when window is load
function playSong(){
song.src = songs[currentSong]; //set the source of 0th song
songTitle.textContent = songs[currentSong]; // set the title of song
song.play(); // play the song
}
function playOrPauseSong(){
if(song.paused){
song.play();
$("#play img").attr("src","Pause.png");
}
else{
song.pause();
$("#play img").attr("src","Play.png");
}
}
song.addEventListener('timeupdate',function(){
var position = song.currentTime / song.duration;
fillBar.style.width = position * 100 +'%';
});
function next(){
currentSong++;
if(currentSong > 2){
currentSong = 0;
}
playSong();
$("#play img").attr("src","Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function pre(){
currentSong--;
if(currentSong < 0){
currentSong = 2;
}
playSong();
$("#play img").attr("src","Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
</script>
</html>