YouTube 自动播放不起作用 [英] YouTube Autoplay not working

查看:119
本文介绍了YouTube 自动播放不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有一个播放器可以播放多个视频.我一直在调整代码以使用 YouTube 的 iframe API 作为播放器.我无法让视频自动播放.相关代码如下:

My website has a player for multiple videos. I've been adapting the code to use YouTube's iframe API as the player. I can't get the videos to autoplay. Here's the relevant code:

    <body>
          <iframe id="existing-iframe-example"
              width="640" height="360"
              src="https://www.youtube.com/embed/-SFcIUEvNOQ?   autoplay=1&;enablejsapi=1"
              frameborder="0"
              autoplay="1"
              style="border: solid 4px #37474F"
              ></iframe>
        <div id="player"></div>

        <div id="movieButtons" class="movieButtons">
        <button class="movieButton" data-movieAdr="1-VjtC939_Q">Memorial Slide Show</button>

其余的是标准的 YouTube iframe API 脚本.您可以看到我尝试将 Autoplay=1 设置为 iframe 参数和 iframe src 的一部分.我也试过将它包含在按钮的数据中.这些似乎都不起作用.单击按钮时会加载视频,但不会自动播放.

The rest is standard YouTube iframe API script. You can see I tried setting Autoplay=1 as both an iframe parameter and as part of the iframe src. I've also tried including it in the data in the button. None of these seems to work. The vids load when the buttons are clicked, but they don't autoplay.

推荐答案

它从 2018 年 4 月起就失效了,因为 Google 决定让用户更好地控制播放.您只需要将 &mute=1 添加到您的 URL 中.自动播放政策变更

It's not working since April of 2018 because Google decided to give greater control of playback to users. You just need to add &mute=1 to your URL. Autoplay Policy Changes

<iframe id="existing-iframe-example"
          width="640" height="360"
          src="https://www.youtube.com/embed/-SFcIUEvNOQ?autoplay=1&mute=1&enablejsapi=1"
          frameborder="0"
          style="border: solid 4px #37474F"
          ></iframe>

更新:

Chrome 73 中的音频/视频更新

Audio/Video Updates in Chrome 73

谷歌说:既然渐进式 Web 应用程序 (PWA) 在所有桌面平台上都可用,我们正在将我们在移动设备上的规则扩展到桌面:现在允许已安装的 PWA 自动播放声音.请注意,它仅适用于 Web 应用清单范围内的页面.https://developers.google.com/web/updates/2019/02/chrome-73-media-updates#autoplay-pwa

Google said : Now that Progressive Web Apps (PWAs) are available on all desktop platforms, we are extending the rule that we had on mobile to desktop: autoplay with sound is now allowed for installed PWAs. Note that it only applies to pages in the scope of the web app manifest. https://developers.google.com/web/updates/2019/02/chrome-73-media-updates#autoplay-pwa

这篇关于YouTube 自动播放不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆