JWPlayer Prevent SKipping forward unless already watched

拜拜、爱过 提交于 2019-12-01 05:52:57
mal

I found this a while back, probably on the JWplayer forum. I think I added a bit about the playlist. So just in case you or others are still looking for an answer, consider adding stuff like:

var maxPlayPosition = 0.0;
var seeking = false;

jwplayer().onTime(function(event) 
{
    if (!seeking) 
    {
        maxPlayPosition = Math.max(event.position, maxPlayPosition); 
    }
})
.onPlaylistItem(function()
{
    maxPlayPosition = 0.0;
})   // consider using only if you have playlists
.onSeek(function (event) 
{
    if (!seeking) 
    {
        if (event.offset > maxPlayPosition) 
        {
            seeking = true;
            setTimeout(function ()
            {  
               jwplayer().seek(maxPlayPosition);
            }, 100);
        }
    } 
    else 
    {
        seeking = false;
    }   
 });

Had been using @mal's answer for a while, but found it was breaking for some edge cases (e.g. click and drag). Could be because we're on JW player 8?

Anyway, got a modified solution that covers them pretty well if anyone is still looking for answers to this. Relies on the seeked handler which fires after the seek occurs.

var seeking = false;
var maxPlayPosition = 0;

jwplayer().on('time', function (event) {
    if (!seeking) {
        maxPlayPosition = Math.max(event.position, maxPlayPosition);
    }
}).on('seek', function (event) {
    seeking = true;
}).on('seeked', function (event) {
    var pos = jwplayer().getPosition();
    if (pos > maxPlayPosition) {
        jwplayer().seek(maxPlayPosition);
    }
    seeking = false;
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!