5 Replies Latest reply on Apr 28, 2014 9:50 AM by SXM132

    Key up Audio Stop

    SXM132

      I'm making an interactive piano tutorial, and I have a strings scale attached to the key down of several keys. Here is an example of one key down;

       

      if (e.which == 65) {  //A

                var getShot = sym.getSymbol("soundtestA").getSymbol("Asound");

                getShot.play("A");

      }

       

      It works fine, but upon lift it keeps playing through - making the notes slow and delayed.

       

      I'm not too code savy. How can I link the key up to either pause or stop the sound bite?

        • 1. Re: Key up Audio Stop
          Zaxist Level 4

          you can do it this way :

           

          //in Stage > compositionReady

           

          music = sym.$("MusicFileName")[0];

           

           

          //in keydown

           

          if (e.which == 65) {

                    music.play();

          }

           

          //in keyup

           

          if (e.which == 65) {

                    music.pause();

                    music.currentTime = 0;

          }

           

           

          Hope this can help you

          if you had any question let me know ..

           

          regards

          Zaxist

          • 2. Re: Key up Audio Stop
            SXM132 Level 1

            Can you define what you mean by "MusicFileName"?
            Is it the symbol it's in or the actual .WAV file name?

             

            Either way, I've tried using both but neither work =/ Good guess though

            • 3. Re: Key up Audio Stop
              Zaxist Level 4

              in your Project as i can see you named it Asound

               

              so your music line should be like this

               

              music = sym.getSymbol("soundtestA").$("Asound")[0];

               

               

              Hope this can help you

               

              regards

              Zaxist

              1 person found this helpful
              • 4. Re: Key up Audio Stop
                Sudeshnasarkar27 Adobe Employee

                Hi ,

                 

                I am sharing a sample for playing audio as long as say "a" is pressed and on keyup it would stop the audio.

                Basically , on my stage keyup the code is -

                 

                if (e.which == 65)

                {

                          sym.$("mysong")[0].muted = true;

                          console.log("Keyup for A");

                          sym.$("mysong")[0].stop();

                }

                 

                and on stage keydown it is -

                if (e.which == 65)

                {

                          sym.$("mysong")[0].muted = false;

                          console.log("Keydown for A"); 

                          // Play an audio track

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

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

                }

                 

                where "mysong" is the song element.

                 

                Let me know if that solves your problem.

                 

                Thanks and Regards,

                Sudeshna Sarkar

                1 person found this helpful
                • 5. Re: Key up Audio Stop
                  SXM132 Level 1

                  As far as functionality goes this solves the problem. It make a new one, however.

                  After pressing key down for a while the audio begins to jitter horribly. Can this be fixed by adjusting the code's timing cues?