HTML5 视频全屏无法在 iPad 上运行
我有一个 html5 视频流。我使用自定义控件,并使用 jQuery 将操作绑定到它们。其中一个控件是全屏按钮,它调用 video.webkitEnterFullScreen()。当我在 Safari 全屏中测试它时效果很好。当我在 iPad 上尝试此操作时,它失败了。什么给?
这是我在 html 中声明视频的方式:
<video preload="true" width="720" height="405"></video>
这是我的全屏按钮的声明:
<a href="javascript:;" class="fullscreen">
<span class="icon"></span>
</a>
这是我将按钮绑定到操作的方式:
var video = $('video')[0];
$('body').find('.fullscreen').click(function(){
video.webkitEnterFullscreen();
});
$('body').find('.fullscreen .icon').click(function(){
video.webkitEnterFullscreen();
});
同样,这在 safari 中有效,但在 ipad 上无效。当将警报和日志语句包含到函数声明中时,它们就会出现,这意味着我的点击确实在 ipad 上注册了,但视频不会进入全屏模式。帮助!
更新:只是为了澄清我的问题,我在播放时没有遇到问题。该视频可在 Safari 桌面版和 iPad 版 Safari 中播放。在桌面版 safari 上,全屏可以工作,但在 ipad 版 safari 上,全屏不起作用。
I have an html5 video stream. I use custom controls, and bind actions to them using jQuery. One of these said controls is a fullscreen button, which calls video.webkitEnterFullScreen(). When i test this out in Safari fullscreen works fine. When I try this on an iPad it fails. What gives?
Here is how i declare my video in html:
<video preload="true" width="720" height="405"></video>
Here is the declaration of my fullscreen button:
<a href="javascript:;" class="fullscreen">
<span class="icon"></span>
</a>
Here is how I bind the button to the action:
var video = $('video')[0];
$('body').find('.fullscreen').click(function(){
video.webkitEnterFullscreen();
});
$('body').find('.fullscreen .icon').click(function(){
video.webkitEnterFullscreen();
});
Again this works in safari but not on the ipad. When include alerts and logging statements into the function declaration they appear, meaning that my clicks did register with the ipad, but the video does not go into fullscreen mode. Help!
UPDATE: Just to clarify my issue, i am not having trouble with playback. The video plays in both safari desktop and safari for the ipad. On safari for the desktop, fullscreen works, but on safari for the ipad fullscreen does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
坏消息抱歉...到目前为止 iPad 还不支持 webkitEnterFullscreen。好消息是规范已在此处起草:http://dvcs。 w3.org/hg/fullscreen/raw-file/tip/Overview.html
我们需要再等一会儿才能发生......
Bad news sorry... So far webkitEnterFullscreen is not supported by iPad. Good news is specs has been draft here: http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html
We will need to wait little bit more for that to happen...
一件事,虽然我不确定它在这里重要,但
preload="true"
不再有效。preload
可以设置为以下之一:metadata
、none
或auto
(这可能就是它被设置为的内容)这里)。也许 iPad
auto
默认设置是不预加载任何内容,所以也许尝试将其设置为metadata
?也请查看此。
One thing, although I'm not sure it matters here, but
preload="true"
is no longer valid.preload
can be set to one of:metadata
,none
orauto
(which is probably what it's being set to here).Perhaps the iPad
auto
default is not to preload anything, so perhaps try setting it tometadata
?Check out this too.
因此,经过艰苦繁琐的调试后,我发现了问题的原因。我检查了所有可以由播放器继承的 CSS 规则,并切换它们(将它们注释掉然后再注释掉),看看会产生什么效果。终于我找到了罪魁祸首。我的视频所在的 div 最初有一个 css 类,其规则为“可见性:隐藏”。当用户按下页面上的按钮时,jQuery 会触发一个命令将此规则从“隐藏”更改为“可见”。从初始 css 类中删除“可见性:隐藏”规则使我能够在 ipad 上全屏显示。现在我可以在 ipad 上全屏显示,但我的项目设计不起作用,但这是另一篇文章的问题。我希望这可以帮助处于类似情况的其他人。
So after painstakingly tedious debugging i discovered the cause of my problem. I went through all my css rules that could be inherited by the player, and toggled them (commented them out and then back in), to see what effect that would have. Finally i found the culprit. The div that my video sits on, initially has a css class which has a rule 'visibility: hidden'. When the user presses a button the page, jQuery fires a command to change this rule from 'hidden' to 'visible'. Removing the 'visibility: hidden' rule from the initial css class allowed me to full screen on an ipad. Now I can fullscreen on the ipad, but my project design doesn't work, but that's a question for another post. I hope this helps someone else in a similar situation.
Apple 最近(截至 2019 年初)将 iPadOS 从 iOS 中分离出来,早在去年(2018 年)秋天,他们就在 iPad Safari 上提供了对全屏 api 的支持。
现在,您可以在 iPadOS Safari 上支持全屏 Web 应用程序。下面分享的是跨浏览器和 iPadOS 12.x+ 仅限 Safari 的解决方案以及必要的代码:
在 iPad Safari 上全屏显示。
披露:我已在上述链接上撰写了博客。请注意,iPadOS 上的 Chrome 仍然不支持全屏 api,但从这里开始只会变得更好。
Apple separated the iPadOS from iOS recently (as of early 2019) and they came up with support for fullscreen api on iPad Safari as early as fall of last year (2018).
You can now support fullscreen web apps on iPadOS Safari. Share below is a cross-browser and iPadOS 12.x+ Safari only solution along with requisite code:
Going fullscreen on iPad Safari.
Disclosure: I have written the blog on the aforementioned link. Note that Chrome on iPadOS still doesn't have support for the fullscreen api, but it will only get better from here.