Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jwplayer seek() and onTime() to play bits of video

So I've been trying to manipulate my jwplayer which plays youtube videos with success but still encounter a bit of a problem.

I want my player to play from a "start time" and stop at en "end time". Those two values will be taken from two form inputs. So I went and wrote this little function which work quite well :

function timeControl(start, end) {
jwplayer().seek(start).onTime(function (event) {
    if(event.position >= end ) {
        this.stop();
    }
});

}

The thing is, if I run this function twice, the second time it will sometimes ignore the new parameters (for example if I set the start time at 3 seconds and end time at ten, if I run it again with the end time being 6seconds, it will work, but it won't if I start with end time at 6 and then at ten... )

Anybody has an idea of what's going on ? Anyway to reset the "onTime" property of the player without having to reload the player ?

Thanks in advance !

like image 252
Charleshaa Avatar asked Nov 03 '22 18:11

Charleshaa


1 Answers

I know this question is old, but I'm going to out on a limb and say that the problem simply might be that your generically referencing jwplayer, and not specifically referencing a jwplayer video instance.

<div id="aVideoObject">Loading the player...</div>

<script type="text/javascript">

    jwplayer("aVideoObject").setup({
        flashplayer: "player.swf",
        width: 450,
        height: 320
    });

    function timeControl(start, end) {
        jwplayer("aVideoObject").seek(start).onTime(function (event) {
            if(event.position >= end ) {
                this.stop();
            }
        });
    }
</script>

This implementation works for me

like image 117
RedactedProfile Avatar answered Nov 12 '22 16:11

RedactedProfile