JS YouTube Embed 交换在不同 iOS 版本上不一致
所以我正在开发一个移动网站,上面有一些视频。我使用提供的 YouTube API 在不同设备上的 Flash 和 HTML5 之间切换,但出于几个不同的原因,我使用自定义缩略图。
我使用一些 JavaScript 来隐藏 YouTube iframe,直到用户单击图片,然后应该将图像替换为视频 onClick,调用 switchItUp
方法。
var video = document.getElementById("VideoID");
var image = document.getElementById("PlaceholderImage");
video.style.display = "none";
function switchItUp() {
var video = document.getElementById("VideoID");
var image = document.getElementById("PlaceholderImage");
image.style.display = "none";
video.style.display = "block";
}
API 指定的 YouTube 代码如下(仅在页面上运行):
<iframe src="http://www.youtube.com/embed/BaKcl0Qg13o?autoplay=1" width="300" height="190"></iframe>
这是有趣的部分。
- 这在 4.0 版 Safari 中效果很好。
- 在 4.1 中,onClick 显示了视频,但无法播放。
- 在 4.2 中,视频根本不显示,但当图像隐藏时,页面上会留下巨大的空白。
它在所有桌面浏览器上都能很好地工作,因此调试这是一个问题。
任何帮助表示赞赏!蒂亚!
编辑: 播放器必须处于自动播放状态,才能在点击 1 次后进行交换,因此页面上必须以 display:none 的形式开始。
另外,容器会导致这个问题吗?它当前正在页面上的 内呈现,该页面在 display:none 之前没有设置 display:block。
So I'm working on a mobile site that has some videos on it. I am using the provided YouTube API for switching between flash and HTML5 on different devices, but I am using custom thumbnails for those for a couple different reasons.
I use some javascript to hide the YouTube iframe until a user clicks on a picture, and then it is supposed to swap out the image for the video onClick, calling the switchItUp
method.
var video = document.getElementById("VideoID");
var image = document.getElementById("PlaceholderImage");
video.style.display = "none";
function switchItUp() {
var video = document.getElementById("VideoID");
var image = document.getElementById("PlaceholderImage");
image.style.display = "none";
video.style.display = "block";
}
The YouTube code, as specified by the API, is as follows (and works when on the page alone):
<iframe src="http://www.youtube.com/embed/BaKcl0Qg13o?autoplay=1" width="300" height="190"></iframe>
Here's the fun part.
- This works great in Safari on 4.0.
- In 4.1 the onClick shows the video, but you can't play it.
- In 4.2 the video doesn't show at all, but leaves a giant blank space on the page when the image hides.
It works great on all the desktop browsers, so debugging this is a problem.
Any help is appreciated! TYIA!
EDIT: The player must be on autoplay for the swap to work on 1 click, so it must start out as display:none on the page.
Also, would the container cause this problem? It's currently rendering inside a <span>
on the page, that doesn't have display:block set before display:none.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试通过将视频放置在屏幕之外来隐藏视频,而不是使用
display=none
。这是解决此类问题的经典方法。然后你可以“展示”它
Try to hide the video by positioning it off the screen rather than using
display=none
. This is a classic work around for this kind of problem.Then you can 'show' it with
由于自动播放在 4.2 中不起作用,我们决定取消缩略图交换。没有一种方法可以在所有 iOS 版本上执行此操作。所以我们只是使用一些 YouTube 生成的缩略图。
Because of the autoplay doesn't work in 4.2 we decided to get rid of the thumbnail swap. There isn't a way to do this that works across all iOS versions. So we are just using some youtube-generated thumbnails.