I have a UIWebView subclass that I used to play both youtube and local videos. Worked perfectly under iOS6. In upgrading to iOS7 I\'ve encountered a problem I don\'t really kn
This is the tested code in IOS7 , its working fine
[self embedYouTube:[self getYTUrlStr:@"https://www.youtube.com/watch?v=Zq4o_Ca14aw"] frame:CGRectMake(0,40,self.view.frame.size.width, self.view.frame.size.height-40)];
- (NSString*)getYTUrlStr:(NSString*)url
{
if (url == nil)
return nil;
NSString *retVal = [url stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"v/"];
NSRange pos=[retVal rangeOfString:@"version"];
if(pos.location == NSNotFound)
{
retVal = [retVal stringByAppendingString:@"?version=3&hl=en_EN"];
}
return retVal;
}
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
NSString* embedHTML = @"\
\
\
\
\
";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
if(videoView == nil) {
videoView = [[UIWebView alloc] initWithFrame:frame];
videoView.delegate=self;
[self.view addSubview:videoView];
}
videoView.mediaPlaybackAllowsAirPlay=YES;
videoView.allowsInlineMediaPlayback=YES;
[videoView loadHTMLString:html baseURL:nil];
}