Reputation:
The Play pause button works for HTML5 video and this Video.JS. I am not sure why the other functions don't work for video.js, even though they work for HTML5 video?
What can I do to make video JS skip forward and backwards 15 seconds? Also, for some weird reason the video won't change size either.
<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>
Upvotes: 14
Views: 35109
Reputation: 735
const video=document.getElementById("videoId");
forward=()=>{
skip(15);
}
backward=()=>{
skip(-15);
}
skip=(time)=>{
video.currentTime=video.currentTime+time;
}
For contorlling with arrow keys
document.addEventListener("keydown",(e)=>{
if(e.keyCode==37){ //left arrow
backward()
}else if(e.keyCode==39){ //right arrow
forward()
}
}
)
Upvotes: 9
Reputation: 75686
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);
},
Upvotes: 3
Reputation: 151
it's a bit late but i use currentTime like this:
var video = videojs($("#player_id"));
video.currentTime(video.currentTime() + 10);
Hope this will help.
Upvotes: 13