Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seekTo value and result mismatched #75

Closed
whitegrey opened this issue Jun 17, 2016 · 6 comments
Closed

seekTo value and result mismatched #75

whitegrey opened this issue Jun 17, 2016 · 6 comments

Comments

@whitegrey
Copy link

whitegrey commented Jun 17, 2016

If you use seekTo to set a value, the result may be wrong by 1s.

case in point:

seeking to 0:05 in a 148 second video means calling seekTo( 0.033783783783783786 ). onDuration will immediately return {played: 0.0337837775564004}. I'm assuming this is because React Player only sets to the 6th or 7th digit?

The problem is 0.0337837775564004 multiplied by 148s (video length) returns 4.999999078347259. Which youtube rounds down to 4s.

In other words, if you try to set time to 5s, you will instead get 4s.

On a side note, would you consider adding the options to set seek via seconds elapsed? It may just be me, but I feel it's a much more intuitive method of working with seek than percent played.

@whitegrey whitegrey changed the title seekTo and onDuration values mismatched seekTo value and result mismatched Jun 17, 2016
@cookpete
Copy link
Owner

Your specific issue could be YouTube adding one second to the reported duration (possibly so videos between 0 and 1 second long appears as 1 second long). The reason fraction is used is because we only know the duration after onDuration is called, so the app would have to gather the duration into state (or somehow know it beforehand) before it is able to safely seek anywhere. With a fraction you can seek without needed to know the duration (because 0.5 will always be halfway through the media, etc).

I agree that is seems less intuitive, but unfortunately the different players make their durations available at different times during the loading sequence.

Perhaps seekTo could be clever and handle both. Seek using a fraction if the value given is less than 1, otherwise seek using seconds.

@lostbard
Copy link

lostbard commented May 7, 2018

So what happens when you do a seekTo(0.5) meaning you want to seek to 0.5 seconds ?

@cookpete
Copy link
Owner

cookpete commented May 8, 2018

So what happens when you do a seekTo(0.5) meaning you want to seek to 0.5 seconds ?

I did consider this when implementing but figured the chance of someone ever wanting to seek to 0.x seconds was pretty much zero.

If you really wanted to (and the player SDK supported such specific seeking), you could use getInternalPlayer() and manually call seekTo (or whatever method is supported) on the internal player that ReactPlayer uses.

@kalpesh4307
Copy link

@cookpete how can i use getInternalPlayer() and manually call seekTo in my video modal??

@waynebloss
Copy link

Hello and thanks for your work on this player.

Everything is working great so far, but I really needed to be able to seek by 0.1 seconds for a video editor that I'm building. Overloading the seekTo method to do 2 separate functions by looking for fractions between '0' and '1' seems to go against best practices for making a clear and concise programming interface.

Would you consider a pull request that normalizes this behavior into separate functions?

david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue Dec 23, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue May 23, 2020
albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
@amanChaturvedi7
Copy link

@cookpete according to https://www.npmjs.com/package/react-player documentation, if we pass second argument for type as "seconds", It should override the default behaviour of considering value between 0 and 1 as fractions. But this isn't happening. I am trying to do player.seekTo(0.4, "seconds") and it's taking me to 0.4 times the duration of the video.

webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants