-
Notifications
You must be signed in to change notification settings - Fork 903
/
Copy pathapp.js
63 lines (52 loc) · 1.63 KB
/
app.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
const songs = [
'assets/Apna Bana Le - Arijit Singh, Sachin-Jigar.m4a',
'assets/Raah Mein Unse Mulaqat - Kumar Sanu, Alka Yagnik.m4a',
'assets/Sab Tera - Armaan Malik, Shraddha Kapoor.m4a'
// Add more songs as needed
];
let currentSongIndex = 0;
const audioPlayer = document.getElementById('audioPlayer');
const durationDisplay = document.getElementById('duration');
const seekbar = document.getElementById('seekbar');
function loadSong() {
audioPlayer.src = songs[currentSongIndex];
audioPlayer.load();
updateUI();
}
function updateUI() {
durationDisplay.textContent = formatTime(0);
seekbar.value = 0;
}
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = Math.floor(seconds % 60);
return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
}
function playPause() {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
}
function prevSong() {
currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
loadSong();
playPause();
}
function nextSong() {
currentSongIndex = (currentSongIndex + 1) % songs.length;
loadSong();
playPause();
}
function seek() {
const seekValue = seekbar.value;
const seekTime = (seekValue / 100) * audioPlayer.duration;
audioPlayer.currentTime = seekTime;
}
audioPlayer.addEventListener('timeupdate', () => {
durationDisplay.textContent = formatTime(audioPlayer.currentTime);
seekbar.value = (audioPlayer.currentTime / audioPlayer.duration) * 100;
});
audioPlayer.addEventListener('ended', nextSong);
loadSong();