jwplayer: how to disable seek on not viewed part of video?
Asked Answered
C

2

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.

Coachwork answered 10/12, 2014 at 13:43 Comment(3)
The code above there works.Handfast
I was trying to setup in a page to show demo at 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 1500Coachwork
I would strip this down to a more simple embed. See below.Handfast
H
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>
Handfast answered 10/12, 2014 at 23:38 Comment(4)
I have hosted same example at 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 2500Coachwork
That makes sense, this was not something tested with HLS, or any other streaming protocol, for that matter.Handfast
Thanks for input. I have tested and it works with 6.11 version, not 6.8Coachwork
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: github.com/slhck/web-player-demos/commit/…Trulatrull
S
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');
    }
  }
}
Slesvig answered 3/7, 2018 at 3:21 Comment(2)
But it's not working on IE 11. I don't know why it's not working. It's working on safari, chromeSeisin
uhm, don't know why. If you find a workaround please post here for future SO usersSlesvig
H
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>
Handfast answered 10/12, 2014 at 23:38 Comment(4)
I have hosted same example at 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 2500Coachwork
That makes sense, this was not something tested with HLS, or any other streaming protocol, for that matter.Handfast
Thanks for input. I have tested and it works with 6.11 version, not 6.8Coachwork
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: github.com/slhck/web-player-demos/commit/…Trulatrull

© 2022 - 2024 — McMap. All rights reserved.