HTML5 Video Autoplay on iOS Sample App
Link to my HTML5 Video Autoplay on iOS Sample App GitHub repo
As part of a current project building a large hybrid native/web iPad app, some issues came up regarding iOS 7 and 8 and HTML5 content in a UIWebView with an autoplaying video.
This is an area where Mobile Safari differs from the UIWebView that iOS developers can embed into their own apps. Mobile Safari doesn’t allow video to autoplay, ostensibly to protect users on cellular data plans from large data charges. As far as I can tell, its behavior doesn’t change if the device is on a wifi network, so there may be other reasons.
There are many StackOverflow issues about this, some of which appear to be outdated, so the easiest thing for me to do was to build a quick, simple app to test out HTML5 autoplay. The key setting to know is that you must change the UIWebView to allow media playback without user interaction - you can set this in the Storyboard, or you can set it via code:
self.webView.mediaPlaybackRequiresUserAction = NO;
You don’t need any kind of Javascript to let the HTML5 video autoplay - simply set the autoplay attribute on the video tag, and you’ll be able to run the video as soon as the HTML loads.