Spaces:
Running
Running
JAYASWAROOP
commited on
Commit
•
0648934
1
Parent(s):
1ade524
Update audio.js
Browse files
audio.js
CHANGED
@@ -1,23 +1,28 @@
|
|
1 |
-
// Wait for the document to load
|
2 |
document.addEventListener('DOMContentLoaded', function () {
|
3 |
-
|
4 |
-
const songContainers = document.querySelectorAll('.movie');
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
const audio = this.querySelector('audio'); // Get the audio element inside the container
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 |
+
});
|