1 Reply Latest reply on Aug 30, 2016 4:12 AM by Nipun Asthana

    Reg: Problem with adding sound

    pvk86 Level 1

      Hi,

       

          I am new to html5 canvas using flash cc. I am adding sound effect (mp3). And I am going to do play pause control. 

       

      Code :

        

      _main = this; 

       

      this.stop(); 

       

      createjs.Sound.on("fileload", handleLoad); 

      createjs.Sound.registerSound("song.mp3", "soundID"); 

      function handleLoad(event) { 

          _main.audio1 = createjs.Sound.play("soundID"); 

          _main.play(); 

      }

       

      I got error

      Uncaught TypeError: Cannot read property 'on' of undefined.

       

      Need to add any plugins or not.

       

      Please Explain how to add sound and play pause control.

       

      Thanks in advance..

        • 1. Re: Reg: Problem with adding sound
          Nipun Asthana Adobe Employee

          Canvas publishing in Animate already takes care of loading and playing an audio file.

          To simulate play/pause/stop buttons on an audio, you can use the following snippet:

           

          //Create three movieclips/buttons with instance names: play_btn, pause_btn, stop_btn

          //Import the audio in library and give it a linkage name 'AudioLinkageName' by double clicking on the linkage column in library.

          //Add the following code in your first frame and Test Movie (Ctrl + Enter)

           

          this.play_btn.on("click", function (e) {

            if(!this.s1)

            this.s1 = playSound("AudioLinkageName");

            else

            this.s1.play();

          }.bind(this));

           

           

          this.pause_btn.on("click", function (e) {

            if(this.s1)

            this.s1.paused=true;

          }.bind(this));

           

           

          this.stop_btn.on("click", function (e) {

            if(this.s1)

            this.s1.stop();

          }.bind(this));