你怎么能让Video.JS向前和向后跳15秒?

时间:2016-07-27 05:03:00

标签: javascript html5 video

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

我可以做些什么来让视频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> 

4 个答案:

答案 0 :(得分:6)

它有点晚了,但我使用currentTime:

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

希望这会有所帮助。

答案 1 :(得分:0)

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

答案 2 :(得分:0)

var player = videojs('video');

var skipBehindButton = player.controlBar.addChild("button");
var skipBehindButtonDom = skipBehindButton.el();
skipBehindButtonDom.innerHTML = "30<<";
skipBehindButton.addClass("buttonClass");
    
skipBehindButtonDom.onclick = function(){
    skipS3MV(-30);
}  

var skipAheadButton = player.controlBar.addChild("button");
var skipAheadButtonDom = skipAheadButton.el();
skipAheadButtonDom.innerHTML = ">>30";
skipAheadButton.addClass("buttonClass");
    
skipAheadButtonDom.onclick = function(){
    skipS3MV(30);
}  

function skipS3MV(skipBy) {
    player.currentTime(player.currentTime() + skipBy);
}

enter image description here

那是我为插件https://S3MediaVault.com完成的确切实现。

我使用文本(“ 30 <<”和“ >> 30”)的原因是因为在播放器中,颜色都是可自定义的。因此,如果我使用图标图像进行后退和前进,那么每次有人自定义播放器颜色(包括控制栏中的所有文本)时,我都无法更改图标的颜色。

答案 3 :(得分:0)

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){
        backward()
    }else{ 
        forward()
    }
  }
)