Skip to main content
Participant
March 2, 2022
Answered

HTML5 Canvas action at the end of a video

  • March 2, 2022
  • 1 reply
  • 200 views

Hello everybody,

 

I'm using Animate HTML5 Canvas project with a component Video into a frame on the timeline (full screen).

Now I need to do a "GotoAndStop" at a certain frame once the video is ended.

How can I do that ?

Best regards

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

    Hi.

     

    This should work (the loop property of the Video component must be set to false) :

     

     

    var root = this;
    var videoID = "yourVideoID"; // the id is set in the Properties panel when the video component is selected
    var video;
    
    function drawEndHandler()
    {
    	video = document.getElementById(videoID);
    	video.addEventListener("ended", endedHandler);
    }
    
    function endedHandler()
    {
    	video.removeEventListener("ended", endedHandler);
    	root.gotoAndStop(1);
    }
    
    root.stop();
    stage.on("drawend", drawEndHandler, null, true);

     

     

     

    I hope it helps.

     

    Regards,

    JC

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    March 2, 2022

    Hi.

     

    This should work (the loop property of the Video component must be set to false) :

     

     

    var root = this;
    var videoID = "yourVideoID"; // the id is set in the Properties panel when the video component is selected
    var video;
    
    function drawEndHandler()
    {
    	video = document.getElementById(videoID);
    	video.addEventListener("ended", endedHandler);
    }
    
    function endedHandler()
    {
    	video.removeEventListener("ended", endedHandler);
    	root.gotoAndStop(1);
    }
    
    root.stop();
    stage.on("drawend", drawEndHandler, null, true);

     

     

     

    I hope it helps.

     

    Regards,

    JC

    Participant
    March 2, 2022

    Just perfect, working so fine.

    It's magical 🙂

    Thank you, all best

    Philippe