Copy link to clipboard
Copied
Hi to all,
I try to create a play/pause buttons for to play/pause an animation on the timeline, the buttons work well for the animation, but noto for the audio... this is because in the canvas sets it isn't possible use audio in streaming but only in event mode...
I find documentation only for external audio but not in timeline
this is my code inside a MC playpause_mc
this.stop_btn.addEventListener("click", stop_anim.bind(this));
function stop_anim() {
//javascript:alert("Mouse clicked");
this.parent.stop();
this.gotoAndStop("STOP");
//stop audio in parent
}
Can you help me?
You can stop all sound with this:
createjs.Sound.stop();
That would work for your example code, but if you really wanted to pause a song and then continue from where you left off, or from another position in the sound, it's slightly harder.
You would need to play the sound with code, and then you can pause the sound, set its position, or unpause the sound. Here's an example, where the first script is in frame 1, and the second is in frame 48, and in the library is a sound with its linkage set to be
...Copy link to clipboard
Copied
Copy link to clipboard
Copied
They are using Canvas, so the AS3 solutions won't apply.
Copy link to clipboard
Copied
Thank you for the clarification, Colin. I was not careful enough in my reading.
Do you have any solutions for this user?
Thanks,
Preran
Copy link to clipboard
Copied
You can stop all sound with this:
createjs.Sound.stop();
That would work for your example code, but if you really wanted to pause a song and then continue from where you left off, or from another position in the sound, it's slightly harder.
You would need to play the sound with code, and then you can pause the sound, set its position, or unpause the sound. Here's an example, where the first script is in frame 1, and the second is in frame 48, and in the library is a sound with its linkage set to be 'tune':
//frame 1
window.pos = 0;
window.snd = createjs.Sound.play("tune");
//frame 48
this.stop();
window.pos = window.snd.position;
window.snd.paused = true;
setTimeout(playsnd,3000);
function playsnd(){
window.snd.position = window.pos + 3000;
window.snd.paused = false;
}
Those scripts would set a sound going, then pause it after two seconds (in a 24 fps FLA), and in 3 seconds it would advance the sound by 3 seconds and unpause it.
The 'window.' part isn't needed, but I put it there to make it clear that the snd and pos variables are global.
Copy link to clipboard
Copied
Thanks Collin,
I try but the play doesn't run... I'm sure I'm making some mistakes...
window.pos = 0;
window.snd = createjs.Sound.play("tune");
this.stop_btn.addEventListener("click", videoStop.bind(this));
this.stop_btn.addEventListener("click", videoPlay.bind(this));
function videoStop() {
this.stop();
window.pos = window.snd.position;
window.snd.paused = true;
}
function videoPlay() {
this.play();
window.snd.position = window.pos;
window.snd.paused = false;
}
Copy link to clipboard
Copied
You may need to make the initial play of the sound be from a button, otherwise the sound hasn't been played from a user action, which it needs to be. Like:
this.stop();
this.start.addEventListener("click",firstPlay.bind(this));
this.stop_btn.addEventListener("click", videoStop.bind(this));
this.stop_btn.addEventListener("click", videoPlay.bind(this));
function firstPlay(){
window.pos = 0;
window.snd = createjs.Sound.play("tune");
}
function videoStop() {
this.stop();
window.pos = window.snd.position;
window.snd.paused = true;
}
function videoPlay() {
this.play();
window.snd.position = window.pos;
window.snd.paused = false;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now