-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplayer.js
69 lines (49 loc) · 1.92 KB
/
player.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
var songs = ["songs/song1.mp3","songs/song2.mp3","songs/song3.mp3","songs/song4.mp3","songs/song5.mp3","songs/song6.mp3","songs/song7.mp3","songs/song8.mp3","songs/song9.mp3","songs/song10.mp3","songs/song11.mp3","songs/song12.mp3"];
var poster = ["images/hero1.jpg","images/hero2.jpg","images/hero3.jpg","images/hero4.jpg","images/hero5.jpg","images/m1.jpg","images/m2.png","images/m3.jpg"];
var songTitle = document.getElementById("songTitle");
var fillBar = document.getElementById("fill");
var song = new Audio();
var currentSong = 0; //it points to the Current Song
window.onload = playSong(); // Call Function Play Song when window is loaded
function playSong() {
song.src = songs[currentSong]; //set the source of the 0th song
songTitle.textContent = songs[currentSong]; //set the title of the song
song.play();
}
function playOrPauseSong(){
if(song.paused){
song.play();
$("#play img").attr("src","images/pause.png");
}
else{
song.pause();
$("#play img").attr("src","images/play.png");
}
}
song.addEventListener('timeupdate',function(){
var position = song.currentTime / song.duration;
fillBar.style.width = position * 90 +'%';
});
function seek(){
song.currentTime = Math.random()*song.duration;
}
function next(){
currentSong++;
if(currentSong > 12){
currentSong = 0;
}
playSong();
$("#play img").attr("src","images/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","images/pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}