YouTube API not working with iPad / iPhone / non-Flash device(YouTube API 不适用于 iPad/iPhone/非 Flash 设备)
问题描述
这段代码在桌面浏览器中运行良好(代码由@Rob-W 提供),点击缩略图,相邻的视频将开始播放,使用 YouTube 的 API.
HTML
CSS
JS
JSFiddle
问题是它无法在 iOS 设备上播放(我认为是因为缺少 Flash 播放器,它只是挂起).
我可以通过再次点击视频来强制它播放,这会提示它使用 QuickTime 播放.
但是如何让它自动与 QuickTime 一起播放呢?
很抱歉,这在 iOS 中是不可能的.根据 Apple 的文档,
<块引用>"...嵌入式媒体无法在 iOS 上的 Safari 中自动播放 -用户总是启动播放."
无论网络连接如何,限制都是一致的,因为它既是带宽决定,也是用户体验决定.
2016 年 10 月更新:值得注意的是,现在 iOS 10 已经发布并获得了可观的市场份额,人们可以利用 iOS 10 上视频播放方式的变化来获得自动播放行为.如果视频没有音轨或标签被静音,则可以进行自动播放.此 webkit 博客 中提供了更多信息.YouTube API 可能很快就能很好地处理这个问题.
This piece of code works great in DESKTOP browsers (code courtesy of @Rob-W), click the thumbnail and the adjacent video will start playing, using YouTube's API.
HTML
CSS
JS
JSFiddle
The problem is that it fails to play on iOS devices (because of the lack of Flash player, I think, it just hangs).
I can force it to play by tapping the video once more, which prompts it to play using QuickTime.
But how do I get it to play with QuickTime automatically?
I'm sorry to say this is not possible in iOS. According to Apple's documentation,
"...embedded media cannot be played automatically in Safari on iOS - the user always initiates playback."
The restriction is consistent regardless of network connection as it is both a bandwidth decision as well as a user experience decision.
Update, October, 2016: It's worth noting, now that iOS 10 is out and gaining significant market share, that people can leverage changes in the way video playback works on iOS 10 to get autoplay behavior. If the video has no audio tracks or the tag is muted, autoplay can be possible. More information is available in this webkit blog. The YouTube API may handle this nicely soon.
这篇关于YouTube API 不适用于 iPad/iPhone/非 Flash 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!