Skip to main content
Known Participant
October 6, 2021
Answered

Audio won't pause, html5 canvas

  • October 6, 2021
  • 1 reply
  • 263 views

Hi!

I wrote this code below but my pause button won't work. The play and stop are ok. Could anyone tell me why? I openned dev mode in my browser and no errors have been pointed out.

var root = this;
root.stop();
 
root.btnPlay.addEventListener("click", playSong1);
root.btnPause.addEventListener("click", pauseSong1);
root.btnStop.addEventListener("click", stopSong1);
 
function playSong1() {
createjs.Sound.play("SongToPlay1")
}
 
function pauseSong1() {
createjs.Sound.paused = true;
}
 
function stopSong1() {
createjs.Sound.stop();
}
This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

Sorry for not having answered on the other topic.

 

First you store the current sound in a variable and then you access its paused property and stop method.

 

With that being sad, your code should be like this:

 

var root = this;
var sound;

root.stop();

root.btnPlay.addEventListener("click", playSong1);
root.btnPause.addEventListener("click", pauseSong1);
root.btnStop.addEventListener("click", stopSong1);

function playSong1()
{
	sound = createjs.Sound.play("SongToPlay1");
}

function pauseSong1()
{
	sound.paused = true;
}

function stopSong1()
{
	sound.stop();
}

 

 

I hope it helps.

 

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
October 6, 2021

Hi.

 

Sorry for not having answered on the other topic.

 

First you store the current sound in a variable and then you access its paused property and stop method.

 

With that being sad, your code should be like this:

 

var root = this;
var sound;

root.stop();

root.btnPlay.addEventListener("click", playSong1);
root.btnPause.addEventListener("click", pauseSong1);
root.btnStop.addEventListener("click", stopSong1);

function playSong1()
{
	sound = createjs.Sound.play("SongToPlay1");
}

function pauseSong1()
{
	sound.paused = true;
}

function stopSong1()
{
	sound.stop();
}

 

 

I hope it helps.

 

Regards,

JC