Skip to main content
Inspiring
May 3, 2020 9:20 AM UTC
Answered

Fade out mp3

HTML5 canvas how do I do that so I fade out with single mp3 sound.createjs

This topic is closed to new replies. Start a new post to keep the conversation going.
kglad
kgladCorrect answer
Community Expert
May 8, 2020 8:02 PM UTC

I have this at the beginning of the frame of the slideshow:

 

createjs.Sound.on("fileload", handleFileLoad1);
createjs.Sound.registerSound("music1.mp3", "MySound1");

function handleFileLoad1()
{
createjs.Sound.play("MySound1");
}

but now several frames ahead I want to fade out the sound because I don't want a button. How do I do that?


assign a reference to your sound (when it's created) and start the fade when you want.

19 replies

JoãoCésar17023019
Community Expert
Community Expert
Feb 6, 2024 7:30 PM UTC

Hi.

 

Just adding that you can also use the Tween class to fade a sound. Like this:

var sound;

this.yourButton.on("click", function()
{
	if (sound)
		sound.stop();
	
	sound = createjs.Sound.play("YourSoundLinkage");
	createjs.Tween.get(sound).wait(2000).to({ volume: 0 }, 350);
}, this);

 

Regards,

JC

Translate
kglad
Community Expert
Community Expert
May 4, 2020 1:33 PM UTC
this.s.addEventListener("click",f.bind(this));
this.fadeOut = fadeOutF.bind(this);


function f(){
	this.sound = createjs.Sound.play("soundID");
	this.addEventListener("tick", this.fadeOut);
}

function fadeOutF(){
	this.sound.volume -= .02;
	if(this.sound.volume <= 0){
		this.removeEventListener("tick", this.fadeOut);
	}
}
Translate
peorAuthor
Inspiring
May 4, 2020 5:33 PM UTC

Thank you for helping me show code examples. Now I can add it to my slideshow.

Translate
kglad
Community Expert
Community Expert
May 4, 2020 5:46 PM UTC

you're welcome.

Translate
kglad
Community Expert
Community Expert
May 4, 2020 12:06 AM UTC

start a loop (eg, tick) and adjust the sound's volume in the listener function.

Translate
peorAuthor
Inspiring
May 4, 2020 8:53 AM UTC

Can you show me an example with code how I do it.

Translate