<div id="made-in-ny"></div>

<script src="https://player.vimeo.com/api/player.js"></script>
<script>
    const options = {
        id: 59777392,
        width: 640,
        loop: true
    };

    const player = new Vimeo.Player('made-in-ny', options);
    var timeWatched = 0;


    player.on("timeupdate", function(data) {
      if (data.seconds - 1 < timeWatched && data.seconds > timeWatched) {
        timeWatched = data.seconds;
                /*This prevents seeking. The reason this is needed
            is because when the user tries to seek, a time update is called which results in the
            watchedTime becoming the same as the seeked time before it goes into the function 'seeked' (below) resulting
            in both values being the same. We need to get the most recent time update before the seek.
            (data.seconds - 1 < currentTime) basically if you seek, this will return false and the current time wont get updated
            (data.seconds > currentTime) if they seek backwards then dont update current time so they can seek back to where they were before*/

      }
    });

    player.on("seeked", function(data) {
      if (timeWatched < data.seconds) {
        player.setCurrentTime(timeWatched);
        console.log('Verderspoelen mag niet!');
        $( "#nspln" ).remove();
        $( "#made-in-ny" ).append( '<div id="nspln" class="text-primary">Vooruitspoelen is niet toegestaan</p>' );
        //alert('Vooruitspoelen is niet toegestaan.');
      }
    });
    //playerr.setVolume(0);
    player.on('play', function() {
        console.log('played the video!');
    });
    player.on('pause', function() {
        console.log('paused the video!');
    });
    player.on('ended', function() {
        console.log('Finished.');
    });
    player.on('getPlayed', function() {
        console.log('Finished.');
    });
    player.getVideoTitle().then(function(title) {
        console.log('title:', title);
    });
</script>

Geef een reactie 0