-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.js
90 lines (75 loc) · 2.43 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var songs = ['BERA - Untouchable (Filatov And Karas Remix).mp3',
'BERA - Untouchable (Jyye Remix).mp3',
'Enrique Iglesias ft. Descemer Bueno, Zion & Lennox - SUBEME LA RADIO Animated Lyric Video .mp3',
'Luis Fonsi Ft. Daddy Yankee - Despacito.mp3'];
var songTitle = document.getElementById('songTitle');
var songSlider = document.getElementById('songSlider');
var currentTime = document.getElementById('currentTime');
var duration = document.getElementById('duration');
var volumeSlider = document.getElementById('volumeSlider');
var nextSongTitle = document.getElementById('nextSongTime');
var song = new Audio();
var currentSong = 0;
window.onload = loadSong;
function loadSong () {
song.src = "songs/" + songs[currentSong];
songTitle.textContent = (currentSong + 1) + ". " + songs[currentSong];
nextSongTitle.innerHTML = "<b>Next Song: </b>" + songs[currentSong + 1 % songs.length];
song.playbackRate = 1;
song.volume = volumeSlider.value;
song.play();
setTimeout(showDuration, 1000);
}
setInterval(updateSongSlider, 1000);
function updateSongSlider() {
var c = Math.round(song.currentTime);
songSlider.value = c;
currentTime.textContent = convertTime(c);
if (song.ended) {
next();
}
}
function convertTime (secs) {
var min = Math.floor(secs/60);
var sec = secs % 60;
min = (min < 10) ? '0' + min : min;
sec = (sec < 10) ? '0' + sec : sec;
return (min + ':' + sec);
}
function showDuration () {
var d = Math.floor(song.duration);
songSlider.setAttribute('max', d);
duration.textContent = convertTime(d);
}
function playOrPauseSong (img) {
song.playbackRate = 1;
if (song.paused) {
song.play();
img.src = 'images/pause.png';
} else {
song.pause();
img.src = 'images/play.png';
}
}
function next() {
currentSong = currentSong + 1 % songs.length;
loadSong();
}
function previous() {
currentSong--;
currentSong = (currentSong < 0) ? songs.length - 1 : currentSong;
loadSong();
}
function seekSong () {
song.currentTime = songSlider.value;
currentTime.textContent = convertTime(song.currentTime);
}
function adjustVolume () {
song.volume = volumeSlider.value;
}
function increasePlaybackRate () {
songs.playbackRate += 0.5;
}
function decreasePlaybackRate () {
songs.playbackRate -= 0.5;
}