This code is perfect for automatically playing videos in iOS 6 uiwebview. However, I upgraded to iOS 7 and now my video will not automatically play. Sometimes the video will play automatically, and sometimes not. It will automatically play in about 10% of cases. Most of the time I get a spinning wheel. If I remove & playinline = 1 from the src tag, it will automatically play full screen (not what I want). I spent a lot of time creating a custom player for this application, and now it will not work correctly. Any help is appreciated.
_youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, 320, 184)]; _youTubeWebView.delegate = self; _youTubeWebView.scrollView.bounces = NO; _youTubeWebView.allowsInlineMediaPlayback = YES; _youTubeWebView.mediaPlaybackAllowsAirPlay = YES; _youTubeWebView.mediaPlaybackRequiresUserAction = NO; [self.view addSubview:_youTubeWebView]; NSString* embedHTML = [NSString stringWithFormat:@"<html><body style='margin:0px;padding:0px;'><script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){ a.target.playVideo(); }</script><iframe id='playerId' type='text/html' width='%@' height='%@'src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&controls=0&showinfo=0' frameborder='0'></body></html>", w, h, videoId]; [_youTubeWebView loadHTMLString:embedHTML baseURL:nil];
Here is a link to a quick test file. videoPlayerTest.zip
source share