Noobie
Noobie

Reputation: 15

How to pause video automatically after 10 seconds in video.js?

I want to pause a video automatically after playing 10 seconds.

Here is HTML code

<video id="video_kgvid_0" controls preload="metadata" 
 poster="video poster url" width="640" height="267" class="fitvidsignore video-js kg-
 video-js-skin">
 <source src="video url" type="video/mp4" data-res="534p">
 </video>

So far tried this JS code

var pausetime = 10; 

var myPlayer = videojs('video_kgvid_0');

myPlayer.on('timeupdate', function (e) {
    if (myPlayer.currentTime() >= pausetime) {
        myPlayer.pause();
    }
});

myPlayer.play();

Please be noted that I am using a plugin called "Video Embed & Thumbnail Generator" on a WordPress site.

Upvotes: 0

Views: 2496

Answers (1)

lakshman rajput
lakshman rajput

Reputation: 507

Yes you can try this

   var pausetime = 10; 

var myPlayer = videojs('video_kgvid_0');

myPlayer.on('timeupdate', function (e) {
    if (myPlayer.currentTime() >= pausetime) {
        myPlayer.pause();
        pausetime = Number(myPlayer.currentTime()) + 10;
    }
});

myPlayer.play();

Upvotes: 1

Related Questions