Audio won't pause, html5 canvas

Community Beginner ,
Oct 06, 2021 Oct 06, 2021

Copy link to clipboard

Copied

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();
}
TOPICS
Code , How to

Views

61

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Oct 06, 2021 Oct 06, 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 pa...

Likes

Translate

Translate
Adobe Community Professional ,
Oct 06, 2021 Oct 06, 2021

Copy link to clipboard

Copied

LATEST

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

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
community guidelines