UIWebview is not loading youtube videoes in iFrame

2019-07-04 08:57发布

In my app I am using UIWebview to Load Html string which is having Text,Image Url and Videos in iFrame.This was working fine till now but recently I came to know that text and image url are loading fine and the video is not loading.I am just getting the blank space which I have allocated for the video but no sign of video.

The video iFrame which I am getting is this:

<iframe width="100%" height="" src="//www.youtube.com/embed/bhRqrw82P3A" frameborder="0" allowfullscreen></iframe>

Please suggest if something has changed in API.

3条回答
Explosion°爆炸
2楼-- · 2019-07-04 09:31

//www.youtube.com/embed/bhRqrw82P3A uses scheme depends on server (http or https...etc). In local HTML it will point to file://www.youtube.com/embed/bhRqrw82P3A. I make a fake http host for loading:

[webView loadHTMLString:yourHTMLCode baseURL:[NSURL URLWithString:@"http://localhost"]];

This works for me.

查看更多
疯言疯语
3楼-- · 2019-07-04 09:35
    <iframe src='http://www.youtube.com/embed/bhRqrw82P3A?modestbranding=1&showinfo=0&fs=0' width='300' height='175' frameborder='0' >
    </iframe>

http://jsfiddle.net/tx77b/

查看更多
何必那么认真
4楼-- · 2019-07-04 09:44

See this difference:

src="//www.youtube.com/embed/bhRqrw82P3A"

src="http://www.youtube.com/embed/bhRqrw82P3A"

If you want to use first one you have to add "http:" into your URL to make it valid link. You can do it very easy by adding some base URL when loading HTML string into UIWebView

NSURL *baseURL = [NSURL URLWithString:@"http:"];
[self.contentWebView loadHTMLString:myHTMLCode
                            baseURL:baseURL];
查看更多
登录 后发表回答