2

I am using jwplayer 6.8.4616. I don't want users to seek to the part of video which he have not already watched, allowing to seek the part which have already watched, but unable to find good solution.

I have tried JWPlayer Prevent SKipping forward unless already watched in google chrome 39.0.2171.71 + ubuntu 14.04. It does not work for me unless I set timeout value to atleast 1500ms in that solution, but if timeout is too long then it becomes visible.

if not through javascript, can it be done using custom skins or plugins. can it be done in some higher version of jwplayer if not in my versio?

EDIT: The above approach works for MP4 video, but not for HLS streams.

Community
  • 1
  • 1
hridayesh
  • 1,123
  • 1
  • 14
  • 36
  • The code above there works. – emaxsaun Dec 10 '14 at 16:31
  • I was trying to setup in a page to show demo at http://vplayer.mindtickle.com/index.php For some unknown reason its not registering callbacks and giving warning "Could not add internal listener". but in my actual app the above works only when i Keep timeout more than 1500 – hridayesh Dec 10 '14 at 19:01
  • I would strip this down to a more simple embed. See below. – emaxsaun Dec 10 '14 at 23:37

2 Answers2

2

There is a different approach, taken from https://github.com/jwplayer/jwplayer/issues/977 that consist on overriding the seek method of the jwPlayer. This way, instead of waiting for the seek completion and then 'rewind', you avoid seeking at all.

var player = jwplayer('container').setup({ file: 'video.mp4'});
player.on('ready', function() {
  const originalSeek= player.seek;
  player.seek= (newPos) => {
    if (someCheckIsValid(newPos)){
      originalSeek(newPos);
    } else {
     console.warn('sorry, you cant seek to that position');
    }
  }
}
rafahoro
  • 1,237
  • 13
  • 19
1

Try this more simple embed, for starters:

<!DOCTYPE html>
<html>
<head>
  <title>Disable Seek</title>
    <script type='text/javascript' src='https://cdn.jwplayer.com/libraries/Jq6HIbgz.js'></script>
  <style type="text/css">
    body { margin: 0; padding: 0 }
  </style>
</head>
<body>
<div id="thePlayer"></div>
<script type="text/javascript">
jwplayer("thePlayer").setup({
    image: "http://content.bitsontherun.com/thumbs/w5co0c24-480.jpg",
    file: "http://content.bitsontherun.com/videos/w5co0c24-hV866gPy.mp4"
});
var maxPlayPosition = 0;
var seeking = false;
jwplayer().on("time", function (event) {
    if (!seeking) maxPlayPosition = Math.max(event.position, maxPlayPosition)
}).on("playlistItem", function () {
    maxPlayPosition = 0
}).on("seek", function (event) {
    if (!seeking) {
        if (event.offset > maxPlayPosition) {
            seeking = true;
            setTimeout(function () {
                jwplayer().seek(maxPlayPosition)
            }, 100)
        }
    } else seeking = false
});
</script>
</body>
</html>
slhck
  • 36,575
  • 28
  • 148
  • 201
emaxsaun
  • 4,191
  • 2
  • 13
  • 13
  • I have hosted same example at http://vplayer.mindtickle.com/b.html with option to select multiple sources. It works well for given mp4 source, but does not work well for hls stream. Works for hls if timeout is increased to 2500 – hridayesh Dec 11 '14 at 09:41
  • That makes sense, this was not something tested with HLS, or any other streaming protocol, for that matter. – emaxsaun Dec 11 '14 at 15:22
  • Thanks for input. I have tested and it works with 6.11 version, not 6.8 – hridayesh Dec 12 '14 at 09:15
  • The callbacks you are using in this code do not exist anymore. See here for an updated version of the code that prevents seeking to the unbuffered part: https://github.com/slhck/web-player-demos/commit/42ca75f200502b9c67667b6be372fb4ebb6ced3a#diff-e12586dda7ebbb0aecd84f38606ebe943722bb876e534885b7e9ba908109c1dd – slhck Nov 12 '21 at 13:08