Is it possible to get a youtube video to autoplay on Safari and/or UIWebView? I\'ve seen this done in an iPhone app, the tableview displays cells that do not have Youtube pr
the trick is to find the button in the webview. Use the following snippet.
- (void)loadWebUIViewWithYoutubeLink {
webView.delegate = self;
NSString *htmlString = [NSString stringWithFormat:[NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"YouTubeTemplate" ofType:@"txt"]],
@"b85hn8rJvgw", @"b85hn8rJvgw", nil];
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://youtube.com"]];
}
- (UIButton *)findButtonInView:(UIView *)view {
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) {
for (UIView *subview in view.subviews) {
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView {
UIButton *b = [self findButtonInView:_webView];
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}