Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Play or pause an Audio in createJS

Participant ,
Jun 02, 2016 Jun 02, 2016

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

TOPICS
ActionScript
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2016 Jun 02, 2016
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines