Copy link to clipboard
Copied
HTML5 canvas how do I do that so I fade out with single mp3 sound.createjs
assign a reference to your sound (when it's created) and start the fade when you want.
Copy link to clipboard
Copied
start a loop (eg, tick) and adjust the sound's volume in the listener function.
Copy link to clipboard
Copied
Can you show me an example with code how I do it.
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Thank you for helping me show code examples. Now I can add it to my slideshow.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
assign a reference to your sound (when it's created) and start the fade when you want.
Copy link to clipboard
Copied
Can you give me example how I do that with codes because I'm not that keen on programming.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I want to play the sound at the beginning and fade out later a few frames ahead. How do I do then.
Copy link to clipboard
Copied
the user has to interact with your html before sound can start.
place the fadeout tick listener in whatever frame you want.
Copy link to clipboard
Copied
Thanks for your help and some programmer I will never be because I miss thinking logically. I can't solve a problem solution with equations, but I'm good at seeing it systematically. I call Sudoku, Kakuro and Hitori systematic puzzles and I can solve these three quite well, but then I have trained my ability with a lot of these. The patience is gained with in training.
Copy link to clipboard
Copied
What do you mean this "assign a reference" how do I that with code.
Copy link to clipboard
Copied
for the sound, double click the linkage id column adjacent to your library sound.
for the button, use the properties panel to assign an instance name.
and if you're creating something using code, what are you creating?
Copy link to clipboard
Copied
I create a slideshow with pictures where I have a start button. After the start button within the frame so in the next frame there I have this code:
createjs.Sound.on("fileload", handleFileLoad1);
createjs.Sound.registerSound("music1.mp3", "MySound1");
function handleFileLoad1()
{
createjs.Sound.play("MySound1");
}
A few thousand lines ahead and I want to fade out the music that I had at the start ("music1.mp3", "MySound1").
After that I will load new music with the same codes I started with a different instance name.
Copy link to clipboard
Copied
create a reference that you can use to fade:
var _this = this;
function handleFileLoad1()
{
_this.mysound1_instance = createjs.Sound.play("MySound1");
}
Copy link to clipboard
Copied
How should I write the code on fade. Should it be what I have done in the picture I have attached. On console.log I only get red warning where tick loops endlessly. How shall do I.
Copy link to clipboard
Copied
i can't see where you created the sound.
Copy link to clipboard
Copied
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