Create button to advance video

0

I tried to create a function in javascript to allow it to be possible to skip a few seconds in a video, but clicking the button simply returns to the beginning.

var video = document.getElementById("video1");
var segundos = 30;
function skip(segundos) {
    video.currentTime += segundos;
}

function is called in HTML

            <button class="pular" onclick="skip(segundos)">Skip</button>

I followed the examples given in the link but it did not work .

    
asked by anonymous 05.05.2017 / 14:38

1 answer

0

With jquery it's easy

    function vidplay() {
       var video = document.getElementById("Video1");
       var button = document.getElementById("play");
       if (video.paused) {
          video.play();
          button.textContent = "||";
       } else {
          video.pause();
          button.textContent = ">";
       }
    }

    function restart() {
        var video = document.getElementById("Video1");
        video.currentTime = 0;
    }

    function skip(value) {
        var video = document.getElementById("Video1");
        video.currentTime += value;
    }

    $(document).ready(function(){
       var segundos = 30;
       document.getElementById("buttonbar").innerHTML = '<button id="restart" onclick="restart();">restart</button>\n<button id="rew" onclick="skip(-'+segundos+')">-'+segundos+'</button>\n<button id="play" onclick="vidplay()">></button>\n<button id="fastFwd" onclick="skip(+'+segundos+')">+'+segundos+'</button>';

    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><videoid="Video1">
     <source src="http://kithomepage.com/sos/deo.mp4"type="video/mp4" />
     <source src="demo.ogv" type="video/ogg" />
     HTML5 Video is required for this example. 
     <a href="demo.mp4">Download the video</a> file. 
</video>

<div id="buttonbar">
</div> 
    
05.05.2017 / 15:13