-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (56 loc) · 2.14 KB
/
Copy pathscript.js
File metadata and controls
63 lines (56 loc) · 2.14 KB
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
// Reference to audio player element
const audioPlayer = document.getElementById('audio-player');
const playBtn = document.getElementById('play-btn');
const pauseBtn = document.getElementById('pause-btn');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const songList = document.getElementById('song-list');
const songTitle = document.getElementById('song-title');
const albumArt = document.getElementById('album-art'); // Album art element
const albumCOVER = document.getElementById('album-COVER');
// Playlist array (with song titles, source, and album image)
const songs = [
{ title: "Song 1", src: "v1.mpeg", img: "song1-album.png" },
{ title: "Song 2", src: "v2.mpeg", img: "song2-album.png" },
{ title: "Song 3", src: "v3.mpeg", img: "song3-album.png" }
];
let currentSongIndex = 0;
// Function to load a selected song
function loadSong(songIndex) {
const song = songs[songIndex];
songTitle.textContent = song.title;
audioPlayer.src = song.src;
albumArt.src = song.img; // Update album art image
audioPlayer.play();
playBtn.style.display = 'none';
pauseBtn.style.display = 'inline';
}
// Play the current song
playBtn.addEventListener('click', () => {
audioPlayer.play();
playBtn.style.display = 'none';
pauseBtn.style.display = 'inline';
});
// Pause the current song
pauseBtn.addEventListener('click', () => {
audioPlayer.pause();
playBtn.style.display = 'inline';
pauseBtn.style.display = 'none';
});
// Skip to the next song
nextBtn.addEventListener('click', () => {
currentSongIndex = (currentSongIndex + 1) % songs.length;
loadSong(currentSongIndex);
});
// Skip to the previous song
prevBtn.addEventListener('click', () => {
currentSongIndex = (currentSongIndex - 1 + songs.length) % songs.length;
loadSong(currentSongIndex);
});
// Play a song when clicked from the playlist
songList.addEventListener('click', (e) => {
if (e.target.tagName === 'LI') {
currentSongIndex = [...songList.children].indexOf(e.target);
loadSong(currentSongIndex);
}
});