JAYASWAROOP commited on
Commit
ae8f9a8
1 Parent(s): b45ae19

Update audio.js

Browse files
Files changed (1) hide show
  1. audio.js +36 -36
audio.js CHANGED
@@ -1,40 +1,40 @@
1
- // Get all the add-to-playlist buttons
2
- const addToPlaylistButtons = document.querySelectorAll('.add-to-playlist');
3
-
4
- // Add event listener to each button
5
- addToPlaylistButtons.forEach(button => {
6
- button.addEventListener('click', function() {
7
- // Get the song details
8
- const songCard = this.closest('.movie');
9
- const songTitle = songCard.querySelector('.title').textContent;
10
- const songDescription = songCard.querySelector('.description').textContent;
11
- const songSrc = songCard.querySelector('source').getAttribute('src');
12
-
13
- // Create a new list item element
14
- const newSongItem = document.createElement('li');
15
- newSongItem.classList.add('song-item', 'row');
16
-
17
- // Create the song item content
18
- const songItemContent = `
19
- <div class="song-details col-10 col-md-11">
20
- <p class="song-title">${songTitle}</p>
21
- <p class="song-artist">${songDescription}</p>
22
- </div>
23
- `;
24
-
25
- // Set the content of the new list item
26
- newSongItem.innerHTML = songItemContent;
27
-
28
- // Append the new song item to the playlist
29
- const playlist = document.querySelector('.song-list');
30
- playlist.appendChild(newSongItem);
31
 
32
- // Update the audio source and display the audio player
33
- const audioPlayer = document.querySelector('#audio');
34
- audioPlayer.querySelector('source').setAttribute('src', songSrc);
35
- audioPlayer.classList.remove('d-none');
36
- });
37
- });
 
 
 
 
38
 
39
 
40
  function validateSignup() {
 
1
+ function addToPlaylist() {
2
+ // Get information about the song
3
+ const songTitle = document.querySelector('.title').innerText;
4
+ const artist = 'Singer Name'; // You can replace this with the actual artist name
5
+ const audioSource = document.querySelector('#audio source').getAttribute('src');
6
+
7
+ // Create elements for the new song in the playlist
8
+ const playlist = document.querySelector('.playlist');
9
+
10
+ const newSongDiv = document.createElement('div');
11
+ newSongDiv.classList.add('song1');
12
+
13
+ const newSongTitle = document.createElement('h3');
14
+ newSongTitle.textContent = songTitle;
15
+
16
+ const newArtist = document.createElement('p');
17
+ newArtist.textContent = `Artist: ${artist}`;
18
+
19
+ const newAudio = document.createElement('audio');
20
+ newAudio.setAttribute('controls', '');
21
+
22
+ const audioSourceElem = document.createElement('source');
23
+ audioSourceElem.setAttribute('src', audioSource);
24
+ audioSourceElem.setAttribute('type', 'audio/mpeg');
25
+
26
+ newAudio.appendChild(audioSourceElem);
 
 
 
 
27
 
28
+ newSongDiv.appendChild(newSongTitle);
29
+ newSongDiv.appendChild(newArtist);
30
+ newSongDiv.appendChild(newAudio);
31
+
32
+ // Add the new song to the playlist
33
+ playlist.appendChild(newSongDiv);
34
+ }
35
+
36
+
37
+
38
 
39
 
40
  function validateSignup() {