嵌入式 YouTube iframe 不再自动播放 [英] Embedded YouTube iframes No Longer Autoplay

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

问题描述

我们的网络应用中有许多视频引用,它们将 YouTube 视频作为嵌入式 iframe 延迟加载.我们希望视频自动播放,这样用户一次点击就足以将 YouTube iframe 加载到页面中并开始播放.几个月前,我们已经开始使用此功能,但自动播放不再发生.我知道 2018 年春季对 Google/YouTube 政策进行了更新,限制了自动播放;最近有什么我不知道的变化吗?否则,有人知道为什么这可能会停止工作吗?

We have a number of video references in our web app which lazy load YouTube videos as embedded iframes. We want to have the videos autoplay so a single user click will suffice to load the YouTube iframe into the page and start its playback. We've had this working as recently as a few months ago, but the autoplay is no longer occurring. I know there was an update to Google/YouTube policies in the spring of 2018 which limited autoplay; has there been a more recent change I don't know about? Otherwise, does anyone know why this might have stopped working?

我尝试了我可以在网上找到的最新 iframe 示例,其中包含多种变体(例如,使用和不使用静音=1).这些似乎都不起作用.

I've tried the most recent iframe examples I could find online, with several variations (e.g., with and without mute=1). None of these seem to work.

以下是我们的 iframe 标记示例:

Here's an example of our iframe markup:

<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>

推荐答案

由于普遍滥用,主要浏览器已禁用这些功能.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
https://blog.mozilla.org/firefox/block-autoplay/

Major browser have disabled these features due to general abuse.
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
https://blog.mozilla.org/firefox/block-autoplay/

YouTube 在加载时检查它是否有权播放视频.只有在获得适当权限的情况下才会自动播放.最近的 Chrome 和 Firefox 版本的默认设置是只允许视频 - 没有声音.添加 &mute=1 youtube URL 允许(静音)自动播放.如果您不一定需要声音,则此方法有效,如果需要,则必须让用户自己点击播放.

YouTube checks upon loading whether it has permission to play how it wants to play the video. It will only autoplay if it has proper permission. The default in recent Chrome and Firefox builds is to only allow video - no sound. Adding &mute=1 the the youtube URL allows (muted) autoplay. This works if you don't necessarily need the sound, if you do then you will have to make the user click play themselves.

将此应用于示例中的嵌入:
<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&mute=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>

Applying this to the embed in your example:
<iframe allow="autoplay" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/sapLz6NjvJk?autoplay=1&mute=1&origin=https://OurWebsiteDomain" title="Bug Week " height="278" data-ytbridge="vidSurrogate2" style="width: 100%;"></iframe>

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

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