SerenityNetworks Posted March 24, 2015 Share Posted March 24, 2015 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 More sharing options...
SerenityNetworks Posted March 24, 2015 Author Share Posted March 24, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now