Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView youtube iframe api autoplay/playsinline quit working in iOS7

This code has worked really well to auto-play video inline in an iOS 6 uiwebview. However, I upgraded to iOS 7 and now my video will not auto-play. Sometimes video will auto-play and sometimes it won't. It will auto-play about 10% of the time. Most of the time I get a spinning wheel. If I remove &playsinline=1 from the src tag it will auto-play fullscreen (not what I want). I spent a lot of time creating a custom player for this app and now it won't work correctly. Any help is greatly 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's a link to a quick test file. videoPlayerTest.zip

like image 463
Steve McIntyre Avatar asked Oct 07 '13 22:10

Steve McIntyre


1 Answers

This sounds like the following open bug against the Youtube iframe player API:

Issue 5204: js iframe api playVideo() doesn't play video in iOS 7

http://code.google.com/p/gdata-issues/issues/detail?id=5204

like image 117
absurd1 Avatar answered Oct 01 '22 12:10

absurd1