Question

I have a video player that opens and plays whenever a link is clicked and after two videos are viewed there is a form that appears that allows you to rate the information that was given.

The problem that i'm having is that there is a replay button that appears when the video is completed. I currently have setTimeout in place that does away with the video and it's overlay then runs the rate form function. BUT if the replay button it clicked the setTimeout is still running and midway through the replay of the video the function runs. Here is my code:

Remove Video Overlay

fnVideoOverlayOff = function () {

    jQuery('#video, #block, .video-closebtn').css('display', 'none');

}

JW Player Code

jwplayer('videoScreen').setup({
        flashplayer: '/assets/js/lib/player.swf',
        allowscriptaccess: "always",
        width:972,
        height:547,
        controlbar: "none",
        autostart: true,
        playlistfile: "/assets/videos/playlist.xml",
        events: {
            onPlaylistItem: function (event) {

                jQuery(document).idleTimer('destroy');

            },
                            onPLay: function (event) {

                            },
            onComplete: function (event) {

                setTimeout(function () {

                    fnVideoOverlayOff();

                }, 10000);

                var clickCount = 0;

                if(jQuery.cookie('clickCount') == 2) {

                    fnRateOverlayOn();

                    jQuery('#video, .video-closebtn').css('display', 'none');

                }
            }
        }
    });

I would like to Kill fnVideoOverlayOff(); if the replay button is clicked

Was it helpful?

Solution

Store a reference to setTimeout, and call clearTimeout() when you want to prevent it from finishing.

fnVideoOverlayOffTimer = setTimeout(... 

// and later on when you want to "kill" it,

clearTimeout(fnVideoOverlayOffTimer);`

Ideally you would declare fnVideoOverlayOffTimer somewhere to keep it off the global scope, but that is optional.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top