-
1. Re: managing multiple audio with one toggle button
sarhunt Mar 16, 2014 8:04 PM (in response to resdesign)Hey Marie,
I tried approaching this from a few different angles and unfortunately couldn't get it to work Bumping to the top in case anyone smarter than me has a solution...
Sarah
Edit: HA! HAHAHA! Take that Javascript. I think I found an answer...
Try this:
myAud=document.getElementsByTagName("audio");
for(var i=0; i<myAud.length; i++)
myAud[i].muted=true;
This will get all of the documents audio elements and mute them - will setting up another button with muted=false work for the toggle?
Sarah
-
2. Re: managing multiple audio with one toggle button
Blokeish Jul 13, 2014 8:14 PM (in response to resdesign)Hi Marie,
This is a function that I use to stop all audio on the stage. You should be able to modify it to suit your need. What you have to watch-out for is that when you toggle (play) there is a chance for all the audio on the stage to play. Probably you will have to check the 'currentTime' property as well. Muting is not a solution as it will continue to play the sound silently.
function stopAllAudio(){
$.each(sym.$("audio"), function(index, value) {
if(!$(this)[0].paused){
$(this)[0].pause();
$(this)[0].currentTime = 0;
}
});
}
your solution would look something like this. You might require a global variable to record the playback status. Since you have multiple audios relying on its status may not be a good idea. You will have to tweak this.
var isPaused = false;
function toggleAllAudio(){
isPaused = !isPaused;
$.each(sym.$("audio"), function(index, value) {
if(isPaused && $(this)[0].paused){
$(this)[0].play();
else
$(this)[0].pause();
});
}
reference: HTML Audio/Video DOM Reference




