万户网络知识库 > 常见问题 > HTML5 video 在 iPhone 、 iPad、Browser 禁止全屏
HTML5 video 在 iPhone 、 iPad、Browser 禁止全屏
更新时间:2019-03-13 10:15:08 访问量:
前几天为了解决一个项目在iphone 6视频不能播放问题,寻找了很多资料,其中访问到了国外大神的论坛留言,以下是引入的片段。 英文不好怕翻译有误,所以留了原话。
-----------------------------------
I've created an HTML5 video player (very simple) that works perfectly on the iPad and the browser.
However, when I open it on the iPhone, I only get a play button which, when pressed, opens the native video player on a new window, on top of all my stuff.
That means I lose access to my custom controls and time tracking (written in Javascript), since the video is now running isolated.
Is there any way to override Apple's control of HTML5 video on the iphone and get it working like on the ipad?
Cheers
-------------------------------------------------
Technically you can't, but there are a couple libraries available that make it possible, like iphone-inline-video (disclosure: I wrote it) – bfred.it Apr 1 '16 at 5:14
8 Answers
Right,
I was going nowhere with this and filed a bug with Apple.
After a couple of weeks they got back to me saying, very simply, that I should add "webkit-playsinline" to the video tag on the HTML, as well as adding the "allowsInlineMediaPlayback" property on the UIWebView.
So in the end, this is what it looks like:
HTML
Obj-C
webview.allowsInlineMediaPlayback = YES;
And all works just fine :)
Hope this helps someone, as it's virtually undocumented and the only place I could find a reference to "webkit-playsinline" was in the iAds reference, where it says: "iAds JS only".
-----------------------------------------------
In iOS 10+
Apple enabled the attribute playsinline in all browsers on iOS 10, so this works seamlessly:
In iOS 8 and iOS 9
You can work around this issue by simulating the playback by skimming the video instead of actually .play()'ing it.
You can use iphone-inline-video to