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 22, 2021

Yes, it is.

 

I've updated the link with a pause button. I'll leave the full code here in case someone else needs it.

 

var _this = this;

_this.play_btn.on('click', function(){
	
	if (_this.bgm)
		_this.bgm.play();
	else
		_this.bgm = createjs.Sound.play("BGM");
});

this.stop_btn.on("click", function()
{
	if (_this.bgm)
	{
		_this.bgm.stop();
		_this.bgm = null;
	}		
});

this.pause_btn.on("click", function()
{
	if (_this.bgm)
		_this.bgm.paused = true;		
});

Hello João!

 

Can the stop button stop all sounds?

 

https://www.save-sthlm.se/play/

 

The problem I am having is that if more that one play button

is clicked the sounds all play together. I need the ''stop button''

to stop all sounds.

 

Is that possible?

 

 

 

 

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();