Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  42] [ 4]  / answers: 1 / hits: 32284  / 11 Years ago, tue, november 5, 2013, 12:00:00

I have 10 audio players with simple html audio tags on a html5 page.
No jquery, no special audio js plugins, etc...



Does anyone has a simple script in js to pause all other players when the current player is playing ?



I don't want to use js plugins because i want to keep a simple audio html code.


More From » html

 Answers
9

you can use event delegation. Simply listen to the play event in the capturing phase and then pause all video file, but not the target one:



document.addEventListener('play', function(e){
var audios = document.getElementsByTagName('audio');
for(var i = 0, len = audios.length; i < len;i++){
if(audios[i] != e.target){
audios[i].pause();
}
}
}, true);

[#74496] Monday, November 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deiong

Total Points: 15
Total Questions: 103
Total Answers: 99

Location: Sudan
Member since Thu, May 7, 2020
4 Years ago
deiong questions
Mon, Nov 22, 21, 00:00, 3 Years ago
Tue, Jun 15, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 4 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
;