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

Pause on beforeComplete (Prevent Stop event)


playerInstance.on('beforeComplete', function(e){
//alert("before");
playerInstance.pause(true);
console.log("tried to stop!");
});

The code above is meant to pause the player instead of allowing it to launch the event "stop", since "stop" event occurs on complete, I'd like to pause beforeComplete. For some reason the player still finishes. How can I pause right before complete?

Thanks
Ryan

5 Community Answers

Todd

JW Player Support Agent  
0 rated :

I have escalated this to our engineers, so I will be sure to update you when I hear back from them.

Todd

JW Player Support Agent  
0 rated :

Here’s the response I got from them:

beforeComplete shouldn’t really used for pausing. The file is already complete, which is what triggers the beforeComplete event to begin with.

Instead, you can do something like:

jwplayer().on(‘time’, function(event){
var pauseHere = (jwplayer().getDuration() – 1);
if(event.position >= pauseHere) {
jwplayer().pause();
}
});

contact

User  
0 rated :

Thanks Todd, I'm going to test that now. I fear early cutoff. Possible to do milliseconds?

contact

User  
0 rated :

Hey Todd, I updated your code a bit (and added a little of my own) for JW7 specifications. And yes, half a second does work (at least in HTML5). :)

playerInstance.on('time', function(e){
if(typeof pauseHere === 'undefined') {
pauseHere = playerInstance.getDuration() - .5;
console.log(pauseHere);
}
if(e.position >= pauseHere) {
console.log(pauseHere);
playerInstance.pause(true);
}
});

Cheers!
Ryan

Todd

JW Player Support Agent  
0 rated :

Looks good!

As far as the half second, we do not have control over how often the .on(‘time’) events fire. It all depends on browser’s Javascript speed, but that being said, I would not be surprised if an even smaller internal works, like .2

This question has received the maximum number of answers.