Jump to content

clearInterval (r/t setInterval) not stopping loop

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.




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

Share this post

Link to post
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);}

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...