【问题标题】:YTPlayer background video does not play automaticallyYTPlayer 背景视频不自动播放
【发布时间】:2019-10-06 02:09:37
【问题描述】:

我已经集成了插件https://github.com/pupunzi/jquery.mb.YTPlayer,按照文档示例,我无法自动启动视频,用户必须点击播放。

有一种方法可以模拟这种点击,或者有一些解决方案可以让视频在没有任何用户操作的情况下开始加载。

示例完整代码: https://jsfiddle.net/py7bkox3/

HTML

<div id="video"></div>
<div id="ctn">
  <h1>TITLE EXAMPLE</h1>
</div>

Javascript:

// When the document is ready
$(document).ready(function(){

  // Initialize YouTube player
  $("#video").YTPlayer({
    // URL of the YouTube video
    videoURL:'https://youtu.be/BsekcY04xvQ',
    // If you want it as background of your website
    // or of an element e.g #elementId
    containment: "#ctn",
    autoplay: true,
    controls: 0,
    mute: true,
    startAt: 0,
    opacity: 1,
    // Hide YouTube Controls
    showControls: false,
    onReady: function(){
    },
    onError: function(err){
      console.log("An error ocurred", err);
    }
  });
});

CSS

#ctn {
  display: block;
  margin: 0;
  padding: 250px 0 !important;
  width: 100%;
}

【问题讨论】:

    标签: javascript jquery html css youtube


    【解决方案1】:

    许多浏览器都会阻止有或没有声音的自动播放。这可能是您的浏览器的问题,而不是代码本身的问题。

    这是我在 Firefox 中的自动播放设置的屏幕截图。我会检查你的浏览器设置,看看它是否阻止自动播放。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-19
      • 2017-11-20
      • 2018-11-01
      • 1970-01-01
      • 2022-10-16
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多