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

落花浮王杯 提交于 2019-12-10 23:31:07

问题


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.


回答1:


Try this more simple embed, for starters:

<!DOCTYPE html>
<html>
<head>
    <title>Disable Seek</title>
    <script type='text/javascript' src='http://p.jwpcdn.com/6/8/jwplayer.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().onTime(function (event) {
    if (!seeking) maxPlayPosition = Math.max(event.position, maxPlayPosition)
}).onPlaylistItem(function () {
    maxPlayPosition = 0
}).onSeek(function (event) {
    if (!seeking) {
        if (event.offset > maxPlayPosition) {
            seeking = true;
            setTimeout(function () {
                jwplayer().seek(maxPlayPosition)
            }, 100)
        }
    } else seeking = false
});
</script>
</body>
</html>



回答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');
    }
  }
}


来源:https://stackoverflow.com/questions/27402534/jwplayer-how-to-disable-seek-on-not-viewed-part-of-video

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