在视频自动播放之前添加 5 秒延迟



我正在尝试在视频开始自动播放之前为视频添加 5 秒的延迟.js但无法弄清楚如何使用此实现:

$('.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();
        });  
    });
});

如果您使用的是_V_那么您可能使用的是旧版本的视频.js。更高版本只使用videojs 这应该仍然有效,但您也应该升级。

首先,请确保您的视频代码中不再包含 autoplay 属性。然后:

_V_(id).ready(function(){
  var player = this;
  setTimeout(function(){
    player.play();
  }, 5000);
});

最新更新