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

getPosition() immediately after seek() returns incorrect number


bc.. var newPos = 10;
var oldPos = player.getPosition();
player.play(false);
player.seek(newPos);
var testPos = player.getPosition();



In this example, I would think that testPos == newPos. But no, testPos == oldPos. Why? And what needs to happen for player.getPosition() to return the correct position after player.seek()? Do I need to call player.play(true) before the position actually gets updated?

5 Community Answers

JW Player

User  
0 rated :

@JP

Thinking out loud here.

Have you tried using 'event.position'?

For example and taking your code listing:

bc.. var newPos = 10;
var oldPos = event.position;
player.play(false);
player.seek(newPos);
var testPos = event.position;



Two things are worth noting here: as you are comparing 'apples and oranges' that is to say
newPos is an integer number whereas event.position is a floating point number.


<ol>
*
<li>newPos is an integer number </li>
<li>event.position is a floating point number </li>
*
</ol>


I would recommend that you convert the event.position into an integer number.
parseInt(evt.position) BUT you can also convert the newPos variable into a floating point number parseFloat(newPos). Either way you then will be able to compare two apples or oranges.

There is also another issue namely, the manner of how you utilize the JWPlayer

<ol>
*
<li>player.play(true) should read as jwplayer().play(true)</li>
<li>similarly player.seek(newPos) should read as jwplayer().seek(newPos)</li>
<li>varoldPos = player.getPosition() should read as var old = jwplayer().getPosition()
*
</ol>

JW Player

User  
0 rated :

Thanks for the reply... the code I specified was just an example. In production, the variable "player" is returned from:

bc.. player = jwplayer('player-id').setup(myOptions);



The player does eventually return the correct position, but I think that only happens after I start playing again. Unfortunately, I need it to return the correct value right after I seek to it.

Also, I don't have access to the event data after I seek.

Ethan Feldman

JW Player Support Agent  
0 rated :

Can I see where this is running?

JW Player

User  
0 rated :

Sorry Ethan, I don't have a test page setup that you can access. Do you know if this is supposed to happen? I'm basically implementing a looper, so when it reaches the end of the loop, it rewinds to the beginning of the loop. Immediately after calling seek(), getPosition() does not return the updated position.

Ethan Feldman

JW Player Support Agent  
0 rated :

It should get the position, so that is why I wanted to see an example.

This question has received the maximum number of answers.