JAYASWAROOP commited on
Commit
0648934
1 Parent(s): 1ade524

Update audio.js

Browse files
Files changed (1) hide show
  1. audio.js +22 -17
audio.js CHANGED
@@ -1,23 +1,28 @@
1
- // Wait for the document to load
2
  document.addEventListener('DOMContentLoaded', function () {
3
- // Get all the song containers
4
- const songContainers = document.querySelectorAll('.movie');
5
 
6
- // Attach a click event listener to each song container
7
- songContainers.forEach(function (container) {
8
- container.addEventListener('click', function () {
9
- const audio = this.querySelector('audio'); // Get the audio element inside the container
10
 
11
- // Toggle the visibility of the audio element
12
- audio.classList.toggle('d-none');
13
-
14
- // Check if the audio is playing or paused, and toggle play/pause accordingly
15
- if (audio.paused) {
16
- audio.play(); // Play the audio if it's paused
17
- } else {
18
- audio.pause(); // Pause the audio if it's playing
19
  }
20
  });
21
- });
22
- });
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  document.addEventListener('DOMContentLoaded', function () {
2
+ const movieContainers = document.querySelectorAll('.movie');
 
3
 
4
+ movieContainers.forEach(function (container) {
5
+ container.addEventListener('click', function () {
6
+ const audio = this.querySelector('audio');
 
7
 
8
+ // Pause all other audio elements except the one clicked
9
+ movieContainers.forEach(function (otherContainer) {
10
+ const otherAudio = otherContainer.querySelector('audio');
11
+ if (otherAudio !== audio && !otherAudio.paused) {
12
+ otherAudio.pause();
13
+ otherAudio.classList.add('d-none');
 
 
14
  }
15
  });
 
 
16
 
17
+ // Play or pause the audio based on its current state
18
+ if (audio.paused) {
19
+ audio.play();
20
+ } else {
21
+ audio.pause();
22
+ }
23
+
24
+ // Toggle the display of the audio element
25
+ audio.classList.toggle('d-none');
26
+ });
27
+ });
28
+ });