I am trying to embed a youtube video and automatically run it in my application. The code does not work on iOS6, however it works fine on earlier iOS 5.
I do it as follows:
-(IBAction)playVideo:(id)sender {
myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
myWebView.delegate = self;
[myWebView setAllowsInlineMediaPlayback:YES];
myWebView.mediaPlaybackRequiresUserAction=NO;
[myWebView loadHTMLString:[NSString stringWithFormat:@"<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"300\"></embed>", @"http://www.youtube.com/watch?v=TbsXUJITa40"] baseURL:nil];
}
- (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];
}
So, when the webview is loaded, it automatically finds uibutton and the video starts. I can’t understand why in iOS 6 this method no longer works. He uploads a video but nothing appears ...
Can anybody help me? I'm going crazy to try to solve it ...
Piero source
share