0

我正在使用以下代码在 webview 中打开 youtube 链接。

[self playVideo:@"www.youtube.com/watch?v=GcpFTAqvLYQ" frame:CGRectMake(0, 44, 1024, 700)];


- (void)playVideo:(NSString *)urlString frame:(CGRect)frame
{
    NSString *embedHTML = @"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
    NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    [videoView loadHTMLString:html baseURL:nil];
    [self.view addSubview:videoView];
    [videoView release];
    NSLog(@"%@",html);
}

在此代码的帮助下,我只能打开其他 youtube 链接,特别是该链接未打开。

此外,我在浏览器中使用此链接,它正在浏览器中打开。

我不明白是什么问题。

如果您有任何想法,请分享。

提前谢谢...

4

1 回答 1

0

做这个:

[self playVideo:@"http://www.youtube.com/watch?v=GcpFTAqvLYQ" frame:CGRectMake(0, 44, 1024, 700)];

现在 playVideo 将是:

 - (void)playVideo:(NSString *)urlString frame:(CGRect)frame
{
    NSString *embedHTML = [NSString stringWithFormat:@"\
    <html><head>\
    <style type=\"text/css\">\
    body {\
    background-color: transparent;\
    color: white;\
    }\
    </style>\
    </head><body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>", urlString, frame.size.width, frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    [videoView loadHTMLString:embedHTML baseURL:nil];
    [self.view addSubview:videoView];
    [videoView release];
    NSLog(@"%@",embedHTML);
}
于 2012-09-25T06:52:24.520 回答