Jump to content

clearInterval (r/t setInterval) not stopping loop


SerenityNetworks

Recommended Posts

I'm playing a video and while it is playing I'm using setInterval to search for a string every second. This is working perfectly. When I pause the video then I want the search loop to stop, but it's not stopping with the clearInterval command.

 

What am I doing wrong here? I'm stumped.

 

Thanks,

Andrew

// ------------  PLAY PAUSE ------------  function playPause() {     if (vvid.paused)         {vvid.play(); 		var vInterval = setInterval(function() { findWord(); }, 1000);		findWord(jQuery('#findWord').val());        }    else         {        vvid.pause();        clearInterval(vInterval);        } }
Link to comment
Share on other sites

Whoops! Never mind. I thought I was getting it set as a global variable, but I wasn't. Just in case anyone is interested, the following works fine.

var nIntervId;function playPause() {     if (vvid.paused)         {vvid.play(); 		//timerOnOff(1);		startInterval();		findWord(jQuery('#findWord').val());        }    else         {        vvid.pause();        //timerOnOff(2);        stopInterval();        } }        function startInterval() {  nIntervId = setInterval(findWord, 500);} function stopInterval() {  clearInterval(nIntervId);}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...