diff --git a/templates/macros.html b/templates/macros.html index 757ce315f952345bd457225e2abc80ff54be2900..6b1f0c0fbc69746c25114721527c195c444c5484 100644 --- a/templates/macros.html +++ b/templates/macros.html @@ -55,6 +55,29 @@ $('#videoplayer').addClass("vjs-16-9"); $('#videoplayer').css("width"); $(function() { + //resume + var progress_key = "progress_{{ lecture.id }}"; + var seconds_played; + if (localStorage) { + seconds_played = localStorage.getItem(progress_key); + if (!seconds_played) { + seconds_played = 0; + } else { + videojs('videoplayer').currentTime(seconds_played); + } + } + videojs("videoplayer").on("timeupdate", function() { + if (localStorage) { + var player_cur_Time = Math.round(videojs("videoplayer").currentTime()); + if(Math.abs(player_cur_Time - seconds_played) >= 10) { + seconds_played = player_cur_Time; + localStorage.setItem( progress_key , seconds_played) + } + } + + }); + + //autoplay var playerplay = function() { if ($('#videoplayer').data("wasnotplayed") == 1) { videojs('videoplayer').play();