Steve Yancharas Jr.
Steve Yancharas Jr.

Reputation: 163

Add 5 second delay before video autoplays

I'm trying to add a 5 second delay to video.js before it starts auto-playing, but can't figure out how to with this implementation:

$('.video-js').each(function () {
    var element = $(this);
    var id = element.attr('id').replace('#', '');
    var heading_links = element.parents('.post-images-wrapper').find('.pcos-heading-links');

    _V_(id).ready(function() {
        var video_player = this, options = video_player.options();

        if (options.autoplay) { heading_links.hide(); }

        video_player.on('ended', function() {  
            video_player.posterImage.show();  
            video_player.currentTime(0);  
            video_player.controlBar.hide();  
            video_player.bigPlayButton.show();  
            video_player.cancelFullScreen();
            heading_links.show();  
        });  

        video_player.on('play', function() {
            video_player.posterImage.hide();  
            video_player.controlBar.show();  
            video_player.bigPlayButton.hide();
            heading_links.hide();
        });  

    });
});

Upvotes: 0

Views: 1430

Answers (1)

heff
heff

Reputation: 3239

If you're using _V_ then you're probably on an old version of video.js. Later versions just use videojs This should still work, but you should also upgrade.

First make sure you no longer have the autoplay attribute on your video tag. Then:

_V_(id).ready(function(){
  var player = this;

  setTimeout(function(){
    player.play();
  }, 5000);
});

Upvotes: 2

Related Questions