2 Replies Latest reply on Jun 2, 2016 5:53 AM by rahimhaji

    Play pause an audio in Animate CC

    rahimhaji Level 1

      Dear Friends,

       

      Iam creating an elearning lesson in Animate CC. in that I need to add play pause for movie as well as audio. Iam using the following code, here pause is working, but when iam playing movie is playing but the audio is playing from starting not from the place where it stopped.

       

      var assetsPath = "./assets/";
      var snd_start = 0;
      var pause = false;

      var sounds = [{
      src: "objective.mp3",
      data: {
        audioSprite: [{
         id: "sound1",
         startTime: snd_start
        }]
      }
      }];

      createjs.Sound.alternateExtensions = ["mp3"];
      createjs.Sound.on("fileload", loadSound);
      createjs.Sound.registerSounds(sounds, assetsPath);

      // after load is complete
      function loadSound(e) {
      }


      _this = this;
      this.pause_but.addEventListener("click", pause_click);
      function pause_click(event) {
      if (pause) {
        snd_start = _this.currentFrame * 24;
        _this.play();
        createjs.Sound.play("sound1");
        pause = false;
      } else {
        createjs.Sound.stop();
        _this.stop();
        pause = true;
      }
      }

       

      Please check my above code and correct me if I made any mistake. The logic here I used is I have store the sopping position and multiplying it by frame rate 24 and trying to play the audio from that position by keeping a variable snd_start (sound start time).

       

      Thanks in advance,

      Syed Abdul Rahim