如何在 iframe 中嵌入自动播放的 YouTube 视频? [英] How to embed an autoplaying YouTube video in an iframe?

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

问题描述

我正在尝试嵌入 YouTube 视频的新 iframe 版本并让它自动播放.

I am trying to embed the new iframe version of a YouTube video and get it to auto play.

据我所知,没有办法通过修改 URL 的标志来做到这一点.有没有办法通过使用 JavaScript & 来做到这一点?API?

As far as I can tell, there is no way of doing this by amending flags to the URL. Is there a way to do it by using JavaScript & the API?

推荐答案

这适用于 Chrome 但不适用于 Firefox 3.6(警告:RickRoll 视频):

This works in Chrome but not Firefox 3.6 (warning: RickRoll video):

<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>

用于 iframe 嵌入的 JavaScript API 存在,但仍作为实验性功能发布.

The JavaScript API for iframe embeds exists, but is still posted as an experimental feature.

更新:现在完全支持 iframe API,并且创建 YT.Player 对象 - 示例 2" 展示了如何在 JavaScript 中设置自动播放".

UPDATE: The iframe API is now fully supported and "Creating YT.Player objects - Example 2" shows how to set "autoplay" in JavaScript.

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

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