Skip to main content
Known Participant
October 6, 2021
Answered

Audio won't pause, html5 canvas

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 is closed to new replies. Start a new post to keep the conversation going.
JoãoCésar17023019
JoãoCésar17023019Correct 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

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

Translate