UIWebView不会播放YouTube视频

时间:2013-10-18 02:37:49

标签: ios uiwebview

现在我对这个问题感到困惑,并且无法在Stack Overflow上找到任何有用的东西。

当用户点击链接时,我正在使用应用内浏览器开发应用。现在,它只是UINavigationController中的全尺寸UIWebView。我可以用UIWebView加载网页,但是当有一个Youtube嵌入时,我无法播放视频。

我正在使用此网址来测试:http://kottke.org/13/10/the-grand-budapest-hotel

当我使用Twitterific中的应用内浏览器加载网址时,视频可播放。当我在我的应用程序内浏览器中加载它时,我得到一个带有来自Youtube的红色播放按钮的黑盒子,但是当你点击播放按钮时,它会消失并且视频永远不会加载。

_webView = [[UIWebView alloc] init];
[_webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[_webView setScalesPageToFit:YES];
[self.view addSubview:_webView];
[self.view addConstraints:constraints];
[_webView loadRequest:request];

我是否错过了UIWebView上的设置?

1 个答案:

答案 0 :(得分:0)

我用这个:

NSString *html = [self getHTML:videoId];
[self loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];

- (NSString *) getHTML: (NSString *)videoID
{
    if (videoType == videoTypeYoutube)
    {
        NSString *youTubeVideoHTML = @"<html>\
        <body style=\"margin:0;\">\
        <iframe class=\"youtube-player\" type=\"text/html\" width=\"%0.0f\" height=\"%0.0f\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\">\
        </iframe>\
        </body>\
        </html>";
        NSString *html = [NSString stringWithFormat:youTubeVideoHTML, self.frame.size.width, self.frame.size.height, videoId];
        return html;
    }
}

无论如何(我已经从我使用的子类中剪切和粘贴了东西)。

相关问题