我正在尝试在 iOS 6.0 的应用程序中从 YouTube URL 播放 YouTube 视频 Belo 是我的代码。它无法播放视频。请建议。
- (void) playYouTubeVideoWithUrl:(NSString*) youTubeUrl andFrame:(CGRect)aFrame
{
UIWebView *youTubeWebView = [[[UIWebView alloc] initWithFrame:aFrame] autorelease];
[youTubeWebView setBackgroundColor:[UIColor clearColor]];
[youTubeWebView setUserInteractionEnabled:YES];
[youTubeWebView setMultipleTouchEnabled:YES];
[youTubeWebView setScalesPageToFit:YES];
youTubeWebView.delegate = self;
[self.view addSubview:youTubeWebView];
NSString *videoHTML = [NSString stringWithFormat:@"\
<html>\
<head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {background-color:#000; margin:0;}\
</style>\
</head>\
<body>\
<iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
</body>\
</html>", youTubeUrl];
[youTubeWebView loadHTMLString:videoHTML baseURL:nil];
}