0

次のコードを使用して、Webビューで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);
}

このコードの助けを借りて、私は他のユーチューブリンクを開くことができますが、このリンクは開かれていません。

さらに、私はこのリンクをブラウザで使用しており、ブラウザで開かれています。

何が問題なのかわかりません。

何かアイデアがあれば、それを共有してください。

よろしくお願いします...

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 に答える