【问题标题】:youtube embed video autoplay is not working with sound unmuted in google chrome, while it works for firefoxyoutube 嵌入视频自动播放不适用于谷歌浏览器中未静音的声音,但它适用于 Firefox
【发布时间】:2019-04-07 21:40:11
【问题描述】:

我尝试从 3 天开始使用“声音未静音”在 google chrome 中自动播放 youtube 嵌入视频,但它不起作用。虽然具有相同代码的相同视频适用于 Mozilla Firefox。我尝试了不同的代码,但到目前为止都没有成功。

这里是代码。

<head>
    <style>
        body{
            margin-left: 0px;
        }
    </style>
</head> 
<script src="js/jquery-3.1.1.min.js"></script>
<div id="YouTubeVideoPlayer"></div>

<script async src="https://www.youtube.com/iframe_api"></script>
<script>
 function onYouTubeIframeAPIReady() {
  var player;
  player = new YT.Player('YouTubeVideoPlayer', {
    videoId: 'M7lc1UVf-VE', // YouTube Video ID
    width: 560,               // Player width (in px)
    height: 316, 
    start:0,             // Player height (in px)
    playerVars: {
      autoplay: 1,        // Auto-play the video on load
      controls: 1,        // Show pause/play buttons in player
      showinfo: 0,        // Hide the video title
      modestbranding: 1,  // Hide the Youtube Logo
      loop: 1,            // Run the video in a loop
      fs: 0,              // Hide the full screen button
      cc_load_policy: 0, // Hide closed captions
      iv_load_policy: 3,  // Hide the Video Annotations
      autohide: 0         // Hide video controls when playing
    },
    events: {
      onReady: function(e) {
       e.target.setVolume(40);
      }
    }
  });
 }

$("body").animate({ margin: "400px 0px 0px 0px" }, 18000 );

</script>

【问题讨论】:

  • 您是否可以或尝试过关注this 文档?
  • @Towkir 是的,我也尝试过此页面中的代码。
  • @dev ,您的代码对我来说完美运行。刚刚使用您的代码创建了一个 html 文件,它可以工作。虽然当我尝试在答案部分创建代码 sn-p 时它不起作用。可能是因为它在 iframe 中。

标签: javascript jquery youtube jsapi


【解决方案1】:

您需要将静音设置为 0,并且在视频开始播放后,您需要在 0:01 秒触发以将音量恢复到 40。

【讨论】:

    猜你喜欢
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2012-04-28
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多