问题
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