Skip to content

Instantly share code, notes, and snippets.

@nullivex
Last active January 28, 2018 03:29
Show Gist options
  • Save nullivex/7a0b26a466cf68f92bb6845eab7c12d8 to your computer and use it in GitHub Desktop.
Save nullivex/7a0b26a466cf68f92bb6845eab7c12d8 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var currentPosition = 0;
if (localStorage.currentPlayerPosition) {
currentPosition = localStorage.currentPlayerPosition;
}
player.once('play', function (){
'use strict';
if (currentPosition > 0 && Math.abs(player.getDuration() - currentPosition) > 5) {
player.seek(currentPosition);
}
})
window.onunload = function (){
localStorage.currentPlayerPosition = player.getPosition();
}
player.on('error', function (e){
console.log(e);
localStorage.currentPlayerPosition = player.getPosition();
window.localhost.reload(true);
})
</script>
@nullivex
Copy link
Author

This assumes your player is loaded to the player variable if it isnt do the following first.

var player = jwplayer();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment