JWPlayer Prevent SKipping forward unless already watched

前端 未结 2 1606
梦毁少年i
梦毁少年i 2021-01-13 02:45

I\'m using JWPlayer 5.4 and it\'s setup on the page using the javascript API.

What I\'d like to do is make it so that users can fastforward/rewing via the seek bar O

2条回答
  •  北海茫月
    2021-01-13 03:23

    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;
    });
    

提交回复
热议问题