Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Resume from last time


How can I make jwplayer resume the video from the last time?

9 Community Answers

Todd

JW Player Support Agent  
2 rated :

We do not have built-in functionality for this, but you can write some custom code using our Javascript API.

All you need to do is call jwplayer().getPosition() to find out where the viewer is currently at in the video. You have a few options on what to do with this number, but perhaps the easiest thing is to save this value in a browser cookie. When the viewer returns to the page, you should check for the cookie and if the previous value exists, you can return the viewer to that same place with the jwplayer().seek() call.

Please see our full Javascript API reference at http://support.jwplayer.com/customer/portal/articles/1413089-javascript-api-reference for more details.

k...

User  
1 rated :

Hi Todd Grunow thank you for your answer.
I would like to ask you one more favour, can you help me to make a cookie that that save the data (for a specific page)?

Todd

JW Player Support Agent  
1 rated :

This example uses local storage instead of a cookie, but the code example is still valid. When the page loads, I check to see if a previously-saved value for position exists. If no, I set a default value of 0. If the cookie exists, I first check to make sure the viewer was not at the end of the video and then seek to the last known position when playback starts. The last bit of Javascript records the viewer’s playback position when the tab is closed.

Please note that Flash cannot seek to unbuffered positions, so this code example has only been tested in HTML5 mode.

<div id="player"></div>
<script type="text/javascript">
if (localStorage['JWPlayerPosition'] == '' || localStorage['JWPlayerPosition'] == 'undefined') {
	console.log("No cookie for position found");
	var currentPosition = 0;
} else {
	if (localStorage['JWPlayerPosition'] == "null") {
		localStorage['JWPlayerPosition'] = 0;
	} else {
		var currentPosition = localStorage['JWPlayerPosition'];	
	}
	console.log("Position cookie found: "+localStorage['JWPlayerPosition']);
}

jwplayer("player").setup({
    file: 'tears.mp4',
});

jwplayer().once('play',function(){
	console.log('Checking position cookie!');
	console.log(Math.abs(jwplayer().getDuration() - currentPosition));
	if (currentPosition > 0 && Math.abs(jwplayer().getDuration() - currentPosition) > 5) {
		jwplayer().seek(currentPosition);		
	}
});

window.onunload = function() {
   localStorage['JWPlayerPosition'] = jwplayer().getPosition();
}
</script>  

k...

User  
0 rated :

Sorry again, but how can I change the cookies name? (I use the same php page for play different files basing on the urls)

Todd

JW Player Support Agent  
1 rated :

If you are using PHP, then you can use a PHP session variable instead of a client-side solution. The steps are basically the same:

1) Check to see if a cookie or previous value exists
2) Seek to that value
3) Store the last known position when the viewer leaves the page

k...

User  
1 rated :

But there are any way to change the cookie name with name of the file? (I do like to use your code)
Thank you for your time.

Todd

JW Player Support Agent  
1 rated :

Do you mean the localStorage[‘JWPlayerPosition’] part? You could change this name to a PHP variable, but you would need to be sure to have PHP print out the Javascript with the PHP value, which can get a little messy with the quotation marks:

print "var currentPosition = localStorage['".$cookieName."'];";

k...

User  
0 rated :

thank you very much, that worked perfectly.

Todd

JW Player Support Agent  
0 rated :

You’re welcome. I will mark this support case as closed, but certainly contact us again if you have any other support questions or concerns.

This question has received the maximum number of answers.