iPhone:youtube视频链接未打开

时间:2012-09-25 06:43:02

标签: iphone objective-c video

我正在使用以下代码在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链接,仅此链接未打开。

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

我无法理解这是什么问题。

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

提前预定...

1 个答案:

答案 0 :(得分: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);
}