Can't launch embedded Youtube video by clicking play button with UIWebView

I have a Youtube video embedded in a UIWebView on iOS and it is working correctly so far. The Poster video frame appears, and the usual red Play button appears on it. Clicking on the play button does nothing, except clicking on the button outside the play button starts the video. At first I thought it was an iOS 8 related issue, but the same issue occurs on iOS 7 (simulator) as well. This is very annoying as our users will naturally hit the play button and do nothing.

Does anyone know if Youtube has changed anything that might be causing this?

Here is the code I am using to display the video in the application:

NSString* urlString = [NSString stringWithFormat:@"", videoId];
NSMutableString* html = [[[NSMutableString alloc] initWithCapacity:1] autorelease];
[html appendString:@"<html><head>"];
[html appendString:@"<style type=\"text/css\">"];
[html appendString:@"body {"];
[html appendString:@"background-color: transparent;"];
[html appendString:@"color: white;"];
[html appendString:@"}"];
[html appendString:@"</style>"];
[html appendString:@"</head><body style=\"margin:0\">"];
[html appendFormat:@"<iframe class='youtube-player' type='text/html' width='%0.0f' height='%0.0f' src='%@' frameborder='0'></iframe>", frame.size.width, frame.size.height, urlString];
[html appendString:@"</body></html>"];

NSLog(@"Opening HTML: %@", html);
videoView2 = [[UIWebView alloc] initWithFrame:frame];
[videoView2 setMediaPlaybackRequiresUserAction:NO];
[videoView2 loadHTMLString:html baseURL:nil];



source to share

1 answer

I also ran into this problem and it seems that there is work related to the YouTube player "control" option. If you set "controls = 0" (default "controls = 1") the red play button can be clicked. I don't really like this solution as it explicitly hides the controls, but it allows the red play button to be clicked.



All Articles