Highlighted

To work with Multiple Sounds Dynamically in HTML5 Canvas Animate CC

New Here ,
Aug 13, 2019

Copy link to clipboard

Copied

I am working in HTML5 Canvas in Animate CC 2017. I want to play more than one sounds in my project. The sounds should be dynamically called. The first sound is getting dynamically played smoothly by clicking a button; but when I am trying to call the second sound dynamically by clicking another button it is not getting played, even the first sound is also not responding by clicking the first button, once the second button has been clicked. The code used for playing the sound is:-

this.stop();

//btn1 for playing 1st sound

this.btn1.addEventListener("click", OnA.bind(this));

function OnA() {

this.gotoAndPlay(2);

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

createjs.Sound.alternateExtensions = ["ogg"];

createjs.Sound.registerSound({src:"data/expts/ee003/Armature_Resistance1.mp3", id:"sound1"});

function handleLoadComplete(event) {

createjs.Sound.play("sound1");

}

    }

//btn2 for stopping 1st sound and playing 2nd sound

this.btn2.addEventListener("click", OnB.bind(this));

function OnB() {

createjs.Sound.stop("sound1");

this.gotoAndPlay(7);

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

createjs.Sound.alternateExtensions = ["ogg"];

createjs.Sound.registerSound({src:"data/expts/ee003/Armature_Resistance2.mp3", id:"sound2"});

function handleLoadComplete(event) {

createjs.Sound.play("sound2");

}

}

Views

169

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

To work with Multiple Sounds Dynamically in HTML5 Canvas Animate CC

New Here ,
Aug 13, 2019

Copy link to clipboard

Copied

I am working in HTML5 Canvas in Animate CC 2017. I want to play more than one sounds in my project. The sounds should be dynamically called. The first sound is getting dynamically played smoothly by clicking a button; but when I am trying to call the second sound dynamically by clicking another button it is not getting played, even the first sound is also not responding by clicking the first button, once the second button has been clicked. The code used for playing the sound is:-

this.stop();

//btn1 for playing 1st sound

this.btn1.addEventListener("click", OnA.bind(this));

function OnA() {

this.gotoAndPlay(2);

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

createjs.Sound.alternateExtensions = ["ogg"];

createjs.Sound.registerSound({src:"data/expts/ee003/Armature_Resistance1.mp3", id:"sound1"});

function handleLoadComplete(event) {

createjs.Sound.play("sound1");

}

    }

//btn2 for stopping 1st sound and playing 2nd sound

this.btn2.addEventListener("click", OnB.bind(this));

function OnB() {

createjs.Sound.stop("sound1");

this.gotoAndPlay(7);

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

createjs.Sound.alternateExtensions = ["ogg"];

createjs.Sound.registerSound({src:"data/expts/ee003/Armature_Resistance2.mp3", id:"sound2"});

function handleLoadComplete(event) {

createjs.Sound.play("sound2");

}

}

Views

170

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 13, 2019 0
Adobe Community Professional ,
Aug 13, 2019

Copy link to clipboard

Copied

the first problem i see is you're not removing your sounds' fileload event listeners.  once you fix that you'll probably encounter other problems if you try to play a sound more than once.

to load and play multiple sounds, https://createjs.com/docs/soundjs/classes/Sound.html#method_registerSounds

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2019 0
New Here ,
Aug 13, 2019

Copy link to clipboard

Copied

Thankyou Sir I will try and inform you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 13, 2019 0
kglad LATEST
Adobe Community Professional ,
Aug 14, 2019

Copy link to clipboard

Copied

you're welcome.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 14, 2019 0