How to seek() then pause() with JWPlayer 5.4

人走茶凉 提交于 2019-12-05 09:26:12

@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.

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

jwplayer("vidPlayerDiv").onSeek(function () { jwplayer("vidPlayerDiv").pause(); });

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!