在iOS 6.0的应用中使用YouTube网址播放YouTube视频

时间:2013-10-31 08:13:19

标签: ios iphone

我正在尝试在iOS 6.0的应用中使用YouTube网址播放YouTube视频 贝洛是我的代码。它无法播放视频。请建议。

- (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];
}

0 个答案:

没有答案