如何使Video.JS跳过15秒前进或后退?

14

播放/暂停按钮适用于HTML5视频和Video.JS,但我不确定为什么其他功能对于video.js无效,即使它们适用于HTML5视频?

我该怎么做才能让Video JS向前或向后跳过15秒?而且,由于某种奇怪的原因,视频大小也不会改变。

    <div id="instructions">
      <video id="my_video_1" class="video-js vjs-default-skin" width="640px" height="267px"
          controls preload="none" poster='http://video-js.zencoder.com/oceans-clip.jpg'
          data-setup='{ "aspectRatio":"640:267", "playbackRates": [1, 1.5, 2] }'>
        <source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4' />
        <source src="http://vjs.zencdn.net/v/oceans.webm" type='video/webm' />
      </video>
      <button onclick="playPause()">Play/Pause</button>  
      <button onclick="makeBig()">Big</button>
      <button onclick="makeSmall()">Small</button>
      <button onclick="makeNormal()">Normal</button>
      <button onclick="restart();">Restart</button> 
      <button onclick="skip(-10)">Rewind</button>
      <button onclick="skip(10)">Fastforward</button>
    </div>

    <script> 
    //controls for video.js HTML5 video player
    var myVideo = document.getElementById("my_video_1"); 

    function playPause() { 
        if (myVideo.paused) 
            myVideo.play(); 
        else 
            myVideo.pause(); 
    } 

    function makeBig() { 
        myVideo.width = 560; 
    } 

    function makeSmall() { 
        myVideo.width = 320; 
    } 

    function makeNormal() { 
        myVideo.width = 420; 
    } 

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

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

     </script> 

htmljs似乎返回了预期的结果? - guest271314
我尝试在这里运行了一下,但它无法正常工作...然而,在我的本地服务器上,除了video.js自己的CSS按钮模板之外,创建的播放/暂停可以正常工作,但其他功能都不行。 - user6173198
通常情况下,使用video.js如何使其工作? - user6173198
1
http://plnkr.co/edit/z5fXqYosypuGNJVcfiPE?p=preview - guest271314
所以问题出在 Video.JS 代码上... 嗯 - user6173198
javascript存在什么问题?http://plnkr.co/edit/z5fXqYosypuGNJVcfiPE?p=preview的`html`渲染有什么问题? - guest271314
3个回答

13

虽然有点晚,但我是这样使用currentTime的:

var video = videojs($("#player_id"));
video.currentTime(video.currentTime() + 10);

希望这能有所帮助。


7
const video=document.getElementById("videoId");

forward=()=>{
  skip(15);
}

backward=()=>{
   skip(-15);
}

skip=(time)=>{
  video.currentTime=video.currentTime+time;
}

使用箭头键进行控制

document.addEventListener("keydown",(e)=>{
    if(e.keyCode==37){       //left arrow
        backward()
    }else if(e.keyCode==39){ //right arrow
        forward()
    }
  }
)

3
seek(secs) {
  let time = this.player.currentTime() + secs;

  if (time < 0) {
    time = 0;
  }

  this.player.currentTime(time);
},

forward() {
  this.seek(10);
},

rewind() {
  this.seek(-10);
},

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接