jquery - javascript increment setInteval counter while video is playing -


i have following code detect if user idle or not. on page load, timer run , if user idle of seconds timer pause , resume if user active. , have codes detect if video playing, if video playing timer should run , if video stop/pause timeout run , detect if user still active

the problem if video playing, timer paused , start idle. want when video playing timer should countinue increment.

heres code:

function setplayingvideototrue(){playing_video = true;}  function setplayingvideotofalse(){playing_video = false;}  // check if video iframe exists var iframe_videos = $('body').find('iframe');  if(iframe_videos.length > 0){ // create ready events every iframe iframe_videos.each(function(index){     // add temporary id iframe     // append additional parameters end of iframe's src     var temporary_player_id = 'iframe_player_'+ index;     var new_iframe_src = $(this).attr('src') +'?api=1&player_id='+ temporary_player_id;     $(this).attr('id', temporary_player_id);     $(this).attr('src', new_iframe_src);      // add event listener ready     $f(this).addevent('ready', iframe_ready); });  // when player ready, add event listeners play, pause, finish, , playprogress function iframe_ready(player_id) {     $f(player_id).addevent('play', setplayingvideototrue);     $f(player_id).addevent('playprogress', setplayingvideototrue);     $f(player_id).addevent('pause', setplayingvideotofalse);     $f(player_id).addevent('finish', setplayingvideotofalse); } }   function start_idle_timer(){ var timer = 0;  function increment_duration() {        if(ispaused === false)     {         timer++;     }      // increment timer if video playing     if(playing_video === true){         cleartimeout(idletimer);         ispaused = false;     }       if(playing_video === false && ispaused === false){          // stop timer if user idle 3 minutes         var idletimer = settimeout(function(){             // console.log('idle');             clearinterval(check_time);             ispaused = true;              // modal apper inform user on idle state             $('#linkage').trigger('click');              var modal_timer = 0;             // timer modal idle timer             continue_modal_timer = setinterval(function(){                 modal_timer++;                  inactivity_timer = modal_timer;                 if(modal_timer == 60)                 {                     clearinterval(continue_modal_timer);                     cleartimeout(idletimer);                     }             }, 1000)             }, 10000);     }      // bind elements on dom possible events indicating user active     $('*').bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick', function () {         cleartimeout(idletimer);         ispaused = false;     }); }  // initialize interval check_time = setinterval(increment_duration, 1000);  }  // check if start_timer present loading page record time duration of user if($('.start_timer').length > 0){    start_idle_timer(); } 


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -