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

Setting initial position


Until today we had code the fired after the html was loaded and its job was to find out of the player was available and if it was, move the playhead to the last position the user was watching.

We are still saving the last position, but something seems to have changed and we can no longer make this work to set the initial position when the page opens again.

We were doing:

$(document).ready(function ()
{
. . .
var position = jwplayer().getPosition(); // now always undefined

. . .
}

but starting today, the position is always undefined.

The jwplayer() does return an object.

getPosition() comes to life in later javascript functions, but as the page loads, getPosition() is always returning undefined.

Since this is now not working, what is the right way to set the initial position of a video?

Thank you for your help.


1 Community Answers

Carolyn Ganon

JW Player Support Agent  
0 rated :

Good morning!

This sounds like a javascript timing issue. Since javascript is asynchronous, it’s difficult to force one event to occur after another when you load external libraries. In other words, when you call jwplayer().getPosition() in document.onReady, there’s no guarantee that the JWPlayer object is available or fully loaded when this function is called.

Can you try placing the getPosition() in the JWPlayer onReady callback function? And when the player is loaded again, you can seek the player to the user’s last position using the seek( timeinterval ) function. For a complete API reference, see http://support.jwplayer.com/customer/portal/articles/1413089-javascript-api-reference

Let me know if this works! I will keep the ticket open in the meantime in case you have follow up questions.

Best,

Carolyn Ganon
Customer Support Engineer
JW Player

This question has received the maximum number of answers.