Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Play/pause audio in timeline

New Here ,
Sep 08, 2017 Sep 08, 2017

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?

5.9K
Translate
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

LEGEND , Sep 11, 2017 Sep 11, 2017

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

...
Translate
Adobe Employee ,
Sep 08, 2017 Sep 08, 2017
Translate
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
LEGEND ,
Sep 08, 2017 Sep 08, 2017

They are using Canvas, so the AS3 solutions won't apply.

Translate
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
Adobe Employee ,
Sep 11, 2017 Sep 11, 2017

Thank  you for the clarification, Colin. I was not careful enough in my reading.

Do you have any solutions for this user?

Thanks,

Preran

Translate
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
LEGEND ,
Sep 11, 2017 Sep 11, 2017

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.

Translate
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
New Here ,
Sep 22, 2017 Sep 22, 2017

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;

}

Translate
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
LEGEND ,
Sep 22, 2017 Sep 22, 2017
LATEST

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;

}

Translate
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