Skip to main content
Participant
December 10, 2020
Answered

How to detect end of audio and run a function after

  • December 10, 2020
  • 2 replies
  • 257 views

Im trying to detect when the end of my audio happens so I can run a function.. something simple will do for now such as a console.log.

 

Im stuck please help!

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    Assuming you have a sound in the Library with the linkage name Voice, then the code could be something like this:

    var sound = createjs.Sound.play("Voice");
    
    sound.on("complete", function()
    {
    	console.log("sound finished");
    });

     

    I hope it helps.

     

    Regards,

    JC

    2 replies

    kglad
    Community Expert
    Community Expert
    December 10, 2020

    for sound with linkage = c, you can use:

     

    var s = playSound("c");
    s.addEventListener("complete",f.bind(this));
    function f(e){
    console.log(e);
    }

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    December 10, 2020

    Hi.

     

    Assuming you have a sound in the Library with the linkage name Voice, then the code could be something like this:

    var sound = createjs.Sound.play("Voice");
    
    sound.on("complete", function()
    {
    	console.log("sound finished");
    });

     

    I hope it helps.

     

    Regards,

    JC

    Participant
    December 10, 2020

    I had found something along the lines of this earlier, took me 3 hours just to realize I had to put it on the frame the audio is player at.. lol thanks a lot!