Skip to main content
Participant
November 15, 2016
Answered

Play and Stop sound in HTML5 Canvas

  • November 15, 2016
  • 3 replies
  • 10547 views

Hi -
I'm having trouble figuring out the correct steps to control sound in the Actions panel.

Client wants music to start after hitting a "Play" button.
They want the music to continue playing until the viewer hits a "Replay" button.

Basically, what I need to do is figure out how to pause the previous instance of the music so it doesn't play over itself when the video replays.

.FLA attached:

valtoukatly.com/BeaconSt_WIP/beaconst.fla 2.zip

This topic has been closed for replies.
Correct answer Colin Holgate

Your example file doesn't include any sound.

The simplest solution would be to include this line in your replay code, before the this.gotoAndPlay(2) line:

createjs.Sound.stop();

3 replies

Participant
August 7, 2020

Thank you so much Colin_Holgate!!! Stopping sound in html5 canvas worked. Here is what I used

this.NextButton1.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame()
{
this.gotoAndStop("two");
createjs.Sound.stop();
}

Participating Frequently
November 19, 2020

Can someone please Share their .fla as i still cannot ge thtis to work. 

Participating Frequently
March 23, 2021

Hi.

 

The easiest way is to use the static stop method from SoundJS:

createjs.Sound.stop();

 

But if there are some sounds that must continue playing then stop each created sound individually. Like this:

var sound0 = createjs.Sound.play("LibraryLinkage0");
var sound1 = createjs.Sound.play("LibraryLinkage1");
var sound2 = createjs.Sound.play("LibraryLinkage2");

this.yourStopButton.on("click", function()
{
	sound0.stop();
	sound1.stop();
	sound2.stop();
});

 

Please let me know if you have any further questions.

 

Regards,

JC


Hi JC,

 

Thanks for your reply.

 

Each sound is in an individual HTML5 file.

Those three files are all in the same page but in different containers and with their own html.

 

So basically if I press play on sound 1 or 2 or 3 then only that sound will play. 

 

Is that possible?

 

Attached is .fla

Thank you so much!!

Legend
November 16, 2016

phornschemeier wrote:

Client wants music to start after hitting a "Play" button.
They want the music to continue playing until the viewer hits a "Replay" button.

This sounds like you're saying there should only be music the first time, but not the second or more times.

Colin Holgate
Colin HolgateCorrect answer
Inspiring
November 15, 2016

Your example file doesn't include any sound.

The simplest solution would be to include this line in your replay code, before the this.gotoAndPlay(2) line:

createjs.Sound.stop();