Skip to main content
Inspiring
April 22, 2021
Answered

HTML5/Canvas: I'm trying to add a listener that will move the playhead to a frame when video ends

  • April 22, 2021
  • 1 reply
  • 903 views

Hello. I'm trying to add an event listener that will move the playhead to a frame and stop once a video ends. I'm using a video component. I just can't figure it out. Is this possible with html5/canvas?

    This topic has been closed for replies.
    Correct answer kglad

    if your component's instance name is videoPlayer:

     

    this.stop();
    var video;
    var tl = this;
    function checkInitF() {
    if (video) {
    video.addEventListener("ended", function(){
    // video ended. do whatever. eg,
    tl.gotoAndStop(wherever)
    });
    } else {
    video = $("#videoPlayer")[0];
    setTimeout(checkInitF, 100);
    }
    }
    checkInitF();

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    April 22, 2021

    if your component's instance name is videoPlayer:

     

    this.stop();
    var video;
    var tl = this;
    function checkInitF() {
    if (video) {
    video.addEventListener("ended", function(){
    // video ended. do whatever. eg,
    tl.gotoAndStop(wherever)
    });
    } else {
    video = $("#videoPlayer")[0];
    setTimeout(checkInitF, 100);
    }
    }
    checkInitF();

    Inspiring
    April 23, 2021

    I have simplified this to understand faster. At launch I want them to see a video. i know they must press the play button on the video player skin to start the video. Once the video is finished, go to frame 2 and stop (which is really frame 3 on the timeline).

     

    Here I've put the ode on frame 0 (frame 1), where the video component is. I just want it to stop at frame 2 when the video is completed.

     

     



    So I tried using your code. Since my movie clip instance is named "scene1_mc", do I put that here?


    this.stop();
    var video;
    var tl = this;
    function checkInitF() {
    if (video) {
    video.addEventListener("ended", function(){
    // video ended. do whatever. eg,
    tl.gotoAndStop(2)
    });
    } else {
    video = $("#scene1_mc")[0];
    setTimeout(checkInitF, 100);
    }
    }
    checkInitF();

    kglad
    Community Expert
    Community Expert
    April 23, 2021

    no.  that's the instance name of your video component.  ie, click to select it and check the properties panel for its instance name.  use that in

     

    video = $("#videoPlayer")[0];