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

How to stop onTime Event?


Hello,

on a keyup event, I am checking that a certain element has focus; if the keycode (spacebar in this case) is correct, I use onTime to stop the player at a specific time. If it does not have focus, then keycode is irrelevant and onTime should not be run. However, onTime continues to run and stop the player after the first set of conditions are satisfied (focus and spacebar). Is there a way to remove onTime in this case?

my code:

$(".playlistPanel1").focusin().bind('keyup', function(e) {
var code = e.keyCode || e.which;
if (code == 32) { //SPACE
$('.playlistPanel1 input').each(function(){ // attempt to clear any hidden focused elements
$(this).trigger('blur');
});
$this.seek($("#starttimeEntry").val()); //play at specific start time
$this.play(true);
$this.onTime(function (event) { // **continues to run outside of conditional**
if (event.position >= $("#endtimeEntry").val()) {
jwplayer().pause(true); //pause at specific start time
}
// kill onTime here?
});
// kill onTime here?
} else {
// kill onTime here?
}

});

Or am I using onTime in the wrong place in this case?

6 Community Answers

christanhardwick

User  
0 rated :

Here is a jsfiddle to illustrate: http://jsfiddle.net/chardwick/8YNd7/2/

Andrew

JW Player Support Agent  
0 rated :

Hi,

We will be releasing native keyboard commands in the next version of JW Player 6.9. If you’d like to test this, please feel free to sign up for our developer mailing list:
http://developer.longtailvideo.com/trac/

In the interim, would it be possible to set this up on a public facing static page? Additionally, please note that we no longer support modes with JW6.

christanhardwick

User  
0 rated :

Sure. Here is a publicly facing static example: http://www.aurifice.com/jwplayer_onTime.htm

Thanks for the notice re: modes - I'll update that page.

And thank you for the help!

Chris

Andrew

JW Player Support Agent  
0 rated :

Hi Chris,

Ah, in this case, would you be able to set a conditional variable here? Start off by setting a variable:

var hasbeenpaused = false;

You can check for this variable when making the call to pause your file:

if (event.position >= $(“#endtime”).val()&&hasbeenpaused==false) {
jwplayer().pause(true);
hasbeenpaused=true;
}

Since we’ve set the hasbeenpaused to true once this condition has been met, we will not pause anymore.

Of course, this is assuming you only want this to pause once during playback. :)

christanhardwick

User  
0 rated :

Andrew,

That did it! I went with adding "&&spacebar=true" to the if statement. Seems so obvious now...

So onTime will always be running; it's a matter of setting and checking conditions *within it* in order to start or stop ( or in this case, "not start") an event's callback.

Thanks again!

Chris

Andrew

JW Player Support Agent  
0 rated :

Excellent! Great news. :)

This question has received the maximum number of answers.