JWPlayer 防止向前跳,除非已经看过

发布于 2024-12-03 16:54:45 字数 239 浏览 1 评论 0原文

我正在使用 JWPlayer 5.4,它是使用 javascript API 在页面上设置的。

我想做的是,只有当用户已经播放过视频的该部分时,他们才能通过搜索栏快进/后退。

因此,如果用户是第一次观看视频,他们无法跳过当前位置,但他们可以在视频播放的位置前后搜索。

我正在努力解决 API onTime 事件等问题,尝试计算出数学公式来完成这项工作。

有谁知道如何做到这一点。

谢谢

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 ONLY if they have already played that part of the video.

So, if a user is watching the video for the first time they can't skip beyond the current position, however they can seek forward and back behind where the video played up until.

I'm struggling with the API onTime events etc. to try and work out the Math to make this work.

Does anyone know how this could be done.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傲世九天 2024-12-10 16:54:45

我不久前发现了这个,可能是在 JWplayer 论坛上。我想我添加了一些关于播放列表的内容。
因此,以防万一您或其他人仍在寻找答案,请考虑添加以下内容:

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

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;
    }   
 });
心意如水 2024-12-10 16:54:45

使用 @mal 的答案已经有一段时间了,但发现它在某些边缘情况下(例如单击和拖动)出现问题。可能是因为我们使用的是 JW 播放器 8?

不管怎样,如果有人仍在寻找这个问题的答案,得到了一个修改后的解决方案,可以很好地涵盖它们。依赖于 seeked 处理程序,该处理程序在发生寻道。

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

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;
});
小矜持 2024-12-10 16:54:45

这对我有用

var maxPlayPosition = 0.0;
jwplayer().on('time', function (event) {
        var position = jwplayer().getPosition();

        if (currentposition < maxPlayPosition + 1 && currentposition > maxPlayPosition) {
            maxPlayPosition = currentposition;
        }
        if (currentposition > maxPlayPosition) {
            jwplayer().seek(maxPlayPosition);
        }
});

Here's what worked for me

var maxPlayPosition = 0.0;
jwplayer().on('time', function (event) {
        var position = jwplayer().getPosition();

        if (currentposition < maxPlayPosition + 1 && currentposition > maxPlayPosition) {
            maxPlayPosition = currentposition;
        }
        if (currentposition > maxPlayPosition) {
            jwplayer().seek(maxPlayPosition);
        }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文