2 Replies Latest reply on Jul 13, 2014 8:14 PM by Blokeish

    managing multiple audio with one toggle button

    resdesign Adobe Community Professional & MVP

      My turn today to ask a question.

       

      I have a complicated animation in which i have several sound FX that start at different points on the timeline. I would like to have a toggle button for all sound FX. I created an array and I can stop all the sounds without any problem but I am not sure how I would then toggle all the sounds back so they could become playable again  but without playing since I do not want to play them all at the same time.

      I though about using the mute toggle also but it seems that you cannot mute a sound that is not playing if that makes sense.

        • 1. Re: managing multiple audio with one toggle button
          sarhunt Adobe Employee

          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

          1 person found this helpful
          • 2. Re: managing multiple audio with one toggle button
            Blokeish Level 1

            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