How to seek() then pause() with JWPlayer 5.4
Asked Answered
A

3

7

Does anyone know how to get JW PLayer v5.4 (either the Flash rendering or the HTML5 rendering) to pause after a seek() command?

I'm trying to get the video to step 0.01 seconds forward or backward when a user clicks the fine-grain control buttons (or uses the left or right arrow keys). This is so they can snap a framegrab with better precision.

I'm not sure if this is even possible but I've tried a few things with no luck. Such as the following:

var stepTo = jwplayer("video_player").getPosition() + 0.01;

jwplayer("video_player").seek(stepTo).onComplete(function(){
    jwplayer('video_player').pause();
});

And:

jwplayer("video_player").pause().seek(stepTo);

And:

jwplayer("jwplayer_container").seek(stepTo).pause();

And:

jwplayer("video_player").pause().play().pause();

I've also seen that the 'Shortcuts' plugin has this feature, but that plugin ins't compatible with v5.4 yet.

Thanks for any help.

Ahmad answered 23/1, 2011 at 0:7 Comment(0)
C
4

@AJB -

There's a ticket to add an "onSeek" event scheduled for the 5.6 player. In the meantime, the best way to do this is probably something like this:

jwplayer("video_player").seek(stepTo);

var pauseOnSeek = true;
jwplayer.onTime(function() {
   if (pauseOnSeek) {
      this.pause();
      pauseOnSeek = false;
   }
});

If the onTime() event fires off before the seek is complete, you may be able to hack around it by setting a timeout before defining the onTime() handler.

Caudad answered 24/1, 2011 at 23:8 Comment(2)
No dice PabloS, I tried it but it just kept going back to the "frame" it was initially paused on and then pausing there again. Didn't step forward. Thanks for the suggestion though.Ahmad
I'm still not clear about the use of onTime function. The lecture that I do is: Do things while the video is playing (on the time the vid plays)...is that ok?Registered
B
0

With JW Player 6, you can do the following to cause the video to pause after seeking:

jwplayer("vidPlayerDiv").onSeek(function () { jwplayer("vidPlayerDiv").pause(); });
Bik answered 9/1, 2013 at 18:11 Comment(1)
This didn't work for me because it seems that onSeek() is not invoked for the first time you call seek(). Ended up using onPlay().Lazo
T
0

This is a little variation on PabloS code:

jwp = var player = jwplayer('target').setup({
    file: '/some-file.mp3'
});

jwp.seek(position);

var pauseOnSeek = true;
jwp.onTime(function () {
    if (jwp.getState() === "PLAYING" && pauseOnSeek) {
        this.pause();
        pauseOnSeek = false;
    }
});

I had to write code that changed source mediafile without starting video from the beginning. I wanted to handle switching video when it was paused. When I used seek and pause in onSeek callback it didn't work because video was still buffering. Pausing in onTime callback like in code above worked like a charm.

Tawny answered 24/9, 2013 at 17:34 Comment(1)
old comment but you can use this: jwp.on('time', callback)Stigma

© 2022 - 2024 — McMap. All rights reserved.