iOS:在UITableViewCell内部的Webview中嵌入Youtube视频无法播放

时间:2017-03-02 13:40:00

标签: ios uitableview webview youtube

当我的WebView在普通的UIView中时,每件事情都有效,视频按预期播放。 (我创建了一个新的示例项目来测试它。)

但是当我把WebView放在UITableView中时。它不玩。它会为视频播放器加载视频缩略图和大红色播放按钮。当我点击播放按钮时,视频无法播放。 WebView变黑了。

这是我的代码

void LoadVideo (string videoId)
{
    nfloat width = UIScreen.MainScreen.Bounds.Size.Width - 32;
    nfloat height = VideoWebview.Frame.Size.Height;
    string embedHtml = "<iframe width=\"{0}\" height=\"{1}\" src=\"https://www.youtube.com/embed/{2}?modestbranding=1&showinfo=0\" frameborder=\"0\" style=\"margin:-8px;padding:0;\" allowfullscreen></iframe>";
    string html = string.Format (embedHtml, width, height, videoId);
    Console.WriteLine (html);
    VideoWebview.ScrollView.Bounces = false;
    VideoWebview.LoadHtmlString (html, new Foundation.NSUrl ("https://www.youtube.com"));
}

当WebView不在UITableViewCell中时,这可以正常工作。我在这做错了什么?任何帮助表示赞赏。

修改:

我发现我的项目存在一些问题。我创建了一个新的示例项目,它在UITableViewCell中工作。但是在我目前正在工作的项目中,它只是不起作用......不是在UITableViewCell中,而是在UIView中。

0 个答案:

没有答案
相关问题