Player.js: SetCurrentTime plays loaded video at 0 before playing correct time

Created on 20 Aug 2016  Â·  11Comments  Â·  Source: vimeo/player.js

Expected Behavior

A setCurrentTime() in promise of loadVideo() should buffer and play a paused video directly at the correct time.

Actual Behavior

Using setCurrentTime() in the promise of a loadVideo() plays the video at 0.00 for a brief moment before jumping to the correct time. The player is paused before a loadVideo(). No combination of autopause=1 or autoplay=0 can stop this from occurring. Consecutive setCurrenTime() commands for the loaded video play at the correct time directly and smoothly.

Steps To Reproduce

Add setCurrenTime() to the promise of a loadvideo(). You can also reproduce this on the demo page. Enter an ID in the loadvideo field. Enter any time other than 0 in the setCurrenTime field. Press loadvideo button and immediately press the setCurrentTime() button.

Tried lots of solutions. If anyone has a workaround for this problem, I'd be very thankful.

bug enhancement player

Most helpful comment

A small note about the workaround above is that the "pause" event never actually fires. Seems like it still thinks it is pause even inside the play().then. But it still seems to work.

I ended up opting for this approach since setCurrentTime() actually fires the play event automatically prior to playback start.

var init = true;
player.setCurrentTime(31.2);
player.on('play', function(data) {
  if (init) {
    player.pause()
    init = false;
  }
});

All 11 comments

If you set up the embed to use #t=30 in the url, the player will autoplay and start at that time. You won't be able to use it with loadVideo() though. See this pen for a working example.

Hi bdougherty,

Thanks for the response.

So there's no way to use the javascript player api to instantly start a newly loaded video at a specific time using setCurrenTime() without it first wanting to start playing at time 0.00? Not even when you pause the video before loading a new one and having autoplay turned off?

Thanks for your help.

Hi @bortraws,

To play a loaded video at a specific time using setCurrenTime() then you may use the setCurrenTime(x) where x is number of seconds before play the video.

Hi Gautamdas130780,

Loadvideo in itself works. The issue is that if I want to load a video and start playing it at for instance minute 10, it will always start playing at the beginning for the fraction of a second and then jump to the designated time so 10 min in this example.

Even if the player is set to pause. As soon as I load a new video that I want to start playing at a specific time, it always plays a second of the beginning first before jumping to the right time.

I have this same issue, where I'd like to use the JavaScript API to dynamically change the start time of the video on load WITHOUT having it autoplay. The docs do say:

Setting the current time before playback has started will cause playback to start.

Is there any way to achieve this functionality?

Actually, this seems to work. You have to play, then pause, then change the start time:

player.play().then(function() {
  player.pause().then(function() {
    player.setCurrentTime(31.2);
  });
});

A small note about the workaround above is that the "pause" event never actually fires. Seems like it still thinks it is pause even inside the play().then. But it still seems to work.

I ended up opting for this approach since setCurrentTime() actually fires the play event automatically prior to playback start.

var init = true;
player.setCurrentTime(31.2);
player.on('play', function(data) {
  if (init) {
    player.pause()
    init = false;
  }
});

Hi Patrick

Many many thanks for valuable information.

On Thu, Aug 10, 2017 at 1:44 AM, Patrick Waller notifications@github.com
wrote:

A small note about the workaround above is that the "pause" event never
actually fires. Seems like it still thinks it is pause even inside the
play().then. But it still seems to work.

I ended up opting for this approach since setCurrentTime() actually fires
the play event automatically prior to playback start.

var init = true;
player.setCurrentTime(31.2);
player.on('play', function(data) {
if (init) {
player.pause()
init = false;
}
});

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/vimeo/player.js/issues/42#issuecomment-321368673, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA0jaeAUNOiixhuSjhYCNtNwyWlXvHTPks5sWhM5gaJpZM4Jo8ch
.

--
Regards,
Gautam Kumar Das
Sr. Developer | Ballistic Learning Pvt. Ltd.
M# +91 8130060305
Web: www.ballisticlearning.com

Recently the above statement no longer seems to hold true.

Setting the current time before playback has started will cause playback to start.

Instead, when setCurrentTime() is called a pause event occurs instead of a play event. I believe this is due to the recent autoplay restrictions enabled by most browsers: https://help.vimeo.com/hc/en-us/articles/115004485728-Autoplaying-and-looping-embedded-videos

Can anyone else verify?

@firewaller it's very possible that a pause event is triggered because of the new browser autoplay policies. The play method should reject in that case.

Is this still an issue for people here?

In this little test, the timeupdate events start from 40s for the 2nd video on my end.
http://jsfiddle.net/luwes/k7a5xgfL/

Closing this, I can't reproduce the problem in the jsfiddle above.

Note player.loadVideo() will require a subsequent player.play() call to start the video playback or a autoplay param in the config.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rassemdev picture rassemdev  Â·  7Comments

macliems picture macliems  Â·  7Comments

woodhall2k picture woodhall2k  Â·  4Comments

Shigeki1120 picture Shigeki1120  Â·  3Comments

jswebrjl picture jswebrjl  Â·  5Comments