Due to Apple, they have limited auto-play features to prevent cellular network data outages. In xcode4, I added a workaround. In your "webViewDidFinishLoad" Send a javascript call to automatically play the video and it works. I tried this in an html file with regular javascript, but that didn't work. However, do it through webViewDidFinishLoad. In this example, I want to automatically play the video in my index.html page. I have a javascript function on this page called startVideo ().
- (void)webViewDidFinishLoad:(UIWebView *)webView{ NSURLRequest* request = [webView request]; NSString *page = [request.URL lastPathComponent]; if ([page isEqualToString:@"index.html"]){ NSString *js = @"startVideo();"; [myWebMain stringByEvaluatingJavaScriptFromString:js]; } }
And here is my javascript function:
<script> function startVideo(){ var pElement3 = document.getElementById('myVideo'); pElement3.play(); } </script>
And here is the html if you are new to html video
<video id="myVideo" poster="index_poster.png" width="1024" height="768" xcontrols autoplay="autoplay"> <source src="flow.m4v" type="video/mp4"/> browser not supports the video </video>
source share