4 Replies Latest reply on Mar 6, 2016 5:06 PM by dreaminkiss

    Edge Animate, Working with multiple audio tracks

    Ruffus999

      I'm having trouble with one of my animations.

       

      I have set up 8 animated symbols that will play when the user hovers over the symbol.

      When the user clicks on a symbol it will play an audio mp3 files.

       

      // insert code for mouse click here

      // Sets a toggle to play or pause the audio track

      var audio = sym.$("_1")[0];                            "_1" is the name of the audio file that is placed on the timeline.  The original MP3 file is named 1 but when it was dragged to the canvas it created a layer called "_1".

      if (audio.paused) {

        audio.play();

      } else {

        audio.pause();

      }

       

      But there are two problems, one more concerning than the other.

      The problems are below:

       

      I can not figure out the code to stop the audio when the symbol is clicked again instead of it being paused.  I tried to change audio.pause to audio.stop.  That did not help.  I would like the audio to stop if clicked again and then play from the beginning if clicked one more time.

       

      This is the one that I am most concerned about.  If the user clicks on one symbol, the audio for that symbol will start to play as intended.  But if the user clicks on a second symbol, the audio for that symbol will start to play in conjunction with the audio already playing from the previous symbol.  It would be nice if a user could click on one symbol it will start to play its audio but if they change their mind and click on another symbol, the playing audio will stop and the new clicked symbol will start to play its audio.

       

      Anyone have any suggestions?  Or help to provide.  Thanks in advance.

        • 1. Re: Edge Animate, Working with multiple audio tracks
          jbowden Adobe Employee

          Hi there,

           

          One quick answer to your question, and another that I will follow up on when I get a few minutes.

           

          Animate uses the HTML5 audio API to control audio elements, so you can only use methods and properties that are specified for audio elements in HTML5 browsers.

           

          To "stop" audio, you need to pause it and then set its currentTime property to 0, like so:

           

          sym.$("your_audio_element")[0].pause();

          sym.$("your_audio_element")[0].currentTime = 0;


          The next time you play this audio element, it will play back from the beginning.


          The other part of your question (stopping other playing audio when another symbol audio starts playing) can be done by getting all instances of the audio tag in jQuery and then pausing all audio. I don't have the exact syntax for that at hand as I reply, but I'll respond back with it soon.


          hth,

          Joe


          • 2. Re: Edge Animate, Working with multiple audio tracks
            jbowden Adobe Employee

            …Pt 2:

             

            You can control audio at the tag level using jQuery - this allows you to issue a single command that affects all audio elements in the composition.

             

            So if you want to "stop" all audio from playing and then play the one in your symbol, you could do it this way:

             

            // these commands affect ALL audio elements in the composition

            $("audio").trigger("pause");

            $("audio").prop("currentTime", 0);


            // this applies only to the audio element you want to play

            sym.$("your_audio_element")[0].play();


            hth,

            Joe

            • 3. Re: Edge Animate, Working with multiple audio tracks
              Ruffus999 Level 1

              Thank you so much for this.  I just tested and it does exactly what I was looking for.  Again, thank you for you quick and effective response.

              • 4. Re: Edge Animate, Working with multiple audio tracks
                dreaminkiss Level 1

                jbowden and Ruffus999

                 

                I have similar question up.

                https://forums.adobe.com/message/8557048

                 

                The issue is that I am unable to stop the other audio from playing.

                Even using the $("audio").trigger("pause");

                Does not seem to work.

                 

                Could you please have a look at the example codes in the question, and assist if you can please.

                 

                Thank You

                Wayne